Class TaskManager

  • All Implemented Interfaces:
    ClusterStateApplier

    public class TaskManager
    extends java.lang.Object
    implements ClusterStateApplier
    Task Manager service for keeping track of currently running tasks on the nodes
    • Constructor Detail

      • TaskManager

        public TaskManager​(Settings settings,
                           ThreadPool threadPool,
                           java.util.Set<java.lang.String> taskHeaders)
    • Method Detail

      • setTaskResultsService

        public void setTaskResultsService​(TaskResultsService taskResultsService)
      • register

        public Task register​(java.lang.String type,
                             java.lang.String action,
                             TaskAwareRequest request)
        Registers a task without parent task

        Returns the task manager tracked task or null if the task doesn't support the task manager

      • cancel

        public boolean cancel​(CancellableTask task,
                              java.lang.String reason,
                              java.lang.Runnable listener)
        Cancels a task

        Returns true if cancellation was started successful, null otherwise. After starting cancellation on the parent task, the task manager tries to cancel all children tasks of the current task. Once cancellation of the children tasks is done, the listener is triggered.

      • unregister

        public Task unregister​(Task task)
        Unregister the task
      • storeResult

        public <Response extends ActionResponse> void storeResult​(Task task,
                                                                  java.lang.Exception error,
                                                                  ActionListener<Response> listener)
        Stores the task failure
      • storeResult

        public <Response extends ActionResponse> void storeResult​(Task task,
                                                                  Response response,
                                                                  ActionListener<Response> listener)
        Stores the task result
      • getTasks

        public java.util.Map<java.lang.Long,​Task> getTasks()
        Returns the list of currently running tasks on the node
      • getCancellableTasks

        public java.util.Map<java.lang.Long,​CancellableTask> getCancellableTasks()
        Returns the list of currently running tasks on the node that can be cancelled
      • getTask

        public Task getTask​(long id)
        Returns a task with given id, or null if the task is not found.
      • getCancellableTask

        public CancellableTask getCancellableTask​(long id)
        Returns a cancellable task with given id, or null if the task is not found.
      • getBanCount

        public int getBanCount()
        Returns the number of currently banned tasks.

        Will be used in task manager stats and for debugging.

      • setBan

        public void setBan​(TaskId parentTaskId,
                           java.lang.String reason)
        Bans all tasks with the specified parent task from execution, cancels all tasks that are currently executing.

        This method is called when a parent task that has children is cancelled.

      • removeBan

        public void removeBan​(TaskId parentTaskId)
        Removes the ban for the specified parent task.

        This method is called when a previously banned task finally cancelled

      • waitForTaskCompletion

        public void waitForTaskCompletion​(Task task,
                                          long untilInNanos)
        Blocks the calling thread, waiting for the task to vanish from the TaskManager.