Package com.linecorp.armeria.server
Interface Service<I extends Request,O extends Response>
- Type Parameters:
I
- the type of incomingRequest
. Must beHttpRequest
orRpcRequest
.O
- the type of outgoingResponse
. Must beHttpResponse
orRpcResponse
.
- All Superinterfaces:
Unwrappable
- All Known Subinterfaces:
GraphqlService
,GrpcService
,HttpService
,HttpServiceWithRoutes
,RpcService
,RpcServiceWithRoutes
,ServiceWithRoutes<I,O>
,TransientHttpService
,TransientRpcService
,TransientService<I,O>
- All Known Implementing Classes:
AbstractGraphqlService
,AbstractHttpService
,AbstractThrottlingService
,AbstractUnaryGrpcService
,AbstractUnsafeUnaryGrpcService
,AuthService
,BraveService
,ContentPreviewingService
,CoroutineContextService
,CorsService
,DecodingService
,DecoratingService
,DocService
,EncodingService
,FileService
,HealthCheckService
,JettyService
,LoggingService
,ManagementService
,MetricCollectingService
,PrometheusExpositionService
,RedirectService
,ResteasyService
,SimpleDecoratingHttpService
,SimpleDecoratingRpcService
,SimpleDecoratingService
,ThriftCallService
,ThrottlingRpcService
,ThrottlingService
,THttpService
,TomcatService
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
@FunctionalInterface
public interface Service<I extends Request,O extends Response>
extends Unwrappable
-
Method Summary
Modifier and TypeMethodDescriptiondefault <T> T
Unwraps thisService
into the object of the specifiedtype
.serve(ServiceRequestContext ctx, I req)
Serves an incomingRequest
.default void
serviceAdded(ServiceConfig cfg)
Invoked when this service has been added to aServer
with the specified configuration.default boolean
shouldCachePath(String path, @Nullable String query, Route route)
Returns whether the givenpath
andquery
should be cached if the service's result is successful.unwrap()
Unwraps thisService
and returns the object being decorated.
-
Method Details
-
serviceAdded
Invoked when this service has been added to aServer
with the specified configuration. Please note that this method can be invoked more than once if this service has been added more than once.- Throws:
Exception
-
serve
Serves an incomingRequest
. -
as
Unwraps thisService
into the object of the specifiedtype
. 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);
- Specified by:
as
in interfaceUnwrappable
- Parameters:
type
- the type of the object to return- Returns:
- the object of the specified
type
if found, ornull
if not found. - See Also:
Unwrappable
-
unwrap
Unwraps thisService
and returns the object being decorated. If thisService
is the innermost object, this method returns itself. For example:HttpService service1 = new MyService(); assert service1.unwrap() == service1; HttpService service2 = service1.decorate(LoggingService.newDecorator()); HttpService service3 = service2.decorate(AuthService.newDecorator()); assert service2.unwrap() == service1; assert service3.unwrap() == service2; assert service3.unwrap().unwrap() == service1;
- Specified by:
unwrap
in interfaceUnwrappable
-
shouldCachePath
Returns whether the givenpath
andquery
should be cached if the service's result is successful. By default, exact path mappings with no input query are cached.
-