Class RequestContextWrapper<T extends RequestContext>
- Type Parameters:
T
- the self type
- All Implemented Interfaces:
RequestContext
- Direct Known Subclasses:
ClientRequestContextWrapper
,ServiceRequestContextWrapper
public abstract class RequestContextWrapper<T extends RequestContext> extends Object implements RequestContext
RequestContext
.-
Constructor Summary
Constructors Modifier Constructor Description protected
RequestContextWrapper(T delegate)
Creates a new instance. -
Method Summary
Modifier and Type Method Description ByteBufAllocator
alloc()
Returns theByteBufAllocator
for thisRequestContext
.<V> V
attr(AttributeKey<V> key)
Returns the value associated with the givenAttributeKey
ornull
if there's no value set byRequestContext.setAttr(AttributeKey, Object)
.Iterator<Map.Entry<AttributeKey<?>,Object>>
attrs()
void
cancel()
Cancels the currentRequest
.void
cancel(Throwable cause)
Throwable
cancellationCause()
Returns the cause of cancellation,null
if the request has not been cancelled.String
decodedPath()
Returns the absolute path part of the currentRequest
URI, excluding the query part, decoded in UTF-8.protected T
delegate()
Returns the delegate context.ContextAwareEventLoop
eventLoop()
Returns theContextAwareEventLoop
that is handling the currentRequest
.boolean
hasAttr(AttributeKey<?> key)
boolean
hasOwnAttr(AttributeKey<?> key)
RequestId
id()
<A extends SocketAddress>
AlocalAddress()
Returns the local address of this request, ornull
if the connection is not established yet.RequestLogAccess
log()
Returns theRequestLogAccess
that provides the access to theRequestLog
, which contains the information collected while processing the currentRequest
.RequestLogBuilder
logBuilder()
Returns theRequestLogBuilder
that collects the information about the currentRequest
.MeterRegistry
meterRegistry()
Returns theMeterRegistry
that collects various stats.HttpMethod
method()
Returns the HTTP method of the currentRequest
.<V> V
ownAttr(AttributeKey<V> key)
Returns the value associated with the givenAttributeKey
ornull
if there's no value set byRequestContext.setAttr(AttributeKey, Object)
.Iterator<Map.Entry<AttributeKey<?>,Object>>
ownAttrs()
String
path()
String
query()
<A extends SocketAddress>
AremoteAddress()
Returns the remote address of this request, ornull
if the connection is not established yet.HttpRequest
request()
Returns theHttpRequest
associated with this context, ornull
if there's noHttpRequest
associated with this context yet.ServiceRequestContext
root()
Returns the rootServiceRequestContext
of this context.RpcRequest
rpcRequest()
Returns theRpcRequest
associated with this context, ornull
if there's noRpcRequest
associated with this context.SessionProtocol
sessionProtocol()
Returns theSessionProtocol
of the currentRequest
.<V> V
setAttr(AttributeKey<V> key, V value)
Associates the specified value with the givenAttributeKey
in this context.SSLSession
sslSession()
TheSSLSession
for this request if the connection is made over TLS, ornull
if the connection is not established yet or the connection is not a TLS connection.void
timeoutNow()
Times out the currentRequest
.String
toString()
void
updateRequest(HttpRequest req)
Replaces theHttpRequest
associated with this context with the specified one.void
updateRpcRequest(RpcRequest rpcReq)
Replaces theRpcRequest
associated with this context with the specified one.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
isCancelled, isTimedOut, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, push, replace, run, run
-
Constructor Details
-
RequestContextWrapper
Creates a new instance.
-
-
Method Details
-
delegate
Returns the delegate context. -
root
Description copied from interface:RequestContext
Returns the rootServiceRequestContext
of this context.- Specified by:
root
in interfaceRequestContext
- Returns:
- the root
ServiceRequestContext
, ornull
if this context was not created in the context of a server request.
-
attr
Description copied from interface:RequestContext
Returns the value associated with the givenAttributeKey
ornull
if there's no value set byRequestContext.setAttr(AttributeKey, Object)
.Searching for attributes in a root context
Note: This section applies only to a
ClientRequestContext
. AServiceRequestContext
always has itself as aRequestContext.root()
.If the value does not exist in this context but only in
RequestContext.root()
, this method will return the value from theRequestContext.root()
.
If the value exists both in this context andClientRequestContext ctx = ...; assert ctx.root().attr(KEY).equals("root"); assert ctx.attr(KEY).equals("root"); assert ctx.ownAttr(KEY) == null;
RequestContext.root()
, this method will return the value from this context.ClientRequestContext ctx = ...; assert ctx.root().attr(KEY).equals("root"); assert ctx.ownAttr(KEY).equals("child"); assert ctx.attr(KEY).equals("child");
- Specified by:
attr
in interfaceRequestContext
- See Also:
RequestContext.ownAttr(AttributeKey)
-
ownAttr
Description copied from interface:RequestContext
Returns the value associated with the givenAttributeKey
ornull
if there's no value set byRequestContext.setAttr(AttributeKey, Object)
.Unlike
RequestContext.attr(AttributeKey)
, this does not search inRequestContext.root()
.- Specified by:
ownAttr
in interfaceRequestContext
- See Also:
RequestContext.attr(AttributeKey)
-
hasAttr
Description copied from interface:RequestContext
- Specified by:
hasAttr
in interfaceRequestContext
- See Also:
RequestContext.hasOwnAttr(AttributeKey)
-
hasOwnAttr
Description copied from interface:RequestContext
Returnstrue
if and only if the value associated with the specifiedAttributeKey
is notnull
.Unlike
RequestContext.hasAttr(AttributeKey)
, this does not search inRequestContext.root()
.- Specified by:
hasOwnAttr
in interfaceRequestContext
- See Also:
RequestContext.hasAttr(AttributeKey)
-
attrs
Description copied from interface:RequestContext
Returns theIterator
of allMap.Entry
s this context contains.Searching for attributes in a root context
Note: This section applies only to a
ClientRequestContext
. AServiceRequestContext
always has itself as aRequestContext.root()
.The
Iterator
returned by this method will also yield theMap.Entry
s from theRequestContext.root()
except those whoseAttributeKey
exist already in this context, e.g.
Please note that any changes made to theClientRequestContext ctx = ...; assert ctx.ownAttr(KEY_A).equals("child_a"); assert ctx.root().attr(KEY_A).equals("root_a"); assert ctx.root().attr(KEY_B).equals("root_b"); Iterator<Entry<AttributeKey<?>, Object>> attrs = ctx.attrs(); assert attrs.next().getValue().equals("child_a"); // KEY_A // Skip KEY_A in the root. assert attrs.next().getValue().equals("root_b"); // KEY_B assert attrs.hasNext() == false;
Map.Entry
returned byIterator.next()
never affects theMap.Entry
owned byRequestContext.root()
. For example:
If you want to change the value from the root while iterating, please callClientRequestContext ctx = ...; assert ctx.root().attr(KEY).equals("root"); assert ctx.ownAttr(KEY) == null; Iterator<Entry<AttributeKey<?>, Object>> attrs = ctx.attrs(); Entry<AttributeKey<?>, Object> next = attrs.next(); assert next.getKey() == KEY; // Overriding the root entry creates the client context's own entry. next.setValue("child"); assert ctx.attr(KEY).equals("child"); assert ctx.ownAttr(KEY).equals("child"); // root attribute remains unaffected. assert ctx.root().attr(KEY).equals("root");
RequestContext.attrs()
fromRequestContext.root()
.ClientRequestContext ctx = ...; assert ctx.root().attr(KEY).equals("root"); assert ctx.ownAttr(KEY) == null; // Call attrs() from the root to set a value directly while iterating. Iterator<Entry<AttributeKey<?>, Object>> attrs = ctx.root().attrs(); Entry<AttributeKey<?>, Object> next = attrs.next(); assert next.getKey() == KEY; next.setValue("another_root"); // The ctx does not have its own attribute. assert ctx.ownAttr(KEY) == null; assert ctx.attr(KEY).equals("another_root");
- Specified by:
attrs
in interfaceRequestContext
- See Also:
RequestContext.ownAttrs()
-
ownAttrs
Description copied from interface:RequestContext
Returns theIterator
of allMap.Entry
s this context contains.Unlike
RequestContext.attrs()
, this does not iterateRequestContext.root()
.- Specified by:
ownAttrs
in interfaceRequestContext
- See Also:
RequestContext.attrs()
-
setAttr
Description copied from interface:RequestContext
Associates the specified value with the givenAttributeKey
in this context. If this context previously contained a mapping for theAttributeKey
, the old value is replaced by the specified value. Setnull
not to iterate the mapping fromRequestContext.attrs()
.- Specified by:
setAttr
in interfaceRequestContext
- Returns:
- the old value that has been replaced if there's a mapping for the specified key in this context
or its
RequestContext.root()
, ornull
otherwise.
-
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
-
rpcRequest
Description copied from interface:RequestContext
Returns theRpcRequest
associated with this context, ornull
if there's noRpcRequest
associated with this context.- Specified by:
rpcRequest
in interfaceRequestContext
-
updateRequest
Description copied from interface:RequestContext
Replaces theHttpRequest
associated with this context with the specified one. This method is useful to a decorator that manipulates HTTP request headers.Note that it is a bad idea to change the values of the pseudo headers (
":method"
,":path"
,":scheme"
and":authority"
) when replacing anHttpRequest
, because the properties of this context, such asRequestContext.path()
, are unaffected by such an attempt.- Specified by:
updateRequest
in interfaceRequestContext
- See Also:
HttpRequest.withHeaders(RequestHeaders)
,HttpRequest.withHeaders(RequestHeadersBuilder)
-
updateRpcRequest
Description copied from interface:RequestContext
Replaces theRpcRequest
associated with this context with the specified one. This method is useful to a decorator that manipulates an RPC call.- Specified by:
updateRpcRequest
in interfaceRequestContext
-
sessionProtocol
Description copied from interface:RequestContext
Returns theSessionProtocol
of the currentRequest
.- Specified by:
sessionProtocol
in interfaceRequestContext
-
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
-
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
-
sslSession
Description copied from interface:RequestContext
TheSSLSession
for this request if the connection is made over TLS, ornull
if the connection is not established yet or the connection is not a TLS connection.- Specified by:
sslSession
in interfaceRequestContext
-
id
Description copied from interface:RequestContext
- Specified by:
id
in interfaceRequestContext
-
method
Description copied from interface:RequestContext
Returns the HTTP method of the currentRequest
.- Specified by:
method
in interfaceRequestContext
-
path
Description copied from interface:RequestContext
Returns the absolute path part of the currentRequest
URI, excluding the query part, as defined in RFC3986.- Specified by:
path
in interfaceRequestContext
-
decodedPath
Description copied from interface:RequestContext
Returns the absolute path part of the currentRequest
URI, excluding the query part, decoded in UTF-8.- Specified by:
decodedPath
in interfaceRequestContext
-
query
Description copied from interface:RequestContext
- Specified by:
query
in interfaceRequestContext
-
log
Description copied from interface:RequestContext
Returns theRequestLogAccess
that provides the access to theRequestLog
, which contains the information collected while processing the currentRequest
.- Specified by:
log
in interfaceRequestContext
-
logBuilder
Description copied from interface:RequestContext
Returns theRequestLogBuilder
that collects the information about the currentRequest
.- Specified by:
logBuilder
in interfaceRequestContext
-
meterRegistry
Description copied from interface:RequestContext
Returns theMeterRegistry
that collects various stats.- Specified by:
meterRegistry
in interfaceRequestContext
-
cancel
Description copied from interface:RequestContext
- Specified by:
cancel
in interfaceRequestContext
-
cancel
public void cancel()Description copied from interface:RequestContext
Cancels the currentRequest
.- Specified by:
cancel
in interfaceRequestContext
-
timeoutNow
public void timeoutNow()Description copied from interface:RequestContext
Times out the currentRequest
.- Specified by:
timeoutNow
in interfaceRequestContext
-
cancellationCause
Description copied from interface:RequestContext
Returns the cause of cancellation,null
if the request has not been cancelled.- Specified by:
cancellationCause
in interfaceRequestContext
-
eventLoop
Description copied from interface:RequestContext
Returns theContextAwareEventLoop
that is handling the currentRequest
. TheContextAwareEventLoop
sets thisRequestContext
as the current context before executing any submitted tasks. If you want to useEventLoop
without setting this context, callContextAwareEventLoop.withoutContext()
and use the returnedEventLoop
.- Specified by:
eventLoop
in interfaceRequestContext
-
alloc
Description copied from interface:RequestContext
Returns theByteBufAllocator
for thisRequestContext
. Any buffers created by thisByteBufAllocator
must be reference-counted. If you don't know what this means, you should probably usebyte[]
orByteBuffer
directly instead of calling this method.- Specified by:
alloc
in interfaceRequestContext
-
toString
-