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> extends Unwrappable
| Modifier and Type | Method and Description |
|---|---|
default <T> T |
as(Class<T> type)
Unwraps this
Service into the object of the specified type. |
default <R extends Service<?,?>> |
decorate(Class<R> serviceType)
|
O |
serve(ServiceRequestContext ctx,
I req)
Serves an incoming
Request. |
default void |
serviceAdded(ServiceConfig cfg)
Invoked when this service has been added to a
Server with the specified
configuration. |
default boolean |
shouldCachePath(String path,
String query,
Route route)
Returns whether the given
path and query should be cached if the service's result is
successful. |
default void serviceAdded(ServiceConfig cfg) throws Exception
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.ExceptionO serve(ServiceRequestContext ctx, I req) throws Exception
Request.default <T> T as(Class<T> type)
Service into the object of the specified type.
Use this method instead of an explicit downcast. For example:
HttpService 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);
as in interface Unwrappabletype - the type of the object to returntype if found, or null if not found.Unwrappable@Deprecated default <R extends Service<?,?>> R decorate(Class<R> serviceType)
Copyright © 2020 LeanCloud. All rights reserved.