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. |
Closeable |
attachAsCloseable()
Attach this context to the thread and return a
AutoCloseable that can be
used with try-with-resource statements to properly attach the previously bound context
when AutoCloseable.close() is called. |
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(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, current, fork, key, keyWithDefault, propagate, removeListener, withCancellation, withDeadlineAfter, withDeadlineNanoTime, withValue, withValues, withValues, wrap, 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
.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 Closeable attachAsCloseable()
AutoCloseable
that can be
used with try-with-resource statements to properly attach the previously bound context
when AutoCloseable.close()
is called.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(Context toAttach, @Nullable Throwable cause)
toAttach
- context to make current.cause
- of cancellation, can be null
.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.