Context.CancellableContext, Context.CancellationListener, Context.Key<T>
Modifier and Type | Method and Description |
---|---|
void |
attach()
Attach this context to the thread and make it
Context.current() , the previously current context
will be restored when detach is called. |
Closeable |
attachAsCloseable()
Attach this context to the thread and return a
AutoCloseable that can be
used with try-with-resource statements to properly detach() and cancel(java.lang.Throwable)
the context on completion. |
protected boolean |
canBeCancelled() |
boolean |
cancel(Throwable cause)
Cancel this context and optionally provide a cause for the cancellation.
|
Throwable |
cause()
If a context
Context.isCancelled() then return the cause of the cancellation or
null if context was cancelled without a cause. |
void |
detach()
Detach the current context from the thread and restore the context that was previously
attached to the thread as the 'current' context.
|
void |
detachAndCancel(Throwable cause)
Cancel this context and detach it from the current context from the thread and restore the
context that was previously attached to the thread as the 'current' context.
|
boolean |
isCancelled()
Is this context cancelled.
|
boolean |
isCurrent() |
addListener, current, fork, key, keyWithDefault, removeListener, withCancellation, withDeadlineAfter, withDeadlineNanoTime, withValue, withValues, withValues, wrap, wrap
public void attach()
Context
Context.current()
, the previously current context
will be restored when detach is called. It is allowed to attach contexts where
Context.isCancelled()
is true
.public void detach()
Context
public boolean isCurrent()
public Closeable attachAsCloseable()
AutoCloseable
that can be
used with try-with-resource statements to properly detach()
and cancel(java.lang.Throwable)
the context on completion.Closeable
which can be used with try-with-resource blocks.public boolean cancel(@Nullable Throwable cause)
true
if this context cancelled the context and notified listeners,
false
if the context was already cancelled.public void detachAndCancel(@Nullable Throwable cause)
IllegalStateException
- if this context is not Context.current()
.protected boolean canBeCancelled()
public boolean isCancelled()
Context
isCancelled
in class Context
@Nullable public Throwable cause()
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 cause is provided for informational purposes only and implementations should generally assume that it has already been handled and logged properly.