public final class AsyncContext
extends java.lang.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(java.util.function.BiPredicate<AsyncContextMap.Key<?>,java.lang.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(java.util.Map<AsyncContextMap.Key<?>,java.lang.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(java.lang.Iterable<AsyncContextMap.Key<?>> entries)
Convenience method to remove all the key/value pairs from the current context.
|
static <T,U> java.util.function.BiConsumer<T,U> |
wrapBiConsume(java.util.function.BiConsumer<T,U> consumer)
Wrap a
BiFunction to ensure it is able to track AsyncContext correctly. |
static <T,U,V> java.util.function.BiFunction<T,U,V> |
wrapBiFunction(java.util.function.BiFunction<T,U,V> func)
Wrap a
BiFunction to ensure it is able to track AsyncContext correctly. |
static <T> java.util.function.Consumer<T> |
wrapConsumer(java.util.function.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> java.util.function.Function<T,U> |
wrapFunction(java.util.function.Function<T,U> func)
Wrap a
Function to ensure it is able to track AsyncContext correctly. |
static java.util.concurrent.Executor |
wrapJdkExecutor(java.util.concurrent.Executor executor)
Wrap an
Executor to ensure it is able to track AsyncContext correctly. |
static java.util.concurrent.ExecutorService |
wrapJdkExecutorService(java.util.concurrent.ExecutorService executor)
Wrap an
ExecutorService to ensure it is able to track AsyncContext correctly. |
static java.util.concurrent.ScheduledExecutorService |
wrapJdkScheduledExecutorService(java.util.concurrent.ScheduledExecutorService executor)
Wrap a
ScheduledExecutorService to ensure it is able to track AsyncContext correctly. |
static java.lang.Runnable |
wrapRunnable(java.lang.Runnable runnable)
Wrap a
Runnable to ensure it is able to track AsyncContext correctly. |
public static AsyncContextMap current()
AsyncContextMap
.AsyncContextMap
public 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(java.util.Map<AsyncContextMap.Key<?>,java.lang.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(java.lang.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(java.util.function.BiPredicate<AsyncContextMap.Key<?>,java.lang.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 java.util.concurrent.Executor wrapJdkExecutor(java.util.concurrent.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 java.util.concurrent.ExecutorService wrapJdkExecutorService(java.util.concurrent.ExecutorService executor)
ExecutorService
to ensure it is able to track AsyncContext
correctly.executor
- The executor to wrap.public static java.util.concurrent.ScheduledExecutorService wrapJdkScheduledExecutorService(java.util.concurrent.ScheduledExecutorService executor)
ScheduledExecutorService
to ensure it is able to track AsyncContext
correctly.executor
- The executor to wrap.public static java.lang.Runnable wrapRunnable(java.lang.Runnable runnable)
Runnable
to ensure it is able to track AsyncContext
correctly.runnable
- The runnable to wrap.Runnable
.public static <T> java.util.function.Consumer<T> wrapConsumer(java.util.function.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> java.util.function.Function<T,U> wrapFunction(java.util.function.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> java.util.function.BiConsumer<T,U> wrapBiConsume(java.util.function.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> java.util.function.BiFunction<T,U,V> wrapBiFunction(java.util.function.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()