I
- the type of incoming Request
. Must be HttpRequest
or RpcRequest
.O
- the type of outgoing Response
. Must be HttpResponse
or RpcResponse
.@FunctionalInterface public interface Service<I extends Request,O extends Response>
Modifier and Type | Method and Description |
---|---|
default <T> Optional<T> |
as(Class<T> serviceType)
|
default <R extends Service<?,?>> |
decorate(Class<R> serviceType)
|
default Service<I,O> |
decorate(DecoratingServiceFunction<I,O> function)
|
default <T extends Service<I,O>,R extends Service<R_I,R_O>,R_I extends Request,R_O extends Response> |
decorate(Function<T,R> decorator)
|
O |
serve(ServiceRequestContext ctx,
I req)
Serves an incoming
Request . |
default void |
serviceAdded(ServiceConfig cfg)
|
default boolean |
shouldCachePath(String path,
String query,
PathMapping pathMapping)
Returns whether the given
path and query should be cached if the service's result is
successful. |
default void serviceAdded(ServiceConfig cfg) throws Exception
Service
has been added to a Server
with the specified configuration.
Please note that this method can be invoked more than once if this Service
has been added more
than once.Exception
O serve(ServiceRequestContext ctx, I req) throws Exception
Request
.default <T> Optional<T> as(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.newDecorator())
.decorate(AuthService.newDecorator());
MyService s1 = s.as(MyService.class);
LoggingService s2 = s.as(LoggingService.class);
AuthService s3 = s.as(AuthService.class);
serviceType
- the type of the desired Service
Service
which is an instance of serviceType
if this Service
decorated such a Service
. Optional.empty()
otherwise.default <T extends Service<I,O>,R extends Service<R_I,R_O>,R_I extends Request,R_O extends Response> R decorate(Function<T,R> decorator)
default boolean shouldCachePath(String path, @Nullable String query, PathMapping pathMapping)
path
and query
should be cached if the service's result is
successful. By default, exact path mappings with no input query are cached.© Copyright 2015–2018 LINE Corporation. All rights reserved.