Class CoroutineContextService
java.lang.Object
com.linecorp.armeria.common.util.AbstractUnwrappable<com.linecorp.armeria.server.Service<T_I,T_O>>
com.linecorp.armeria.server.DecoratingService<I,O,I,O>
com.linecorp.armeria.server.SimpleDecoratingService<com.linecorp.armeria.common.HttpRequest,com.linecorp.armeria.common.HttpResponse>
com.linecorp.armeria.server.SimpleDecoratingHttpService
com.linecorp.armeria.server.kotlin.CoroutineContextService
- All Implemented Interfaces:
com.linecorp.armeria.common.util.Unwrappable,com.linecorp.armeria.server.HttpService,com.linecorp.armeria.server.Service<com.linecorp.armeria.common.HttpRequest,com.linecorp.armeria.common.HttpResponse>
public final class CoroutineContextService
extends com.linecorp.armeria.server.SimpleDecoratingHttpService
Decorates an
HttpService to configure the coroutine context which is used as an initial context
of annotated services' suspending functions.
Example:
> serverBuilder
> .annotatedService(object {
> @Get("/users/{uid}")
> suspend fun foo(@Param("uid") uid: String): HttpResponse {
> ...
> }
> })
> .decorator(CoroutineContextService.newDecorator { ctx ->
> CoroutineName(ctx.config().defaultServiceNaming.serviceName(ctx) ?: "name")
> })
Note that ctx.eventLoop() is used as coroutine dispatcher by default,
and ctx.blockingTaskExecutor() is used if `useBlockingTaskExecutor` is set to true
or methods are annotated with @Blocking.
-
Method Summary
Modifier and TypeMethodDescriptionstatic Function<? super com.linecorp.armeria.server.HttpService,CoroutineContextService> newDecorator(CoroutineContextProvider provider) Returns a newHttpServicedecorator that injects into annotated services the coroutine context provided by the specifiedprovider.com.linecorp.armeria.common.HttpResponseserve(com.linecorp.armeria.server.ServiceRequestContext ctx, com.linecorp.armeria.common.HttpRequest req) Methods inherited from class com.linecorp.armeria.server.SimpleDecoratingHttpService
exchangeTypeMethods inherited from class com.linecorp.armeria.server.DecoratingService
serviceAdded, shouldCachePathMethods inherited from class com.linecorp.armeria.common.util.AbstractUnwrappable
as, toString, unwrapMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface com.linecorp.armeria.server.HttpService
decorate, decorateMethods inherited from interface com.linecorp.armeria.server.Service
as, serviceAdded, shouldCachePath, unwrap
-
Method Details
-
newDecorator
public static Function<? super com.linecorp.armeria.server.HttpService,CoroutineContextService> newDecorator(CoroutineContextProvider provider) Returns a newHttpServicedecorator that injects into annotated services the coroutine context provided by the specifiedprovider. -
serve
public com.linecorp.armeria.common.HttpResponse serve(com.linecorp.armeria.server.ServiceRequestContext ctx, com.linecorp.armeria.common.HttpRequest req) throws Exception - Throws:
Exception
-