Class CancellableTask

java.lang.Object
org.elasticsearch.tasks.Task
org.elasticsearch.tasks.CancellableTask
Direct Known Subclasses:
AllocatedPersistentTask, BulkByScrollTask, SearchShardTask, SearchTask

public class CancellableTask extends Task
A task that can be cancelled
  • Constructor Details

  • 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 returning false 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 a TaskCancelledException, consider using ensureNotCancelled() or notifyIfCancelled(org.elasticsearch.action.ActionListener<T>) instead: these methods construct an exception that automatically includes the cancellation reason.
    • getReasonCancelled

      @Nullable public final String 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

      public final void addListener(CancellableTask.CancellationListener listener)
      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 a TaskCancelledException if this task has been cancelled, otherwise does nothing.
    • notifyIfCancelled

      public final <T> boolean notifyIfCancelled(ActionListener<T> listener)
      Notifies the listener of failure with a TaskCancelledException if this task has been cancelled, otherwise does nothing.
      Returns:
      true if the task is cancelled and the listener was notified, otherwise false.