Package com.linecorp.armeria.common
Class NonWrappingRequestContext
- java.lang.Object
-
- com.linecorp.armeria.common.AbstractRequestContext
-
- com.linecorp.armeria.common.NonWrappingRequestContext
-
- All Implemented Interfaces:
RequestContext
,AttributeMap
- Direct Known Subclasses:
DefaultClientRequestContext
,DefaultServiceRequestContext
public abstract class NonWrappingRequestContext extends AbstractRequestContext
DefaultRequestContext
implementation.
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
NonWrappingRequestContext(MeterRegistry meterRegistry, SessionProtocol sessionProtocol, HttpMethod method, String path, String query, Request request)
Creates a new instance.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description <T> Attribute<T>
attr(AttributeKey<T> key)
Iterator<Attribute<?>>
attrs()
Returns allAttribute
s set in this context.protected abstract Channel
channel()
Returns theChannel
that is handling this request, ornull
if the connection is not established yet.String
decodedPath()
Returns the absolute path part of the currentRequest
URI, excluding the query part, decoded in UTF-8.<T> boolean
hasAttr(AttributeKey<T> key)
void
invokeOnChildCallbacks(RequestContext newCtx)
Invokes allRequestContext.onChild(BiConsumer)
callbacks.void
invokeOnEnterCallbacks()
Invokes allRequestContext.onEnter(Consumer)
callbacks.void
invokeOnExitCallbacks()
Invokes allRequestContext.onExit(Consumer)
callbacks.<A extends SocketAddress>
AlocalAddress()
Returns the local address of this request, ornull
if the connection is not established yet.MeterRegistry
meterRegistry()
Returns theMeterRegistry
that collects various stats.HttpMethod
method()
Returns the HTTP method of the currentRequest
.void
onChild(BiConsumer<? super RequestContext,? super RequestContext> callback)
Registerscallback
to be run when this context is replaced by a child context.void
onEnter(Consumer<? super RequestContext> callback)
Registerscallback
to be run when re-entering thisRequestContext
, usually when using theRequestContext.makeContextAware(java.util.concurrent.Executor)
family of methods.void
onExit(Consumer<? super RequestContext> callback)
Registerscallback
to be run when re-exiting thisRequestContext
, usually when using theRequestContext.makeContextAware(java.util.concurrent.Executor)
family of methods.String
path()
String
query()
<A extends SocketAddress>
AremoteAddress()
Returns the remote address of this request, ornull
if the connection is not established yet.<T extends Request>
Trequest()
Returns theRequest
associated with this context.SessionProtocol
sessionProtocol()
Returns theSessionProtocol
of the currentRequest
.-
Methods inherited from class com.linecorp.armeria.common.AbstractRequestContext
contextAwareEventLoop, equals, hashCode, isTimedOut, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, onEnter, onExit, rejectPromise, resolvePromise, setTimedOut
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.linecorp.armeria.common.RequestContext
alloc, contextAwareExecutor, eventLoop, executor, log, logBuilder, makeContextAware, newDerivedContext, newDerivedContext, push, push, pushIfAbsent, sslSession
-
-
-
-
Constructor Detail
-
NonWrappingRequestContext
protected NonWrappingRequestContext(MeterRegistry meterRegistry, SessionProtocol sessionProtocol, HttpMethod method, String path, @Nullable String query, Request request)
Creates a new instance.- Parameters:
sessionProtocol
- theSessionProtocol
of the invocationrequest
- the request associated with this context
-
-
Method Detail
-
sessionProtocol
public final SessionProtocol sessionProtocol()
Description copied from interface:RequestContext
Returns theSessionProtocol
of the currentRequest
.
-
channel
@Nullable protected abstract Channel channel()
Returns theChannel
that is handling this request, ornull
if the connection is not established yet.
-
remoteAddress
@Nullable public <A extends SocketAddress> A remoteAddress()
Description copied from interface:RequestContext
Returns the remote address of this request, ornull
if the connection is not established yet.
-
localAddress
@Nullable public <A extends SocketAddress> A localAddress()
Description copied from interface:RequestContext
Returns the local address of this request, ornull
if the connection is not established yet.
-
method
public final HttpMethod method()
Description copied from interface:RequestContext
Returns the HTTP method of the currentRequest
.
-
path
public final String path()
Description copied from interface:RequestContext
-
decodedPath
public final String decodedPath()
Description copied from interface:RequestContext
Returns the absolute path part of the currentRequest
URI, excluding the query part, decoded in UTF-8.
-
query
public final String query()
Description copied from interface:RequestContext
-
request
public final <T extends Request> T request()
Description copied from interface:RequestContext
Returns theRequest
associated with this context.
-
meterRegistry
public final MeterRegistry meterRegistry()
Description copied from interface:RequestContext
Returns theMeterRegistry
that collects various stats.
-
attr
public <T> Attribute<T> attr(AttributeKey<T> key)
-
hasAttr
public <T> boolean hasAttr(AttributeKey<T> key)
-
attrs
public Iterator<Attribute<?>> attrs()
Description copied from interface:RequestContext
Returns allAttribute
s set in this context.
-
onEnter
public final void onEnter(Consumer<? super RequestContext> callback)
Description copied from interface:RequestContext
Registerscallback
to be run when re-entering thisRequestContext
, usually when using theRequestContext.makeContextAware(java.util.concurrent.Executor)
family of methods. Any thread-local state associated with this context should be restored by this callback.- Parameters:
callback
- aConsumer
whose argument is this context
-
onExit
public final void onExit(Consumer<? super RequestContext> callback)
Description copied from interface:RequestContext
Registerscallback
to be run when re-exiting thisRequestContext
, usually when using theRequestContext.makeContextAware(java.util.concurrent.Executor)
family of methods. Any thread-local state associated with this context should be reset by this callback.- Parameters:
callback
- aConsumer
whose argument is this context
-
onChild
public final void onChild(BiConsumer<? super RequestContext,? super RequestContext> callback)
Description copied from interface:RequestContext
Registerscallback
to be run when this context is replaced by a child context. You could use this method to inherit an attribute of this context to the child contexts or register a callback to the child contexts that may be created later:ctx.onChild((curCtx, newCtx) -> { assert ctx == curCtx && curCtx != newCtx; // Inherit the value of the 'MY_ATTR' attribute to the child context. newCtx.attr(MY_ATTR).set(curCtx.attr(MY_ATTR).get()); // Add a callback to the child context. newCtx.onExit(() -> { ... }); });
- Parameters:
callback
- aBiConsumer
whose first argument is this context and whose second argument is the new context that replaces this context
-
invokeOnEnterCallbacks
public void invokeOnEnterCallbacks()
Description copied from interface:RequestContext
Invokes allRequestContext.onEnter(Consumer)
callbacks. It is discouraged to use this method directly. UseRequestContext.makeContextAware(Runnable)
orRequestContext.push(boolean)
instead so that the callbacks are invoked automatically.
-
invokeOnExitCallbacks
public void invokeOnExitCallbacks()
Description copied from interface:RequestContext
Invokes allRequestContext.onExit(Consumer)
callbacks. It is discouraged to use this method directly. UseRequestContext.makeContextAware(Runnable)
orRequestContext.push(boolean)
instead so that the callbacks are invoked automatically.
-
invokeOnChildCallbacks
public void invokeOnChildCallbacks(RequestContext newCtx)
Description copied from interface:RequestContext
Invokes allRequestContext.onChild(BiConsumer)
callbacks. It is discouraged to use this method directly. UseRequestContext.makeContextAware(Runnable)
orRequestContext.push(boolean)
instead so that the callbacks are invoked automatically.
-
-