Class RequestContextWrapper<T extends RequestContext>
- Type Parameters:
T
- the self type
- All Implemented Interfaces:
RequestContext
,Unwrappable
- Direct Known Subclasses:
ClientRequestContextWrapper
,ServiceRequestContextWrapper
RequestContext
.-
Constructor Summary
ModifierConstructorDescriptionprotected
RequestContextWrapper
(T delegate) Creates a new instance. -
Method Summary
Modifier and TypeMethodDescriptionalloc()
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)
.attrs()
void
cancel()
Cancels the currentRequest
.void
Returns the cause of cancellation,null
if the request has not been cancelled.Returns the absolute path part of the currentRequest
URI, excluding the query part, decoded in UTF-8.protected final T
delegate()
Deprecated.Returns theContextAwareEventLoop
that is handling the currentRequest
.boolean
hasAttr
(AttributeKey<?> key) boolean
hasOwnAttr
(AttributeKey<?> key) id()
Initiates connection shutdown and returnsCompletableFuture
that completes when the connection associated with this context is closed.<A extends SocketAddress>
AReturns the local address of this request, ornull
if the connection is not established yet.log()
Returns theRequestLogAccess
that provides the access to theRequestLog
, which contains the information collected while processing the currentRequest
.Returns theRequestLogBuilder
that collects the information about the currentRequest
.Returns theMeterRegistry
that collects various stats.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)
.ownAttrs()
path()
query()
<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.root()
Returns the rootServiceRequestContext
of this context.Returns theRpcRequest
associated with this context, ornull
if there's noRpcRequest
associated with this context.Returns theSessionProtocol
of the currentRequest
.<V> V
setAttr
(AttributeKey<V> key, V value) Associates the specified value with the givenAttributeKey
in this context.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
Times out the currentRequest
.toString()
Unwraps this object and returns the innermost object being decorated.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.uri()
Methods inherited from class com.linecorp.armeria.common.util.AbstractUnwrappable
as, unwrap
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, makeContextAware, push, replace, run, run, unwrap
Methods inherited from interface com.linecorp.armeria.common.util.Unwrappable
as, equalsIgnoreWrapper
-
Constructor Details
-
RequestContextWrapper
Creates a new instance.
-
-
Method Details
-
delegate
Deprecated.UseAbstractUnwrappable.unwrap()
instead.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:
-
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:
-
hasAttr
Description copied from interface:RequestContext
- Specified by:
hasAttr
in interfaceRequestContext
- See Also:
-
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:
-
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:
-
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:
-
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:
-
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
-
uri
Description copied from interface:RequestContext
- Specified by:
uri
in interfaceRequestContext
- See Also:
-
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
-
unwrapAll
Description copied from interface:Unwrappable
Unwraps this object and returns the innermost object being decorated. If thisUnwrappable
is the innermost object, this method returns itself. For example:class Foo implements Unwrappable {} class Bar<T extends Unwrappable> extends AbstractUnwrappable<T> { Bar(T delegate) { super(delegate); } } class Qux<T extends Unwrappable> extends AbstractUnwrappable<T> { Qux(T delegate) { super(delegate); } } Foo foo = new Foo(); assert foo.unwrapAll() == foo; Bar<Foo> bar = new Bar<>(foo); assert bar.unwrapAll() == foo; Qux<Bar<Foo>> qux = new Qux<>(bar); assert qux.unwrap() == bar; assert qux.unwrapAll() == foo;
- Specified by:
unwrapAll
in interfaceRequestContext
- Specified by:
unwrapAll
in interfaceUnwrappable
- Overrides:
unwrapAll
in classAbstractUnwrappable<T extends RequestContext>
-
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
-
exchangeType
Description copied from interface:RequestContext
- Specified by:
exchangeType
in interfaceRequestContext
-
initiateConnectionShutdown
Description copied from interface:RequestContext
Initiates connection shutdown and returnsCompletableFuture
that completes when the connection associated with this context is closed.- Specified by:
initiateConnectionShutdown
in interfaceRequestContext
- See Also:
-
toString
- Overrides:
toString
in classAbstractUnwrappable<T extends RequestContext>
-
AbstractUnwrappable.unwrap()
instead.