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 Known Subinterfaces:
HttpService
,RpcService
,ServiceWithRoutes<I,O>
,TransientService<I,O>
- All Known Implementing Classes:
AbstractCompositeService
,AbstractHttpService
,CorsService
,DecoratingService
,DocService
,HealthCheckService
,HttpAuthService
,HttpEncodingService
,HttpFileService
,HttpHealthCheckService
,LoggingService
,ManagedHttpHealthCheckService
,MetricCollectingService
,PrometheusExpositionService
,RedirectService
,SimpleCompositeService
,SimpleDecoratingHttpService
,SimpleDecoratingRpcService
,SimpleDecoratingService
,StructuredLoggingService
,ThrottlingHttpService
,ThrottlingRpcService
,ThrottlingService
- 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>
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default <T> Optional<T>
as(Class<T> serviceType)
default Service<I,O>
decorate(DecoratingServiceFunction<I,O> function)
default <R extends Service<?,?>>
Rdecorate(Class<R> serviceType)
default <T extends Service<I,O>,R extends Service<R_I,R_O>,R_I extends Request,R_O extends Response>
Rdecorate(Function<T,R> decorator)
O
serve(ServiceRequestContext ctx, I req)
Serves an incomingRequest
.default void
serviceAdded(ServiceConfig cfg)
default boolean
shouldCachePath(String path, String query, Route route)
Returns whether the givenpath
andquery
should be cached if the service's result is successful.
-
-
-
Method Detail
-
serviceAdded
default void serviceAdded(ServiceConfig cfg) throws Exception
Invoked when thisService
has been added to aServer
with the specified configuration. Please note that this method can be invoked more than once if thisService
has been added more than once.- Throws:
Exception
-
serve
O serve(ServiceRequestContext ctx, I req) throws Exception
Serves an incomingRequest
.
-
as
default <T> Optional<T> as(Class<T> serviceType)
Undecorates thisService
to find theService
which is an instance of the specifiedserviceType
. Use this method instead of an explicit downcast since mostService
s are decorated viadecorate(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);
- Parameters:
serviceType
- the type of the desiredService
- Returns:
- the
Service
which is an instance ofserviceType
if thisService
decorated such aService
.Optional.empty()
otherwise.
-
decorate
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)
-
-