Interface ClusterStateTaskExecutor.TaskContext<T extends ClusterStateTaskListener>

Enclosing interface:
ClusterStateTaskExecutor<T extends ClusterStateTaskListener>

public static interface ClusterStateTaskExecutor.TaskContext<T extends ClusterStateTaskListener>
A task to be executed, along with callbacks for the executor to record the outcome of this task's execution. The executor must call exactly one of these methods for every task in its batch.
  • Method Details

    • getTask

      T getTask()
      Returns:
      the task to be executed.
    • success

      void success(ActionListener<ClusterState> publishListener)
      Record that the task succeeded.

      Note that some tasks implement ClusterStateAckListener and can listen for acks themselves. If so, you may not use this method and must instead call success(ActionListener, ClusterStateAckListener), passing the task itself as the clusterStateAckListener argument.

      Parameters:
      publishListener - A listener for the completion of the resulting cluster state publication. This listener is completed with the cluster state that was published (or the publication exception that occurred) in the thread context in which the task was submitted. The task's ClusterStateTaskListener.clusterStateProcessed(org.elasticsearch.cluster.ClusterState, org.elasticsearch.cluster.ClusterState) method is not called directly by the master service, nor is ClusterStateTaskListener.onFailure(java.lang.Exception) once the task execution has succeeded, but legacy implementations may supply a listener which calls those methods.

      The listener should prefer not to use the published state for things like determining the result of a task. The task may have been executed as part of a batch, and later tasks in the batch may overwrite the results from earlier tasks. Instead the listener should independently capture the information it needs to properly process the completion of a cluster state update.

    • success

      void success(ActionListener<ClusterState> publishListener, ClusterStateAckListener clusterStateAckListener)
      Record that the task succeeded.

      Note that some tasks implement ClusterStateAckListener and can listen for acks themselves. If so, you must pass the task itself as the clusterStateAckListener argument.

      Parameters:
      publishListener - A listener for the completion of the resulting cluster state publication. This listener is completed with the cluster state that was published (or the publication exception that occurred) in the thread context in which the task was submitted. The task's ClusterStateTaskListener.clusterStateProcessed(org.elasticsearch.cluster.ClusterState, org.elasticsearch.cluster.ClusterState) method is not called directly by the master service, nor is ClusterStateTaskListener.onFailure(java.lang.Exception) once the task execution has succeeded, but legacy implementations may use this listener to call those methods.

      The listener should prefer not to use the published state for things like determining the result of a task. The task may have been executed as part of a batch, and later tasks in the batch may overwrite the results from earlier tasks. Instead the listener should independently capture the information it needs to properly process the completion of a cluster state update.

      clusterStateAckListener - A listener for acknowledgements from nodes. If the publication succeeds then this listener is completed as nodes ack the state update. If the publication fails then the failure notification happens via publishListener.onFailure(): this listener is not notified.
    • success

      default void success(ClusterStateAckListener clusterStateAckListener)
      Record that the task succeeded.

      Note that some tasks implement ClusterStateAckListener and can listen for acks themselves. If so, you must pass the task itself as the clusterStateAckListener argument.

      This method is useful in cases where the task will take some action at the end of acking but takes no action at the end of publication. If publication fails then the task's ClusterStateTaskListener.onFailure(java.lang.Exception) method is called.

      Parameters:
      clusterStateAckListener - A listener for acknowledgements from nodes. If the publication succeeds then this listener is completed as nodes ack the state update. If the publication fails then the failure notification happens via publishListener.onFailure(): this listener is not notified.
    • onFailure

      void onFailure(Exception failure)
      Record that the cluster state update task failed.
      Parameters:
      failure - The exception with which the task failed.