public final class AsyncContext
extends Object
This should not be used as a "catch all" to avoid designing APIs which accommodate for your needs. This should be used as a last resort (e.g. for low level framework or infrastructure like tasks) because there maybe non-trivial overhead required to maintain this context.
| Modifier and Type | Method and Description |
|---|---|
static void |
clear()
Convenience method to clear all the key/value pairs from the current context.
|
static boolean |
containsKey(AsyncContextMap.Key<?> key)
Convenience method to determine if the current context contains a key/value entry corresponding to
key. |
static AsyncContextMap |
current()
Get the current
AsyncContextMap. |
static void |
disable()
Disable AsyncContext.
|
static AsyncContextMap.Key<?> |
forEach(BiPredicate<AsyncContextMap.Key<?>,Object> consumer)
Convenience method to iterate over the key/value pairs contained in the current context.
|
static <T> T |
get(AsyncContextMap.Key<T> key)
Convenience method to get the value associated with
key from the current context. |
static boolean |
isEmpty()
Convenience method to determine if there are no key/value pairs in the current context.
|
static <T> void |
put(AsyncContextMap.Key<T> key,
T value)
Convenience method for adding a value to the current context.
|
static void |
putAll(Map<AsyncContextMap.Key<?>,Object> map)
Convenience method for to put all the key/value pairs into the current context.
|
static void |
remove(AsyncContextMap.Key<?> key)
Convenience method to remove a key/value pair from the current context.
|
static void |
removeAll(Iterable<AsyncContextMap.Key<?>> entries)
Convenience method to remove all the key/value pairs from the current context.
|
static <T,U> BiConsumer<T,U> |
wrapBiConsume(BiConsumer<T,U> consumer)
Wrap a
BiFunction to ensure it is able to track AsyncContext correctly. |
static <T,U,V> BiFunction<T,U,V> |
wrapBiFunction(BiFunction<T,U,V> func)
Wrap a
BiFunction to ensure it is able to track AsyncContext correctly. |
static <T> Consumer<T> |
wrapConsumer(Consumer<T> consumer)
Wrap a
Consumer to ensure it is able to track AsyncContext correctly. |
static Executor |
wrapExecutor(Executor executor)
Wrap an
Executor to ensure it is able to track AsyncContext
correctly. |
static <T,U> Function<T,U> |
wrapFunction(Function<T,U> func)
Wrap a
Function to ensure it is able to track AsyncContext correctly. |
static Executor |
wrapJdkExecutor(Executor executor)
Wrap an
Executor to ensure it is able to track AsyncContext correctly. |
static ExecutorService |
wrapJdkExecutorService(ExecutorService executor)
Wrap an
ExecutorService to ensure it is able to track AsyncContext correctly. |
static ScheduledExecutorService |
wrapJdkScheduledExecutorService(ScheduledExecutorService executor)
Wrap a
ScheduledExecutorService to ensure it is able to track AsyncContext correctly. |
static Runnable |
wrapRunnable(Runnable runnable)
Wrap a
Runnable to ensure it is able to track AsyncContext correctly. |
public static AsyncContextMap current()
AsyncContextMap.AsyncContextMappublic static <T> void put(AsyncContextMap.Key<T> key, T value)
T - The type of object associated with key.key - the key used to index value. Cannot be null.value - the value to put.AsyncContextMap.put(AsyncContextMap.Key, Object)public static void putAll(Map<AsyncContextMap.Key<?>,Object> map)
map - contains the key/value pairs that will be added.AsyncContextMap.putAll(Map)public static void remove(AsyncContextMap.Key<?> key)
key - The key to remove.AsyncContextMap.remove(AsyncContextMap.Key)public static void removeAll(Iterable<AsyncContextMap.Key<?>> entries)
entries - A Iterable which contains all the keys to remove.AsyncContextMap.removeAll(Iterable)public static void clear()
AsyncContextMap.clear()@Nullable public static <T> T get(AsyncContextMap.Key<T> key)
key from the current context.T - The anticipated type of object associated with key.key - the key to lookup.key, or null if no value is associated.AsyncContextMap.get(AsyncContextMap.Key)public static boolean containsKey(AsyncContextMap.Key<?> key)
key.key - the key to lookup.true if the current context contains a key/value entry corresponding to key.
false otherwise.AsyncContextMap.containsKey(AsyncContextMap.Key)public static boolean isEmpty()
true if there are no key/value pairs in the current context.AsyncContextMap.isEmpty()@Nullable public static AsyncContextMap.Key<?> forEach(BiPredicate<AsyncContextMap.Key<?>,Object> consumer)
consumer - Each key/value pair will be passed as arguments to this BiPredicate. Returns true
if the consumer wants to keep iterating or false to stop iteration at the current key/value pair.null if consumer iterated through all key/value pairs or the AsyncContextMap.Key
at which the iteration stopped.AsyncContextMap.forEach(BiPredicate)public static Executor wrapJdkExecutor(Executor executor)
Executor to ensure it is able to track AsyncContext correctly.executor - The executor to wrap.public static Executor wrapExecutor(Executor executor)
Executor to ensure it is able to track AsyncContext
correctly.executor - The executor to wrap.public static ExecutorService wrapJdkExecutorService(ExecutorService executor)
ExecutorService to ensure it is able to track AsyncContext correctly.executor - The executor to wrap.public static ScheduledExecutorService wrapJdkScheduledExecutorService(ScheduledExecutorService executor)
ScheduledExecutorService to ensure it is able to track AsyncContext correctly.executor - The executor to wrap.public static Runnable wrapRunnable(Runnable runnable)
Runnable to ensure it is able to track AsyncContext correctly.runnable - The runnable to wrap.Runnable.public static <T> Consumer<T> wrapConsumer(Consumer<T> consumer)
Consumer to ensure it is able to track AsyncContext correctly.T - The type of data consumed by consumer.consumer - The consumer to wrap.Consumer.public static <T,U> Function<T,U> wrapFunction(Function<T,U> func)
Function to ensure it is able to track AsyncContext correctly.T - The type of data consumed by func.U - The type of data returned by func.func - The function to wrap.Function.public static <T,U> BiConsumer<T,U> wrapBiConsume(BiConsumer<T,U> consumer)
BiFunction to ensure it is able to track AsyncContext correctly.T - The type of data consumed by func.U - The type of data consumed by func.consumer - The consumer to wrap.BiConsumer.public static <T,U,V> BiFunction<T,U,V> wrapBiFunction(BiFunction<T,U,V> func)
BiFunction to ensure it is able to track AsyncContext correctly.T - The type of data consumed by func.U - The type of data consumed by func.V - The type of data returned by func.func - The function to wrap.BiFunction.public static void disable()