java.lang.Object
org.elasticsearch.tasks.Task
org.elasticsearch.tasks.CancellableTask
- Direct Known Subclasses:
AllocatedPersistentTask
,BulkByScrollTask
,SearchShardTask
,SearchTask
A task that can be cancelled
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
This interface is implemented by any class that needs to react to the cancellation of this task.Nested classes/interfaces inherited from class org.elasticsearch.tasks.Task
Task.Status
-
Field Summary
Fields inherited from class org.elasticsearch.tasks.Task
APM_TRACE_CONTEXT, HEADERS_TO_COPY, TRACE_ID, TRACE_PARENT, TRACE_PARENT_HTTP_HEADER, TRACE_START_TIME, TRACE_STATE, X_ELASTIC_PRODUCT_ORIGIN_HTTP_HEADER, X_OPAQUE_ID_HTTP_HEADER
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal void
This method adds a listener that needs to be notified if this task is cancelled.final void
Throws aTaskCancelledException
if this task has been cancelled, otherwise does nothing.final String
The reason the task was cancelled or null if it hasn't been cancelled.final boolean
Return whether the task is cancelled.final <T> boolean
notifyIfCancelled
(ActionListener<T> listener) Notifies the listener of failure with aTaskCancelledException
if this task has been cancelled, otherwise does nothing.protected void
Called after the task is cancelled so that it can take any actions that it has to take.boolean
Returns whether this task's children need to be cancelled too.Methods inherited from class org.elasticsearch.tasks.Task
getAction, getDescription, getHeader, getId, getParentTaskId, getStartTime, getStartTimeNanos, getStatus, getType, headers, result, result, taskInfo, taskInfo, toString
-
Constructor Details
-
CancellableTask
-
-
Method Details
-
shouldCancelChildrenOnCancellation
public boolean shouldCancelChildrenOnCancellation()Returns whether this task's children need to be cancelled too.true
is a reasonable response even for tasks that have no children, since child tasks might be added in future and it'd be easy to forget to update this, but returningfalse
saves a bit of computation in the task manager. -
isCancelled
public final boolean isCancelled()Return whether the task is cancelled. If testing this flag to decide whether to throw aTaskCancelledException
, consider usingensureNotCancelled()
ornotifyIfCancelled(org.elasticsearch.action.ActionListener<T>)
instead: these methods construct an exception that automatically includes the cancellation reason. -
getReasonCancelled
The reason the task was cancelled or null if it hasn't been cancelled. May also be null if the task was just cancelled since we don't set the reason and the cancellation flag atomically. -
addListener
This method adds a listener that needs to be notified if this task is cancelled. -
onCancelled
protected void onCancelled()Called after the task is cancelled so that it can take any actions that it has to take. -
ensureNotCancelled
public final void ensureNotCancelled()Throws aTaskCancelledException
if this task has been cancelled, otherwise does nothing. -
notifyIfCancelled
Notifies the listener of failure with aTaskCancelledException
if this task has been cancelled, otherwise does nothing.- Returns:
true
if the task is cancelled and the listener was notified, otherwisefalse
.
-