java.lang.Object
org.elasticsearch.tasks.Task
org.elasticsearch.tasks.CancellableTask
- All Implemented Interfaces:
Traceable
- Direct Known Subclasses:
AllocatedPersistentTask,BulkByScrollTask,DownsampleTask,SearchShardTask,SearchTask
A task that can be cancelled
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceThis 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 voidThis method adds a listener that needs to be notified if this task is cancelled.final voidThrows aTaskCancelledExceptionif this task has been cancelled, otherwise does nothing.final StringThe reason the task was cancelled or null if it hasn't been cancelled.final booleanReturn whether the task is cancelled.final <T> booleannotifyIfCancelled(ActionListener<T> listener) Notifies the listener of failure with aTaskCancelledExceptionif this task has been cancelled, otherwise does nothing.protected voidCalled after the task is cancelled so that it can take any actions that it has to take.booleanReturns whether this task's children need to be cancelled too.toString()Methods inherited from class org.elasticsearch.tasks.Task
getAction, getDescription, getHeader, getId, getParentTaskId, getSpanId, getStartTime, getStartTimeNanos, getStatus, getType, headers, result, result, taskInfo, taskInfo
-
Constructor Details
-
CancellableTask
-
-
Method Details
-
shouldCancelChildrenOnCancellation
public boolean shouldCancelChildrenOnCancellation()Returns whether this task's children need to be cancelled too.trueis 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 returningfalsesaves 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 aTaskCancelledExceptionif this task has been cancelled, otherwise does nothing. -
notifyIfCancelled
Notifies the listener of failure with aTaskCancelledExceptionif this task has been cancelled, otherwise does nothing.- Returns:
trueif the task is cancelled and the listener was notified, otherwisefalse.
-
toString
-