Skip to content

Commit

Permalink
Added fix for Service flexibility.
Browse files Browse the repository at this point in the history
Made BaseService an interface that extends Module and Service.
Added the class DefaultService that extends AbstractIdleService and implements the new BaseService interface.
Bumped version.
  • Loading branch information
noboomu committed Apr 10, 2019
1 parent 9e1eee1 commit 14b3a54
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 48 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,9 @@ public ServerResponse<Map<String,Object>> complexParameters(
Services
-------------

Proteus has three standard services that extend the ```io.sinistral.proteus.services.BaseService``` class.
Proteus has three standard services that extend the ```io.sinistral.proteus.services.DefaultService``` class.
The ```io.sinistral.proteus.services.DefaultService``` extends ```com.google.common.util.concurrent.AbstractIdleService``` and implements the ```io.sinistral.proteus.services.BaseService``` interface.
The ProteusApplication class expects services that implement ```io.sinistral.proteus.services.BaseService```.

- __AssetsService__

Expand Down Expand Up @@ -502,7 +504,7 @@ Prior to calling `start` on the `ProteusApplication` instance:

Out of the box you get a [Swagger UI](https://github.com/swagger-api/swagger-ui) at `/openapi`.

> A `Service` extends `com.google.common.util.concurrent.AbstractIdleService` or `io.sinistral.proteus.services.BaseService`.
> A `Service` extends `com.google.common.util.concurrent.AbstractIdleService` or `io.sinistral.proteus.services.DefaultService`.
> A `Module` implements `com.google.inject.Module`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import io.sinistral.proteus.server.handlers.HandlerGenerator;
import io.sinistral.proteus.server.handlers.ServerDefaultHttpHandler;
import io.sinistral.proteus.services.BaseService;
import io.sinistral.proteus.services.DefaultService;
import io.sinistral.proteus.utilities.SecurityOps;
import io.sinistral.proteus.utilities.TablePrinter;
import io.undertow.Undertow;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import io.sinistral.proteus.server.ServerResponse;
import io.sinistral.proteus.server.endpoints.EndpointInfo;
import io.sinistral.proteus.services.BaseService;
import io.sinistral.proteus.services.DefaultService;
import io.undertow.server.DefaultResponseListener;
import io.undertow.server.HandlerWrapper;
import io.undertow.server.HttpHandler;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.sinistral.proteus.services;

import com.google.inject.Inject;
import com.google.inject.Singleton;
import com.google.inject.name.Named;
import com.typesafe.config.Config;
import io.sinistral.proteus.server.endpoints.EndpointInfo;
Expand All @@ -19,7 +20,8 @@
*
* @author jbauer
*/
public class AssetsService extends BaseService implements Supplier<RoutingHandler>
@Singleton
public class AssetsService extends DefaultService implements Supplier<RoutingHandler>
{
@Inject
@Named("registeredEndpoints")
Expand Down
42 changes: 2 additions & 40 deletions core/src/main/java/io/sinistral/proteus/services/BaseService.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.sinistral.proteus.services;

import com.google.common.util.concurrent.AbstractIdleService;
import com.google.common.util.concurrent.Service;
import com.google.inject.Binder;
import com.google.inject.Inject;
import com.google.inject.Module;
Expand All @@ -14,48 +15,9 @@
*
* @author jbauer
*/
@Singleton
public abstract class BaseService extends AbstractIdleService implements Module
public interface BaseService extends Module, Service
{
private static Logger log = LoggerFactory.getLogger(BaseService.class.getCanonicalName());

/*
* @see com.google.inject.AbstractModule#configure()
*/
@Inject
protected Config config;

public BaseService()
{
}

/*
* (non-Javadoc)
* @see com.google.inject.Module#configure(com.google.inject.Binder)
*/
@Override
public void configure(Binder binder)
{

}

/*
//* @see com.google.common.util.concurrent.AbstractIdleService#shutDown()
*/
@Override
protected void shutDown() throws Exception
{
log.info("Stopping " + this.getClass().getSimpleName());
}

/*
* @see com.google.common.util.concurrent.AbstractIdleService#startUp()
*/
@Override
protected void startUp() throws Exception
{
log.info("Starting " + this.getClass().getSimpleName());
}
}


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package io.sinistral.proteus.services;

import com.google.common.util.concurrent.AbstractIdleService;
import com.google.inject.Binder;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import com.typesafe.config.Config;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* An abstract base class for a Proteus service.
*
* @author jbauer
*/
@Singleton
public abstract class DefaultService extends AbstractIdleService implements BaseService
{
private static Logger log = LoggerFactory.getLogger(DefaultService.class.getCanonicalName());

/*
* @see com.google.inject.AbstractModule#configure()
*/
@Inject
protected Config config;

public DefaultService()
{
}

/*
* (non-Javadoc)
* @see com.google.inject.Module#configure(com.google.inject.Binder)
*/
@Override
public void configure(Binder binder)
{

}

/*
//* @see com.google.common.util.concurrent.AbstractIdleService#shutDown()
*/
@Override
protected void shutDown() throws Exception
{
log.info("Stopping " + this.getClass().getSimpleName());
}

/*
* @see com.google.common.util.concurrent.AbstractIdleService#startUp()
*/
@Override
protected void startUp() throws Exception
{
log.info("Starting " + this.getClass().getSimpleName());
}
}



Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import io.sinistral.proteus.openapi.jaxrs2.Reader;
import io.sinistral.proteus.openapi.jaxrs2.ServerModelResolver;
import io.sinistral.proteus.openapi.jaxrs2.ServerParameterExtension;
import io.sinistral.proteus.services.BaseService;
import io.sinistral.proteus.services.DefaultService;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;

Expand Down Expand Up @@ -76,7 +76,7 @@
*/

@Singleton
public class OpenAPIService extends BaseService implements Supplier<RoutingHandler>
public class OpenAPIService extends DefaultService implements Supplier<RoutingHandler>
{
private static Logger log = LoggerFactory.getLogger(OpenAPIService.class.getCanonicalName());

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<groupId>io.sinistral</groupId>
<artifactId>proteus-project</artifactId>
<packaging>pom</packaging>
<version>0.4-SNAPSHOT</version>
<version>0.4.1-SNAPSHOT</version>

<description>Proteus is an extremely light, fast, and flexible Java REST API framework built atop Undertow.</description>
<url>http://github.com/noboomu/proteus</url>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import com.google.inject.name.Named;
import com.typesafe.config.Config;
import io.sinistral.proteus.server.endpoints.EndpointInfo;
import io.sinistral.proteus.services.BaseService;
import io.sinistral.proteus.services.DefaultService;
import io.sinistral.proteus.swagger.jaxrs2.Reader;
import io.sinistral.proteus.swagger.jaxrs2.ServerParameterExtension;
import io.swagger.jaxrs.ext.SwaggerExtension;
Expand Down Expand Up @@ -57,7 +57,7 @@
*/

@Singleton
public class SwaggerService extends BaseService implements Supplier<RoutingHandler>
public class SwaggerService extends DefaultService implements Supplier<RoutingHandler>
{

private static Logger log = LoggerFactory.getLogger(SwaggerService.class.getCanonicalName());
Expand Down

0 comments on commit 14b3a54

Please sign in to comment.