Package com.linecorp.armeria.server
Class ServiceRequestContextWrapper
java.lang.Object
com.linecorp.armeria.common.RequestContextWrapper<ServiceRequestContext>
com.linecorp.armeria.server.ServiceRequestContextWrapper
- All Implemented Interfaces:
RequestContext
,ServiceRequestContext
public class ServiceRequestContextWrapper
extends RequestContextWrapper<ServiceRequestContext>
implements ServiceRequestContext
Wraps an existing
ServiceRequestContext
.-
Constructor Summary
ModifierConstructorDescriptionprotected
Creates a new instance. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addAdditionalResponseHeader(CharSequence name, Object value)
Adds a header with the specifiedname
andvalue
.void
addAdditionalResponseTrailer(CharSequence name, Object value)
Adds a trailer with the specifiedname
andvalue
.Returns theHttpHeaders
which is included along with any other trailers when aService
completes anHttpResponse
.Returns theContextAwareScheduledExecutorService
that could be used for executing a potentially long-running task.void
Clears the previously scheduled request timeout, if any.Returns the address of the client who initiated this request.config()
Returns theRequestContext.decodedPath()
with its context path removed.Initiates connection shutdown without overriding current configuration of the drain duration and returnsCompletableFuture
that completes when the channel is closed.initiateConnectionShutdown(long drainDurationMicros)
Initiates graceful connection shutdown with a given drain duration in microseconds and returnsCompletableFuture
that completes when the channel is closed..boolean
Returns whether thisRequestContext
has been cancelled.boolean
Returns whether thisRequestContext
has been timed-out, that is the cancellation cause is an instance ofTimeoutException
.<A extends SocketAddress>
AReturns the local address of this request, ornull
if the connection is not established yet.Returns theRequestContext.path()
with its context path removed.long
Returns the maximum length of the currentRequest
.void
void
Mutates theHttpHeaders
which is included along with any other trailers when aService
completes anHttpResponse
.Returns the negotiated producible media type.Returns the proxied addresses of the currentRequest
.<A extends SocketAddress>
AReturns the remote address of this request, ornull
if the connection is not established yet.request()
Returns theHttpRequest
associated with this context, ornull
if there's noHttpRequest
associated with this context yet.long
root()
Returns the rootServiceRequestContext
of this context.Returns theRoutingContext
used to find theService
.void
setAdditionalResponseHeader(CharSequence name, Object value)
Sets a header with the specifiedname
andvalue
.void
setAdditionalResponseTrailer(CharSequence name, Object value)
Sets a trailer with the specifiedname
andvalue
.void
setMaxRequestLength(long maxRequestLength)
Sets the maximum length of the currentRequest
.void
setRequestTimeout(TimeoutMode mode, Duration requestTimeout)
Schedules the request timeout that is triggered when theRequest
is not fully received or the correspondingResponse
is not sent completely within the specifiedTimeoutMode
and the specifiedrequestTimeout
.void
setRequestTimeoutMillis(TimeoutMode mode, long requestTimeoutMillis)
Schedules the request timeout that is triggered when theRequest
is not fully received or the correspondingResponse
is not sent completely within the specifiedTimeoutMode
and the specifiedrequestTimeoutMillis
.Returns aCompletableFuture
which is completed with aThrowable
cancellation cause after theServiceRequestContext
has been cancelled.Returns aCompletableFuture
which is completed with aThrowable
cancellation cause when theServiceRequestContext
is about to get cancelled.Deprecated.Deprecated.Methods inherited from class com.linecorp.armeria.common.RequestContextWrapper
alloc, attr, attrs, cancel, cancel, cancellationCause, decodedPath, delegate, eventLoop, hasAttr, hasOwnAttr, id, log, logBuilder, meterRegistry, method, ownAttr, ownAttrs, path, query, rpcRequest, sessionProtocol, setAttr, sslSession, timeoutNow, toString, updateRequest, updateRpcRequest
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface com.linecorp.armeria.common.RequestContext
alloc, attr, attrs, cancel, cancellationCause, decodedPath, eventLoop, hasAttr, hasOwnAttr, id, log, logBuilder, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, meterRegistry, method, ownAttr, ownAttrs, path, query, replace, run, run, sessionProtocol, setAttr, sslSession, updateRequest, updateRpcRequest
Methods inherited from interface com.linecorp.armeria.server.ServiceRequestContext
cancel, initiateConnectionShutdown, pathParam, push, rpcRequest, setRequestTimeout, setRequestTimeoutMillis, timeoutNow
-
Constructor Details
-
ServiceRequestContextWrapper
Creates a new instance.
-
-
Method Details
-
root
Description copied from interface:RequestContext
Returns the rootServiceRequestContext
of this context.- Specified by:
root
in interfaceRequestContext
- Specified by:
root
in interfaceServiceRequestContext
- Overrides:
root
in classRequestContextWrapper<ServiceRequestContext>
- Returns:
- the root
ServiceRequestContext
, ornull
if this context was not created in the context of a server request.
-
request
Description copied from interface:RequestContext
Returns theHttpRequest
associated with this context, ornull
if there's noHttpRequest
associated with this context yet.- Specified by:
request
in interfaceRequestContext
- Specified by:
request
in interfaceServiceRequestContext
- Overrides:
request
in classRequestContextWrapper<ServiceRequestContext>
-
remoteAddress
Description copied from interface:RequestContext
Returns the remote address of this request, ornull
if the connection is not established yet.- Specified by:
remoteAddress
in interfaceRequestContext
- Specified by:
remoteAddress
in interfaceServiceRequestContext
- Overrides:
remoteAddress
in classRequestContextWrapper<ServiceRequestContext>
-
localAddress
Description copied from interface:RequestContext
Returns the local address of this request, ornull
if the connection is not established yet.- Specified by:
localAddress
in interfaceRequestContext
- Specified by:
localAddress
in interfaceServiceRequestContext
- Overrides:
localAddress
in classRequestContextWrapper<ServiceRequestContext>
-
clientAddress
Description copied from interface:ServiceRequestContext
Returns the address of the client who initiated this request.- Specified by:
clientAddress
in interfaceServiceRequestContext
-
config
Description copied from interface:ServiceRequestContext
- Specified by:
config
in interfaceServiceRequestContext
-
routingContext
Description copied from interface:ServiceRequestContext
Returns theRoutingContext
used to find theService
.- Specified by:
routingContext
in interfaceServiceRequestContext
-
pathParams
Description copied from interface:ServiceRequestContext
Returns the path parameters mapped by theRoute
associated with theService
that is handling the currentRequest
.- Specified by:
pathParams
in interfaceServiceRequestContext
-
blockingTaskExecutor
Description copied from interface:ServiceRequestContext
Returns theContextAwareScheduledExecutorService
that could be used for executing a potentially long-running task. TheContextAwareScheduledExecutorService
sets thisServiceRequestContext
as the current context before executing any submitted tasks. If you want to useScheduledExecutorService
without setting this context, callContextAwareScheduledExecutorService.withoutContext()
and use the returnedScheduledExecutorService
.- Specified by:
blockingTaskExecutor
in interfaceServiceRequestContext
-
mappedPath
Description copied from interface:ServiceRequestContext
Returns theRequestContext.path()
with its context path removed. This method can be useful for a reusable service bound at various path prefixes.- Specified by:
mappedPath
in interfaceServiceRequestContext
-
decodedMappedPath
Description copied from interface:ServiceRequestContext
Returns theRequestContext.decodedPath()
with its context path removed. This method can be useful for a reusable service bound at various path prefixes.- Specified by:
decodedMappedPath
in interfaceServiceRequestContext
-
negotiatedResponseMediaType
Description copied from interface:ServiceRequestContext
Returns the negotiated producible media type. If the media type negotiation is not used for theService
,null
would be returned.- Specified by:
negotiatedResponseMediaType
in interfaceServiceRequestContext
-
requestTimeoutMillis
public long requestTimeoutMillis()Description copied from interface:ServiceRequestContext
Returns the amount of time allowed from the start time of theRequest
until receiving the currentRequest
and sending the correspondingResponse
completely. This value is initially set fromServiceConfig.requestTimeoutMillis()
.- Specified by:
requestTimeoutMillis
in interfaceServiceRequestContext
-
clearRequestTimeout
public void clearRequestTimeout()Description copied from interface:ServiceRequestContext
Clears the previously scheduled request timeout, if any. Note that calling this will prevent the request from ever being timed out.- Specified by:
clearRequestTimeout
in interfaceServiceRequestContext
-
setRequestTimeoutMillis
Description copied from interface:ServiceRequestContext
Schedules the request timeout that is triggered when theRequest
is not fully received or the correspondingResponse
is not sent completely within the specifiedTimeoutMode
and the specifiedrequestTimeoutMillis
.timeout mode description Timeout mode description TimeoutMode.SET_FROM_NOW
Sets a given amount of timeout from the current time. TimeoutMode.SET_FROM_START
Sets a given amount of timeout since the current Request
began processing.TimeoutMode.EXTEND
Extends the previously scheduled timeout by the given amount of timeout. For example:
ServiceRequestContext ctx = ...; // Schedules a timeout from the start time of the request ctx.setRequestTimeoutMillis(TimeoutMode.SET_FROM_START, 2000); assert ctx.requestTimeoutMillis() == 2000; ctx.setRequestTimeoutMillis(TimeoutMode.SET_FROM_START, 1000); assert ctx.requestTimeoutMillis() == 1000; // Schedules timeout after 3 seconds from now. ctx.setRequestTimeoutMillis(TimeoutMode.SET_FROM_NOW, 3000); // Extends the previously scheduled timeout. long oldRequestTimeoutMillis = ctx.requestTimeoutMillis(); ctx.setRequestTimeoutMillis(TimeoutMode.EXTEND, 1000); assert ctx.requestTimeoutMillis() == oldRequestTimeoutMillis + 1000; ctx.extendRequestTimeoutMillis(TimeoutMode.EXTEND, -500); assert ctx.requestTimeoutMillis() == oldRequestTimeoutMillis + 500;
- Specified by:
setRequestTimeoutMillis
in interfaceServiceRequestContext
-
setRequestTimeout
Description copied from interface:ServiceRequestContext
Schedules the request timeout that is triggered when theRequest
is not fully received or the correspondingResponse
is not sent completely within the specifiedTimeoutMode
and the specifiedrequestTimeout
.timeout mode description Timeout mode description TimeoutMode.SET_FROM_NOW
Sets a given amount of timeout from the current time. TimeoutMode.SET_FROM_START
Sets a given amount of timeout since the current Request
began processing.TimeoutMode.EXTEND
Extends the previously scheduled timeout by the given amount of timeout. For example:
ServiceRequestContext ctx = ...; // Schedules a timeout from the start time of the request ctx.setRequestTimeout(TimeoutMode.SET_FROM_START, Duration.ofSeconds(2)); assert ctx.requestTimeoutMillis() == 2000; ctx.setRequestTimeout(TimeoutMode.SET_FROM_START, Duration.ofSeconds(1)); assert ctx.requestTimeoutMillis() == 1000; // Schedules timeout after 3 seconds from now. ctx.setRequestTimeout(TimeoutMode.SET_FROM_NOW, Duration.ofSeconds(3)); // Extends the previously scheduled timeout. long oldRequestTimeoutMillis = ctx.requestTimeoutMillis(); ctx.setRequestTimeout(TimeoutMode.EXTEND, Duration.ofSeconds(1)); assert ctx.requestTimeoutMillis() == oldRequestTimeoutMillis + 1000; ctx.setRequestTimeout(TimeoutMode.EXTEND, Duration.ofMillis(-500)); assert ctx.requestTimeoutMillis() == oldRequestTimeoutMillis + 500;
- Specified by:
setRequestTimeout
in interfaceServiceRequestContext
-
whenRequestCancelling
Description copied from interface:ServiceRequestContext
Returns aCompletableFuture
which is completed with aThrowable
cancellation cause when theServiceRequestContext
is about to get cancelled. If the request is handled successfully without cancellation, theCompletableFuture
won't complete.- Specified by:
whenRequestCancelling
in interfaceServiceRequestContext
-
whenRequestCancelled
Description copied from interface:ServiceRequestContext
Returns aCompletableFuture
which is completed with aThrowable
cancellation cause after theServiceRequestContext
has been cancelled.RequestContext.isCancelled()
will always returntrue
when the returnedCompletableFuture
is completed. If the request is handled successfully without cancellation, theCompletableFuture
won't complete.- Specified by:
whenRequestCancelled
in interfaceServiceRequestContext
-
whenRequestTimingOut
Deprecated.Description copied from interface:ServiceRequestContext
Returns aCompletableFuture
which is completed when theServiceRequestContext
is about to get timed out. If the request is handled successfully or not cancelled by timeout, theCompletableFuture
won't complete.- Specified by:
whenRequestTimingOut
in interfaceServiceRequestContext
-
whenRequestTimedOut
Deprecated.Description copied from interface:ServiceRequestContext
Returns aCompletableFuture
which is completed after theServiceRequestContext
has been timed out.RequestContext.isTimedOut()
will always returntrue
when the returnedCompletableFuture
is completed. If the request is handled successfully or not cancelled by timeout, theCompletableFuture
won't complete.- Specified by:
whenRequestTimedOut
in interfaceServiceRequestContext
-
isCancelled
public boolean isCancelled()Description copied from interface:RequestContext
Returns whether thisRequestContext
has been cancelled.- Specified by:
isCancelled
in interfaceRequestContext
-
isTimedOut
public boolean isTimedOut()Description copied from interface:RequestContext
Returns whether thisRequestContext
has been timed-out, that is the cancellation cause is an instance ofTimeoutException
.- Specified by:
isTimedOut
in interfaceRequestContext
-
maxRequestLength
public long maxRequestLength()Description copied from interface:ServiceRequestContext
Returns the maximum length of the currentRequest
. This value is initially set fromServiceConfig.maxRequestLength()
. If 0, there is no limit on the request size.- Specified by:
maxRequestLength
in interfaceServiceRequestContext
- See Also:
ContentTooLargeException
-
setMaxRequestLength
public void setMaxRequestLength(long maxRequestLength)Description copied from interface:ServiceRequestContext
Sets the maximum length of the currentRequest
. This value is initially set fromServiceConfig.maxRequestLength()
. If 0, there is no limit on the request size.- Specified by:
setMaxRequestLength
in interfaceServiceRequestContext
- See Also:
ContentTooLargeException
-
additionalResponseHeaders
Description copied from interface:ServiceRequestContext
- Specified by:
additionalResponseHeaders
in interfaceServiceRequestContext
-
setAdditionalResponseHeader
Description copied from interface:ServiceRequestContext
Sets a header with the specifiedname
andvalue
. This will remove all previous values associated with the specifiedname
. The header will be included when aService
sends anHttpResponse
.- Specified by:
setAdditionalResponseHeader
in interfaceServiceRequestContext
-
addAdditionalResponseHeader
Description copied from interface:ServiceRequestContext
Adds a header with the specifiedname
andvalue
. The header will be included when aService
sends anHttpResponse
.- Specified by:
addAdditionalResponseHeader
in interfaceServiceRequestContext
-
mutateAdditionalResponseHeaders
Description copied from interface:ServiceRequestContext
- Specified by:
mutateAdditionalResponseHeaders
in interfaceServiceRequestContext
- Parameters:
mutator
- theConsumer
that mutates the additional response headers
-
additionalResponseTrailers
Description copied from interface:ServiceRequestContext
Returns theHttpHeaders
which is included along with any other trailers when aService
completes anHttpResponse
.- Specified by:
additionalResponseTrailers
in interfaceServiceRequestContext
-
setAdditionalResponseTrailer
Description copied from interface:ServiceRequestContext
Sets a trailer with the specifiedname
andvalue
. This will remove all previous values associated with the specifiedname
. The trailer will be included when aService
completes anHttpResponse
.- Specified by:
setAdditionalResponseTrailer
in interfaceServiceRequestContext
-
addAdditionalResponseTrailer
Description copied from interface:ServiceRequestContext
Adds a trailer with the specifiedname
andvalue
. The trailer will be included when aService
completes anHttpResponse
.- Specified by:
addAdditionalResponseTrailer
in interfaceServiceRequestContext
-
mutateAdditionalResponseTrailers
Description copied from interface:ServiceRequestContext
Mutates theHttpHeaders
which is included along with any other trailers when aService
completes anHttpResponse
.- Specified by:
mutateAdditionalResponseTrailers
in interfaceServiceRequestContext
- Parameters:
mutator
- theConsumer
that mutates the additional trailers
-
proxiedAddresses
Description copied from interface:ServiceRequestContext
Returns the proxied addresses of the currentRequest
.- Specified by:
proxiedAddresses
in interfaceServiceRequestContext
-
initiateConnectionShutdown
Description copied from interface:ServiceRequestContext
Initiates graceful connection shutdown with a given drain duration in microseconds and returnsCompletableFuture
that completes when the channel is closed..At the connection drain server signals the clients that the connection shutdown is imminent but still accepts in flight requests. At the connection drain end server stops accepting new requests.
If graceful shutdown is already triggered and the given connection drain duration is smaller than the wait time before the connection drain end, it reschedules the drain end to happen faster. Otherwise, drain will end as it was previously scheduled.
Note that HTTP/1 doesn't support draining as described here, so for HTTP/1 drain duration is always
0
, which means the connection will be closed immediately at the end of the current response.- Specified by:
initiateConnectionShutdown
in interfaceServiceRequestContext
- See Also:
ServiceRequestContext.initiateConnectionShutdown()
,ServiceRequestContext.initiateConnectionShutdown(Duration)
-
initiateConnectionShutdown
Description copied from interface:ServiceRequestContext
Initiates connection shutdown without overriding current configuration of the drain duration and returnsCompletableFuture
that completes when the channel is closed.- Specified by:
initiateConnectionShutdown
in interfaceServiceRequestContext
- See Also:
ServiceRequestContext.initiateConnectionShutdown(long)
,ServiceRequestContext.initiateConnectionShutdown(Duration)
-