From 14b3a54426bdb9ff90f146a9d3ee23f1d5f650c2 Mon Sep 17 00:00:00 2001 From: Joshua Bauer Date: Wed, 10 Apr 2019 12:24:15 -0700 Subject: [PATCH] Added fix for Service flexibility. Made BaseService an interface that extends Module and Service. Added the class DefaultService that extends AbstractIdleService and implements the new BaseService interface. Bumped version. --- README.md | 6 +- .../sinistral/proteus/ProteusApplication.java | 1 + .../proteus/modules/ApplicationModule.java | 1 + .../proteus/services/AssetsService.java | 4 +- .../proteus/services/BaseService.java | 42 +------------ .../proteus/services/DefaultService.java | 61 +++++++++++++++++++ .../openapi/services/OpenAPIService.java | 4 +- pom.xml | 2 +- .../swagger/services/SwaggerService.java | 4 +- 9 files changed, 77 insertions(+), 48 deletions(-) create mode 100644 core/src/main/java/io/sinistral/proteus/services/DefaultService.java diff --git a/README.md b/README.md index 6e4744d..1e7078c 100644 --- a/README.md +++ b/README.md @@ -290,7 +290,9 @@ public ServerResponse> 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__ @@ -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`. diff --git a/core/src/main/java/io/sinistral/proteus/ProteusApplication.java b/core/src/main/java/io/sinistral/proteus/ProteusApplication.java index a6d11d7..d50afbe 100644 --- a/core/src/main/java/io/sinistral/proteus/ProteusApplication.java +++ b/core/src/main/java/io/sinistral/proteus/ProteusApplication.java @@ -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; diff --git a/core/src/main/java/io/sinistral/proteus/modules/ApplicationModule.java b/core/src/main/java/io/sinistral/proteus/modules/ApplicationModule.java index 787417b..16b57ec 100644 --- a/core/src/main/java/io/sinistral/proteus/modules/ApplicationModule.java +++ b/core/src/main/java/io/sinistral/proteus/modules/ApplicationModule.java @@ -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; diff --git a/core/src/main/java/io/sinistral/proteus/services/AssetsService.java b/core/src/main/java/io/sinistral/proteus/services/AssetsService.java index a15cde8..e669365 100644 --- a/core/src/main/java/io/sinistral/proteus/services/AssetsService.java +++ b/core/src/main/java/io/sinistral/proteus/services/AssetsService.java @@ -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; @@ -19,7 +20,8 @@ * * @author jbauer */ -public class AssetsService extends BaseService implements Supplier +@Singleton +public class AssetsService extends DefaultService implements Supplier { @Inject @Named("registeredEndpoints") diff --git a/core/src/main/java/io/sinistral/proteus/services/BaseService.java b/core/src/main/java/io/sinistral/proteus/services/BaseService.java index 7f98cf0..5077057 100644 --- a/core/src/main/java/io/sinistral/proteus/services/BaseService.java +++ b/core/src/main/java/io/sinistral/proteus/services/BaseService.java @@ -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; @@ -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()); - } } diff --git a/core/src/main/java/io/sinistral/proteus/services/DefaultService.java b/core/src/main/java/io/sinistral/proteus/services/DefaultService.java new file mode 100644 index 0000000..feabb99 --- /dev/null +++ b/core/src/main/java/io/sinistral/proteus/services/DefaultService.java @@ -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()); + } +} + + + diff --git a/openapi/src/main/java/io/sinistral/proteus/openapi/services/OpenAPIService.java b/openapi/src/main/java/io/sinistral/proteus/openapi/services/OpenAPIService.java index 4a65d63..09a2ca0 100644 --- a/openapi/src/main/java/io/sinistral/proteus/openapi/services/OpenAPIService.java +++ b/openapi/src/main/java/io/sinistral/proteus/openapi/services/OpenAPIService.java @@ -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; @@ -76,7 +76,7 @@ */ @Singleton -public class OpenAPIService extends BaseService implements Supplier +public class OpenAPIService extends DefaultService implements Supplier { private static Logger log = LoggerFactory.getLogger(OpenAPIService.class.getCanonicalName()); diff --git a/pom.xml b/pom.xml index 07f3e34..daf8eba 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ io.sinistral proteus-project pom - 0.4-SNAPSHOT + 0.4.1-SNAPSHOT Proteus is an extremely light, fast, and flexible Java REST API framework built atop Undertow. http://github.com/noboomu/proteus diff --git a/swagger/src/main/java/io/sinistral/proteus/swagger/services/SwaggerService.java b/swagger/src/main/java/io/sinistral/proteus/swagger/services/SwaggerService.java index 84ae96c..3bf5a2a 100644 --- a/swagger/src/main/java/io/sinistral/proteus/swagger/services/SwaggerService.java +++ b/swagger/src/main/java/io/sinistral/proteus/swagger/services/SwaggerService.java @@ -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; @@ -57,7 +57,7 @@ */ @Singleton -public class SwaggerService extends BaseService implements Supplier +public class SwaggerService extends DefaultService implements Supplier { private static Logger log = LoggerFactory.getLogger(SwaggerService.class.getCanonicalName());