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:
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> extends Unwrappable
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default <T> Optional<T>
as(Class<T> type)
Unwraps thisService
into the object of the specifiedtype
.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> type)
Unwraps thisService
into the object of the specifiedtype
. Use this method instead of an explicit 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);
- Specified by:
as
in interfaceUnwrappable
- Parameters:
type
- the type of the object to return- Returns:
- the object of the specified
type
if found.Optional.empty()
if not found. - See Also:
Unwrappable
-
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)
-
-