Class SmallRyeThreadContext
- All Implemented Interfaces:
org.eclipse.microprofile.context.ThreadContext
-
Nested Class Summary
Nested Classes -
Field Summary
Fields inherited from interface org.eclipse.microprofile.context.ThreadContext
ALL_REMAINING, APPLICATION, CDI, NONE, SECURITY, TRANSACTION -
Constructor Summary
ConstructorsConstructorDescriptionSmallRyeThreadContext(SmallRyeContextManager manager, String[] propagated, String[] unchanged, String[] cleared, String injectionPointName, ExecutorService defaultExecutor) -
Method Summary
Modifier and TypeMethodDescriptionbuilder()<U> CompletableFuture<U> completedFuture(U value) Returns a new CompletableFuture that is already completed with the specified value.<U> CompletionStage<U> completedStage(U value) Returns a new CompletionStage that is already completed with the specified value.<R> Callable<R> contextualCallable(Callable<R> callable) <T,U> BiConsumer <T, U> contextualConsumer(BiConsumer<T, U> consumer) <T> Consumer<T> contextualConsumer(Consumer<T> consumer) <T,U, R> BiFunction <T, U, R> contextualFunction(BiFunction<T, U, R> function) <T,R> Function <T, R> contextualFunction(Function<T, R> function) contextualRunnable(Runnable runnable) <R> Supplier<R> contextualSupplier(Supplier<R> supplier) <T> CompletableFuture<T> copy(CompletableFuture<T> stage) Returns a newCompletableFuturethat is completed by the completion of the specified stage.<T> CompletionStage<T> copy(CompletionStage<T> stage) Returns a newCompletionStagethat is completed by the completion of the specified stage.<U> CompletableFuture<U> Returns a new CompletableFuture that is already exceptionally completed with the specified Throwable.<U> CompletionStage<U> failedStage(Throwable ex) Returns a new CompletionStage that is already exceptionally completed with the specified Throwable.static SmallRyeThreadContextReturns the current thread's @{link SmallRyeThreadContext} if set, or null.static SmallRyeThreadContextgetCurrentThreadContext(SmallRyeThreadContext defaultValue) Returns the current thread's @{link SmallRyeThreadContext} if set, or the given @{link SmallRyeThreadContext} default value.static SmallRyeThreadContextReturns the current thread's @{link SmallRyeThreadContext} if set, or a @{link SmallRyeThreadContext} which clears all contexts.static SmallRyeThreadContextReturns the current thread's @{link SmallRyeThreadContext} if set, or a @{link SmallRyeThreadContext} with default contexts, possibly configured via MP Config.static SmallRyeThreadContextReturns the current thread's @{link SmallRyeThreadContext} if set, or a @{link SmallRyeThreadContext} which propagates all contexts.getPlan()booleanisContextualized(Object lambda) Returns true if the given lambda instance is already contextualizedbooleanisEmpty()Returns true if this thread context has no context to propagate nor clear, and so will not contextualise anything.<U> CompletableFuture<U> Returns a new incompleteCompletableFuture.toString()<T> CompletableFuture<T> withContextCapture(CompletableFuture<T> future) Returns a newCompletableFuturethat is completed by the completion of the specified stage.<T> CompletableFuture<T> withContextCapture(CompletableFuture<T> future, Executor executor, int flags) <T> CompletionStage<T> withContextCapture(CompletionStage<T> stage) Returns a newCompletionStagethat is completed by the completion of the specified stage.<T> CompletionStage<T> withContextCapture(CompletionStage<T> stage, Executor executor) static CleanAutoCloseablewithThreadContext(SmallRyeThreadContext threadContext) Updates the current @{link SmallRyeThreadContext} in use by the current thread, and returns an object suitable for use in try-with-resource to restore the previous value.static voidwithThreadContext(SmallRyeThreadContext threadContext, Runnable f) Invokes the given @{link Runnable} with the current @{link SmallRyeThreadContext} updated to the given value for the current thread.static <T> TwithThreadContext(SmallRyeThreadContext threadContext, Supplier<T> f) Invokes the given @{link Supplier} with the current @{link SmallRyeThreadContext} updated to the given value for the current thread.
-
Constructor Details
-
SmallRyeThreadContext
public SmallRyeThreadContext(SmallRyeContextManager manager, String[] propagated, String[] unchanged, String[] cleared, String injectionPointName, ExecutorService defaultExecutor)
-
-
Method Details
-
withThreadContext
Updates the current @{link SmallRyeThreadContext} in use by the current thread, and returns an object suitable for use in try-with-resource to restore the previous value.- Parameters:
threadContext- the @{link SmallRyeThreadContext} to use- Returns:
- an object suitable for use in try-with-resource to restore the previous value.
-
withThreadContext
Invokes the given @{link Runnable} with the current @{link SmallRyeThreadContext} updated to the given value for the current thread.- Parameters:
threadContext- the @{link SmallRyeThreadContext} to usef- the @{link Runnable} to invoke
-
withThreadContext
Invokes the given @{link Supplier} with the current @{link SmallRyeThreadContext} updated to the given value for the current thread.- Type Parameters:
T- The type of @{link Supplier} to return- Parameters:
threadContext- the @{link SmallRyeThreadContext} to usef- the @{link Supplier} to invoke- Returns:
- The value returned by the @{link Supplier}
-
getCurrentThreadContextOrDefaultContexts
Returns the current thread's @{link SmallRyeThreadContext} if set, or a @{link SmallRyeThreadContext} with default contexts, possibly configured via MP Config.- Returns:
- the current thread's @{link SmallRyeThreadContext} if set, or a @{link SmallRyeThreadContext} with default contexts, possibly configured via MP Config.
-
getCurrentThreadContextOrPropagatedContexts
Returns the current thread's @{link SmallRyeThreadContext} if set, or a @{link SmallRyeThreadContext} which propagates all contexts.- Returns:
- the current thread's @{link SmallRyeThreadContext} if set, or a @{link SmallRyeThreadContext} which propagates all contexts.
-
getCurrentThreadContextOrClearedContexts
Returns the current thread's @{link SmallRyeThreadContext} if set, or a @{link SmallRyeThreadContext} which clears all contexts.- Returns:
- the current thread's @{link SmallRyeThreadContext} if set, or a @{link SmallRyeThreadContext} which clears all contexts.
-
getCurrentThreadContext
Returns the current thread's @{link SmallRyeThreadContext} if set, or the given @{link SmallRyeThreadContext} default value.- Parameters:
defaultValue- the default value to use- Returns:
- the current thread's @{link SmallRyeThreadContext} if set, or the given @{link SmallRyeThreadContext} default value.
-
getCurrentThreadContext
Returns the current thread's @{link SmallRyeThreadContext} if set, or null.- Returns:
- the current thread's @{link SmallRyeThreadContext} if set, or null.
-
getPlan
-
getDefaultExecutor
-
isEmpty
public boolean isEmpty()Returns true if this thread context has no context to propagate nor clear, and so will not contextualise anything.- Returns:
- true if this thread context has no context to propagate nor clear
-
isContextualized
Returns true if the given lambda instance is already contextualized- Parameters:
lambda- the lambda to test- Returns:
- true if the given lambda instance is already contextualized
-
builder
-
withContextCapture
Returns a new
CompletableFuturethat is completed by the completion of the specified stage.The new completable future will use the same default executor as this ThreadContext, which can be a ManagedExecutor if this ThreadContext was obtained by
SmallRyeManagedExecutor.getThreadContext()or the default executor service as set bySmallRyeContextManager.Builder.withDefaultExecutorService(ExecutorService), or otherwise have no default executor. If this thread context has no default executor, the new stage and all dependent stages created from it, and so forth, have no default asynchronous execution facility and must raiseUnsupportedOperationExceptionfor all*Asyncmethods that do not specify an executor. For example,thenRunAsync(Runnable).When dependent stages are created from the new completable future, thread context is captured and/or cleared as described in the documentation of the
ManagedExecutorclass, except that this ThreadContext instance takes the place of the default asynchronous execution facility in supplying the configuration of cleared/propagated context types. This guarantees that the action performed by each stage always runs under the thread context of the code that creates the stage, unless the user explicitly overrides by supplying a pre-contextualized action.Invocation of this method does not impact thread context propagation for the supplied completable future or any dependent stages created from it, other than the new dependent completable future that is created by this method.
- Specified by:
withContextCapturein interfaceorg.eclipse.microprofile.context.ThreadContext- Type Parameters:
T- completable future result type.- Parameters:
future- a completable future whose completion triggers completion of the new completable future that is created by this method.- Returns:
- the new completable future.
-
withContextCapture
public <T> CompletableFuture<T> withContextCapture(CompletableFuture<T> future, Executor executor, int flags) -
withContextCapture
Returns a new
CompletionStagethat is completed by the completion of the specified stage.The new completion stage will use the same default executor as this ThreadContext, which can be a ManagedExecutor if this ThreadContext was obtained by
SmallRyeManagedExecutor.getThreadContext()or the default executor service as set bySmallRyeContextManager.Builder.withDefaultExecutorService(ExecutorService), or otherwise have no default executor. If this thread context has no default executor, the new stage and all dependent stages created from it, and so forth, and/or cleared as described in the documentation of theManagedExecutorclass, except that this ThreadContext instance takes the place of the default asynchronous execution facility in supplying the configuration of cleared/propagated context types. This guarantees that the action performed by each stage always runs under the thread context of the code that creates the stage, unless the user explicitly overrides by supplying a pre-contextualized action.Invocation of this method does not impact thread context propagation for the supplied stage or any dependent stages created from it, other than the new dependent completion stage that is created by this method.
- Specified by:
withContextCapturein interfaceorg.eclipse.microprofile.context.ThreadContext- Type Parameters:
T- completion stage result type.- Parameters:
stage- a completion stage whose completion triggers completion of the new stage that is created by this method.- Returns:
- the new completion stage.
-
withContextCapture
-
completedFuture
Returns a new CompletableFuture that is already completed with the specified value.
The new completable future will use the same default executor as this ThreadContext, which can be a ManagedExecutor if this ThreadContext was obtained by
SmallRyeManagedExecutor.getThreadContext()or the default executor service as set bySmallRyeContextManager.Builder.withDefaultExecutorService(ExecutorService), or otherwise have no default executor.- Type Parameters:
U- result type of the completable future.- Parameters:
value- result with which the completable future is completed.- Returns:
- the new completable future.
-
completedStage
Returns a new CompletionStage that is already completed with the specified value.
The new completion stage will use the same default executor as this ThreadContext, which can be a ManagedExecutor if this ThreadContext was obtained by
SmallRyeManagedExecutor.getThreadContext()or the default executor service as set bySmallRyeContextManager.Builder.withDefaultExecutorService(ExecutorService), or otherwise have no default executor.- Type Parameters:
U- result type of the completion stage.- Parameters:
value- result with which the completable future is completed.- Returns:
- the new completion stage.
-
failedFuture
Returns a new CompletableFuture that is already exceptionally completed with the specified Throwable.
The new completable future will use the same default executor as this ThreadContext, which can be a ManagedExecutor if this ThreadContext was obtained by
SmallRyeManagedExecutor.getThreadContext()or the default executor service as set bySmallRyeContextManager.Builder.withDefaultExecutorService(ExecutorService), or otherwise have no default executor.- Type Parameters:
U- result type of the completable future.- Parameters:
ex- exception or error with which the completable future is completed.- Returns:
- the new completable future.
-
failedStage
Returns a new CompletionStage that is already exceptionally completed with the specified Throwable.
The new completion stage will use the same default executor as this ThreadContext, which can be a ManagedExecutor if this ThreadContext was obtained by
SmallRyeManagedExecutor.getThreadContext()or the default executor service as set bySmallRyeContextManager.Builder.withDefaultExecutorService(ExecutorService), or otherwise have no default executor.- Type Parameters:
U- result type of the completion stage.- Parameters:
ex- exception or error with which the stage is completed.- Returns:
- the new completion stage.
-
newIncompleteFuture
Returns a new incomplete
CompletableFuture.The new completable future will use the same default executor as this ThreadContext, which can be a ManagedExecutor if this ThreadContext was obtained by
SmallRyeManagedExecutor.getThreadContext()or the default executor service as set bySmallRyeContextManager.Builder.withDefaultExecutorService(ExecutorService), or otherwise have no default executor.- Type Parameters:
U- result type of the completion stage.- Returns:
- the new completion stage.
-
copy
Returns a new
CompletableFuturethat is completed by the completion of the specified stage.The new completable future is backed by the ManagedExecutor upon which copy is invoked, which serves as the default asynchronous execution facility for the new stage and all dependent stages created from it, and so forth.
When dependent stages are created from the new completable future, thread context is captured and/or cleared by the ManagedExecutor. This guarantees that the action performed by each stage always runs under the thread context of the code that creates the stage, unless the user explicitly overrides by supplying a pre-contextualized action.
Invocation of this method does not impact thread context propagation for the supplied completable future or any dependent stages created from it, other than the new dependent completable future that is created by this method.
- Type Parameters:
T- completable future result type.- Parameters:
stage- a completable future whose completion triggers completion of the new completable future that is created by this method.- Returns:
- the new completable future.
-
copy
Returns a new
CompletionStagethat is completed by the completion of the specified stage.The new completable future is backed by the ManagedExecutor upon which copy is invoked, which serves as the default asynchronous execution facility for the new stage and all dependent stages created from it, and so forth.
When dependent stages are created from the new completable future, thread context is captured and/or cleared by the ManagedExecutor. This guarantees that the action performed by each stage always runs under the thread context of the code that creates the stage, unless the user explicitly overrides by supplying a pre-contextualized action.
Invocation of this method does not impact thread context propagation for the supplied stage or any dependent stages created from it, other than the new dependent completion stage that is created by this method.
- Type Parameters:
T- completion stage result type.- Parameters:
stage- a completion stage whose completion triggers completion of the new stage that is created by this method.- Returns:
- the new completion stage.
-
currentContextExecutor
- Specified by:
currentContextExecutorin interfaceorg.eclipse.microprofile.context.ThreadContext
-
contextualConsumer
- Specified by:
contextualConsumerin interfaceorg.eclipse.microprofile.context.ThreadContext
-
contextualFunction
- Specified by:
contextualFunctionin interfaceorg.eclipse.microprofile.context.ThreadContext
-
contextualCallable
- Specified by:
contextualCallablein interfaceorg.eclipse.microprofile.context.ThreadContext
-
contextualConsumer
- Specified by:
contextualConsumerin interfaceorg.eclipse.microprofile.context.ThreadContext
-
contextualFunction
- Specified by:
contextualFunctionin interfaceorg.eclipse.microprofile.context.ThreadContext
-
contextualRunnable
- Specified by:
contextualRunnablein interfaceorg.eclipse.microprofile.context.ThreadContext
-
contextualSupplier
- Specified by:
contextualSupplierin interfaceorg.eclipse.microprofile.context.ThreadContext
-
toString
-