public abstract class AbstractRequestContext extends Object implements RequestContext
RequestContext implementation.| Constructor and Description |
|---|
AbstractRequestContext() |
| Modifier and Type | Method and Description |
|---|---|
io.netty.channel.EventLoop |
contextAwareEventLoop()
Returns an
EventLoop that will make sure this RequestContext is set as the current
context before executing any callback. |
Executor |
contextAwareExecutor()
Returns an
Executor that will make sure this RequestContext is set as the current
context before executing any callback. |
boolean |
equals(Object obj) |
Executor |
executor()
|
int |
hashCode() |
boolean |
isTimedOut()
Returns whether this
RequestContext has been timed-out (e.g., when the corresponding request
passes a deadline). |
<T,U> BiConsumer<T,U> |
makeContextAware(BiConsumer<T,U> action)
Returns a
BiConsumer that makes sure the current RequestContext is set and then invokes
the input action. |
<T,U,V> BiFunction<T,U,V> |
makeContextAware(BiFunction<T,U,V> function)
Returns a
BiFunction that makes sure the current RequestContext is set and then invokes
the input function. |
<T> Callable<T> |
makeContextAware(Callable<T> callable)
Returns a
Callable that makes sure the current RequestContext is set and then invokes
the input callable. |
io.netty.channel.ChannelFutureListener |
makeContextAware(io.netty.channel.ChannelFutureListener listener)
Returns a
ChannelFutureListener that makes sure the current RequestContext is set and
then invokes the input listener. |
<T> CompletableFuture<T> |
makeContextAware(CompletableFuture<T> future)
Returns a
CompletableFuture that makes sure the current CompletableFuture is set and
then invokes the input future. |
<T> CompletionStage<T> |
makeContextAware(CompletionStage<T> stage)
Returns a
CompletionStage that makes sure the current CompletionStage is set and
then invokes the input stage. |
<T> Consumer<T> |
makeContextAware(Consumer<T> action)
Returns a
Consumer that makes sure the current RequestContext is set and then invokes
the input action. |
Executor |
makeContextAware(Executor executor)
Returns an
Executor that will execute callbacks in the given executor, making sure to
propagate the current RequestContext into the callback execution. |
ExecutorService |
makeContextAware(ExecutorService executor)
Returns an
ExecutorService that will execute callbacks in the given executor, making
sure to propagate the current RequestContext into the callback execution. |
<T,R> Function<T,R> |
makeContextAware(Function<T,R> function)
Returns a
Function that makes sure the current RequestContext is set and then invokes
the input function. |
<T> io.netty.util.concurrent.FutureListener<T> |
makeContextAware(io.netty.util.concurrent.FutureListener<T> listener)
Returns a
FutureListener that makes sure the current RequestContext is set and then
invokes the input listener. |
<T extends io.netty.util.concurrent.Future<?>> |
makeContextAware(io.netty.util.concurrent.GenericFutureListener<T> listener)
Returns a
GenericFutureListener that makes sure the current RequestContext is set and
then invokes the input listener. |
Runnable |
makeContextAware(Runnable runnable)
Returns a
Runnable that makes sure the current RequestContext is set and then invokes
the input runnable. |
ScheduledExecutorService |
makeContextAware(ScheduledExecutorService executor)
Returns a
ScheduledExecutorService that will execute callbacks in the given executor,
making sure to propagate the current RequestContext into the callback execution. |
void |
onEnter(Runnable 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(Runnable callback)
Registers
callback to be run when re-exiting this RequestContext, usually when using
the RequestContext.makeContextAware(java.util.concurrent.Executor) family of methods. |
SafeCloseable |
push()
Pushes the specified context to the thread-local stack.
|
SafeCloseable |
push(boolean runCallbacks)
Pushes the specified context to the thread-local stack.
|
SafeCloseable |
pushIfAbsent()
Pushes this context to the thread-local stack if there is no current context.
|
void |
rejectPromise(io.netty.util.concurrent.Promise<?> promise,
Throwable cause)
Rejects the specified
promise with the specified cause. |
void |
resolvePromise(io.netty.util.concurrent.Promise<?> promise,
Object result)
Resolves the specified
promise with the specified result so that the promise is
marked as 'done'. |
void |
setTimedOut()
Deprecated.
|
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitalloc, attrs, current, currentOrNull, decodedPath, eventLoop, id, invokeOnChildCallbacks, invokeOnEnterCallbacks, invokeOnExitCallbacks, localAddress, log, logBuilder, mapCurrent, meterRegistry, method, newDerivedContext, onChild, onEnter, onExit, path, push, push, query, remoteAddress, request, rpcRequest, sessionProtocol, sslSession, updateRequest, updateRpcRequestpublic final Executor executor()
RequestContextexecutor in interface RequestContextpublic final Executor contextAwareExecutor()
RequestContextExecutor that will make sure this RequestContext is set as the current
context before executing any callback. This should almost always be used for executing asynchronous
callbacks in service code to make sure features that require the RequestContext work properly.
Most asynchronous libraries like CompletableFuture provide methods that accept an
Executor to run callbacks on.contextAwareExecutor in interface RequestContextpublic final io.netty.channel.EventLoop contextAwareEventLoop()
RequestContextEventLoop that will make sure this RequestContext is set as the current
context before executing any callback.contextAwareEventLoop in interface RequestContextpublic final SafeCloseable push()
RequestContextSafeCloseable.close(), which can be done using a try-with-resources block:
try (SafeCloseable ignored = ctx.push()) {
...
}
The callbacks added by RequestContext.onEnter(Consumer) and RequestContext.onExit(Consumer) will be invoked
when the context is pushed to and removed from the thread-local stack respectively.
NOTE: In case of re-entrance, the callbacks will never run.
push in interface RequestContextpublic final SafeCloseable push(boolean runCallbacks)
RequestContextSafeCloseable.close(), which can be done using a try-with-resources block:
try (PushHandle ignored = ctx.push(true)) {
...
}
NOTE: This method is only useful when it is undesirable to invoke the callbacks, such as replacing
the current context with another. Prefer RequestContext.push() otherwise.
push in interface RequestContextrunCallbacks - if true, the callbacks added by RequestContext.onEnter(Consumer) and
RequestContext.onExit(Consumer) will be invoked when the context is pushed to and
removed from the thread-local stack respectively.
If false, no callbacks will be executed.
NOTE: In case of re-entrance, the callbacks will never run.public final SafeCloseable pushIfAbsent()
RequestContextIllegalStateException.
To pop the context from the stack, call SafeCloseable.close(),
which can be done using a try-with-resources block.pushIfAbsent in interface RequestContextpublic final Executor makeContextAware(Executor executor)
RequestContextExecutor that will execute callbacks in the given executor, making sure to
propagate the current RequestContext into the callback execution. It is generally preferred to
use RequestContext.contextAwareEventLoop() to ensure the callback stays on the same thread as well.makeContextAware in interface RequestContextpublic final ExecutorService makeContextAware(ExecutorService executor)
RequestContextExecutorService that will execute callbacks in the given executor, making
sure to propagate the current RequestContext into the callback execution.makeContextAware in interface RequestContextpublic final ScheduledExecutorService makeContextAware(ScheduledExecutorService executor)
RequestContextScheduledExecutorService that will execute callbacks in the given executor,
making sure to propagate the current RequestContext into the callback execution.makeContextAware in interface RequestContextpublic final <T> Callable<T> makeContextAware(Callable<T> callable)
RequestContextCallable that makes sure the current RequestContext is set and then invokes
the input callable.makeContextAware in interface RequestContextpublic final Runnable makeContextAware(Runnable runnable)
RequestContextRunnable that makes sure the current RequestContext is set and then invokes
the input runnable.makeContextAware in interface RequestContextpublic final <T,R> Function<T,R> makeContextAware(Function<T,R> function)
RequestContextFunction that makes sure the current RequestContext is set and then invokes
the input function.makeContextAware in interface RequestContextpublic final <T,U,V> BiFunction<T,U,V> makeContextAware(BiFunction<T,U,V> function)
RequestContextBiFunction that makes sure the current RequestContext is set and then invokes
the input function.makeContextAware in interface RequestContextpublic final <T> Consumer<T> makeContextAware(Consumer<T> action)
RequestContextConsumer that makes sure the current RequestContext is set and then invokes
the input action.makeContextAware in interface RequestContextpublic final <T,U> BiConsumer<T,U> makeContextAware(BiConsumer<T,U> action)
RequestContextBiConsumer that makes sure the current RequestContext is set and then invokes
the input action.makeContextAware in interface RequestContextpublic final <T> io.netty.util.concurrent.FutureListener<T> makeContextAware(io.netty.util.concurrent.FutureListener<T> listener)
RequestContextFutureListener that makes sure the current RequestContext is set and then
invokes the input listener.makeContextAware in interface RequestContextpublic final io.netty.channel.ChannelFutureListener makeContextAware(io.netty.channel.ChannelFutureListener listener)
RequestContextChannelFutureListener that makes sure the current RequestContext is set and
then invokes the input listener.makeContextAware in interface RequestContextpublic final <T extends io.netty.util.concurrent.Future<?>> io.netty.util.concurrent.GenericFutureListener<T> makeContextAware(io.netty.util.concurrent.GenericFutureListener<T> listener)
RequestContextGenericFutureListener that makes sure the current RequestContext is set and
then invokes the input listener. Unlike other versions of makeContextAware, this one will
invoke the listener with the future's result even if the context has already been timed out.makeContextAware in interface RequestContextpublic final <T> CompletionStage<T> makeContextAware(CompletionStage<T> stage)
RequestContextCompletionStage that makes sure the current CompletionStage is set and
then invokes the input stage.makeContextAware in interface RequestContextpublic final <T> CompletableFuture<T> makeContextAware(CompletableFuture<T> future)
RequestContextCompletableFuture that makes sure the current CompletableFuture is set and
then invokes the input future.makeContextAware in interface RequestContextpublic boolean isTimedOut()
RequestContextRequestContext has been timed-out (e.g., when the corresponding request
passes a deadline).isTimedOut in interface RequestContext@Deprecated public void setTimedOut()
DefaultServiceRequestContext.setTimedOut().RequestContext as having been timed out. Any callbacks created with
makeContextAware that are run after this will be failed with CancellationException.public final void onEnter(Runnable 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.onEnter in interface RequestContextpublic final void onExit(Runnable 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.onExit in interface RequestContextpublic final void resolvePromise(io.netty.util.concurrent.Promise<?> promise,
Object result)
RequestContextpromise with the specified result so that the promise is
marked as 'done'. If promise is done already, this method does the following:
result if it is a reference-counted object,
such as ByteBuf and FullHttpResponse.Promise can be done already even if you did not call this method in the following
cases:
Promise has been timed out.RequestContext.resolvePromise(Promise, Object)RequestContext.rejectPromise(Promise, Throwable)Promise.setSuccess(Object)Promise.setFailure(Throwable)Future.cancel(boolean)resolvePromise in interface RequestContextpublic final void rejectPromise(io.netty.util.concurrent.Promise<?> promise,
Throwable cause)
RequestContextpromise with the specified cause. If promise is done
already, this method logs a warning about the failure. Note that a Promise can be done already
even if you did not call this method in the following cases:
Promise has been timed out.RequestContext.resolvePromise(Promise, Object)RequestContext.rejectPromise(Promise, Throwable)Promise.setSuccess(Object)Promise.setFailure(Throwable)Future.cancel(boolean)rejectPromise in interface RequestContextCopyright © 2020 LeanCloud. All rights reserved.