Context.CancellableContext, Context.CancellationListener, Context.Key<T>
Modifier and Type | Method and Description |
---|---|
Context |
attach()
Attach this context to the thread and make it
Context.current() , the previously current context
is returned. |
boolean |
cancel(Throwable cause)
Cancel this context and optionally provide a cause (can be
null ) for the
cancellation. |
Throwable |
cancellationCause()
If a context
Context.isCancelled() then return the cause of the cancellation or
null if context was cancelled without a cause. |
void |
detach(Context toAttach)
Detach the current context from the thread and attach the provided replacement.
|
void |
detachAndCancel(Context toAttach,
Throwable cause)
Cancel this context and detach it as the current context from the thread.
|
boolean |
isCancelled()
Is this context cancelled.
|
boolean |
isCurrent() |
addListener, call, current, currentContextExecutor, fixedContextExecutor, fork, getDeadline, key, keyWithDefault, removeListener, run, withCancellation, withDeadline, withDeadlineAfter, withValue, withValues, withValues, wrap, wrap
public Context attach()
Context
Context.current()
, the previously current context
is returned. It is allowed to attach contexts where Context.isCancelled()
is true
.
Instead of using Context.attach()
& Context.detach(Context)
most use-cases are better
served by using the Context.run(Runnable)
or Context.call(java.util.concurrent.Callable)
to execute work immediately within a context. If work needs to be done in other threads
it is recommended to use the 'wrap' methods or to use a propagating executor.
public void detach(Context toAttach)
Context
Context.current()
a SEVERE message will be logged but the context to attach
will still be bound.public boolean isCurrent()
public boolean cancel(Throwable cause)
null
) for the
cancellation. This will trigger notification of listeners.true
if this context cancelled the context and notified listeners,
false
if the context was already cancelled.public void detachAndCancel(Context toAttach, Throwable cause)
toAttach
- context to make current.cause
- of cancellation, can be null
.public boolean isCancelled()
Context
isCancelled
in class Context
public Throwable cancellationCause()
Context
Context.isCancelled()
then return the cause of the cancellation or
null
if context was cancelled without a cause. If the context is not yet cancelled
will always return null
.
The cancellation cause is provided for informational purposes only and implementations should generally assume that it has already been handled and logged properly.
cancellationCause
in class Context