@FunctionalInterface
public interface Service<I extends Request,O extends Response>
Modifier and Type | Method and Description |
---|---|
default <T> java.util.Optional<T> |
as(java.lang.Class<T> serviceType)
|
default <R extends Service<?,?>> |
decorate(java.lang.Class<R> serviceType)
|
default Service<I,O> |
decorate(DecoratingServiceFunction<? super I,? extends O> function)
|
default <T extends Service<? super I,? extends O>,R extends Service<R_I,R_O>,R_I extends Request,R_O extends Response> |
decorate(java.util.function.Function<T,R> decorator)
|
O |
serve(ServiceRequestContext ctx,
I req)
Serves an incoming
Request . |
default void |
serviceAdded(ServiceConfig cfg)
|
default void serviceAdded(ServiceConfig cfg) throws java.lang.Exception
Service
has been added to a Server
with the specified configuration.
Please note that this method can be invoked more than once if ths Service
has been added more
than once.java.lang.Exception
O serve(ServiceRequestContext ctx, I req) throws java.lang.Exception
Request
.default <T> java.util.Optional<T> as(java.lang.Class<T> serviceType)
Service
to find the Service
which is an instance of the specified
serviceType
. Use this method instead of an explicit downcast since most Service
s are
decorated via decorate(Function)
and thus cannot be downcast. For example:
Service s = new MyService().decorate(LoggingService::new).decorate(AuthService::new);
MyService s1 = s.as(MyService.class);
LoggingService s2 = s.as(LoggingService.class);
AuthService s3 = s.as(AuthService.class);
default <R extends Service<?,?>> R decorate(java.lang.Class<R> serviceType)
default <T extends Service<? super I,? extends O>,R extends Service<R_I,R_O>,R_I extends Request,R_O extends Response> R decorate(java.util.function.Function<T,R> decorator)