public abstract class NonWrappingRequestContext extends AbstractRequestContext
RequestContext implementation.| Modifier | Constructor and Description |
|---|---|
protected |
NonWrappingRequestContext(MeterRegistry meterRegistry,
SessionProtocol sessionProtocol,
RequestId id,
HttpMethod method,
String path,
String query,
HttpRequest req,
RpcRequest rpcReq)
Creates a new instance.
|
| Modifier and Type | Method and Description |
|---|---|
<T> io.netty.util.Attribute<T> |
attr(io.netty.util.AttributeKey<T> key) |
Iterator<io.netty.util.Attribute<?>> |
attrs()
Returns all
Attributes set in this context. |
protected abstract io.netty.channel.Channel |
channel()
Returns the
Channel that is handling this request, or null if the connection is not
established yet. |
String |
decodedPath()
Returns the absolute path part of the current
Request URI, excluding the query part,
decoded in UTF-8. |
<T> boolean |
hasAttr(io.netty.util.AttributeKey<T> key) |
RequestId |
id()
|
void |
invokeOnChildCallbacks(RequestContext newCtx)
Invokes all
RequestContext.onChild(BiConsumer) callbacks. |
void |
invokeOnEnterCallbacks()
Invokes all
RequestContext.onEnter(Consumer) callbacks. |
void |
invokeOnExitCallbacks()
Invokes all
RequestContext.onExit(Consumer) callbacks. |
<A extends SocketAddress> |
localAddress()
Returns the local address of this request, or
null if the connection is not established yet. |
MeterRegistry |
meterRegistry()
Returns the
MeterRegistry that collects various stats. |
HttpMethod |
method()
Returns the HTTP method of the current
Request. |
void |
onChild(BiConsumer<? super RequestContext,? super RequestContext> callback)
Registers
callback to be run when this context is replaced by a child context. |
void |
onEnter(Consumer<? super RequestContext> callback)
Registers
callback to be run when re-entering this RequestContext, usually when using
the RequestContext.makeContextAware(java.util.concurrent.Executor) family of methods. |
void |
onExit(Consumer<? super RequestContext> callback)
Registers
callback to be run when re-exiting this RequestContext, usually when using
the RequestContext.makeContextAware(java.util.concurrent.Executor) family of methods. |
String |
path()
|
String |
query()
Returns the query part of the current
Request URI, without the leading '?' |
<A extends SocketAddress> |
remoteAddress()
Returns the remote address of this request, or
null if the connection is not established yet. |
HttpRequest |
request()
Returns the
HttpRequest associated with this context, or null if there's no
HttpRequest associated with this context yet. |
RpcRequest |
rpcRequest()
Returns the
RpcRequest associated with this context, or null if there's no
RpcRequest associated with this context. |
SessionProtocol |
sessionProtocol()
Returns the
SessionProtocol of the current Request. |
protected void |
unsafeUpdateRequest(HttpRequest req)
Replaces the
HttpRequest associated with this context with the specified one
without any validation. |
void |
updateRequest(HttpRequest req)
Replaces the
HttpRequest associated with this context with the specified one. |
void |
updateRpcRequest(RpcRequest rpcReq)
Replaces the
RpcRequest associated with this context with the specified one. |
protected void |
validateHeaders(RequestHeaders headers)
Validates the specified
RequestHeaders. |
contextAwareEventLoop, contextAwareExecutor, equals, executor, hashCode, isTimedOut, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, onEnter, onExit, push, push, pushIfAbsent, rejectPromise, resolvePromise, setTimedOutclone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitalloc, current, currentOrNull, eventLoop, log, logBuilder, mapCurrent, newDerivedContext, push, push, sslSessionprotected NonWrappingRequestContext(MeterRegistry meterRegistry, SessionProtocol sessionProtocol, RequestId id, HttpMethod method, String path, @Nullable String query, @Nullable HttpRequest req, @Nullable RpcRequest rpcReq)
sessionProtocol - the SessionProtocol of the invocationid - the RequestId associated with this contextreq - the HttpRequest associated with this contextrpcReq - the RpcRequest associated with this contextpublic HttpRequest request()
RequestContextHttpRequest associated with this context, or null if there's no
HttpRequest associated with this context yet.public RpcRequest rpcRequest()
RequestContextRpcRequest associated with this context, or null if there's no
RpcRequest associated with this context.public final void updateRequest(HttpRequest req)
RequestContextHttpRequest 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 an HttpRequest,
because the properties of this context, such as RequestContext.path(), are unaffected by such an attempt.
public final void updateRpcRequest(RpcRequest rpcReq)
RequestContextRpcRequest associated with this context with the specified one.
This method is useful to a decorator that manipulates an RPC call.protected void validateHeaders(RequestHeaders headers)
RequestHeaders. By default, this method will raise
an IllegalArgumentException if it does not have ":scheme" or ":authority"
header.protected final void unsafeUpdateRequest(HttpRequest req)
HttpRequest associated with this context with the specified one
without any validation. Internal use only. Use it at your own risk.public final SessionProtocol sessionProtocol()
RequestContextSessionProtocol of the current Request.@Nullable protected abstract io.netty.channel.Channel channel()
Channel that is handling this request, or null if the connection is not
established yet.@Nullable public <A extends SocketAddress> A remoteAddress()
RequestContextnull if the connection is not established yet.@Nullable public <A extends SocketAddress> A localAddress()
RequestContextnull if the connection is not established yet.public final RequestId id()
RequestContextpublic final HttpMethod method()
RequestContextRequest.public final String path()
RequestContextpublic final String decodedPath()
RequestContextRequest URI, excluding the query part,
decoded in UTF-8.public final String query()
RequestContextpublic final MeterRegistry meterRegistry()
RequestContextMeterRegistry that collects various stats.public <T> io.netty.util.Attribute<T> attr(io.netty.util.AttributeKey<T> key)
public <T> boolean hasAttr(io.netty.util.AttributeKey<T> key)
public Iterator<io.netty.util.Attribute<?>> attrs()
RequestContextAttributes set in this context.public final void onEnter(Consumer<? super RequestContext> callback)
RequestContextcallback to be run when re-entering this RequestContext, usually when using
the RequestContext.makeContextAware(java.util.concurrent.Executor) family of methods. Any thread-local state associated with this context
should be restored by this callback.callback - a Consumer whose argument is this contextpublic final void onExit(Consumer<? super RequestContext> callback)
RequestContextcallback to be run when re-exiting this RequestContext, usually when using
the RequestContext.makeContextAware(java.util.concurrent.Executor) family of methods. Any thread-local state associated with this context
should be reset by this callback.callback - a Consumer whose argument is this contextpublic final void onChild(BiConsumer<? super RequestContext,? super RequestContext> callback)
RequestContextcallback 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(() -> { ... });
});
callback - a BiConsumer whose first argument is this context and
whose second argument is the new context that replaces this contextpublic void invokeOnEnterCallbacks()
RequestContextRequestContext.onEnter(Consumer) callbacks. It is discouraged to use this method directly.
Use RequestContext.makeContextAware(Runnable) or RequestContext.push(boolean) instead so that the callbacks are
invoked automatically.public void invokeOnExitCallbacks()
RequestContextRequestContext.onExit(Consumer) callbacks. It is discouraged to use this method directly.
Use RequestContext.makeContextAware(Runnable) or RequestContext.push(boolean) instead so that the callbacks are
invoked automatically.public void invokeOnChildCallbacks(RequestContext newCtx)
RequestContextRequestContext.onChild(BiConsumer) callbacks. It is discouraged to use this method directly.
Use RequestContext.makeContextAware(Runnable) or RequestContext.push(boolean) instead so that the callbacks are
invoked automatically.Copyright © 2020 LeanCloud. All rights reserved.