Interface TaskController

All Known Implementing Classes:
DefaultConsumerTaskController, DefaultProcessorTaskController, DefaultProducerTaskController, DefaultTaskController

public interface TaskController
The TaskController is responsible for controlling the lifecycle of a task. The TaskManager will call the methods of this interface to notify the TaskController of various events that occur during the lifecycle of a task, and the TaskController will return the list of TaskActions to perform in response to those events. The TaskController is generally free to decide how to respond to these events, for example implementing worker-level retry logic or implementing a circuit-breaker pattern, but to ensure correctness, it must conform to the high-level task lifecycle defined by the TaskManager.
  • Method Details

    • onTaskStart

      List<TaskAction> onTaskStart()
      Called when a task has been started. Called as the first event only.
      Returns:
      the next actions to perform
    • onWorkerStarted

      List<TaskAction> onWorkerStarted(int id)
      Called when a worker was started successfully in response to a start request.
      Parameters:
      id - the id of the worker that was started
      Returns:
      the next actions to perform
      See Also:
    • onWorkerStopped

      List<TaskAction> onWorkerStopped(int id)
      Called when a worker was stopped in response to a stop request.
      Parameters:
      id - the id of the worker that was stopped
      Returns:
      the next action to perform
      See Also:
    • onWorkerCompletedNormally

      List<TaskAction> onWorkerCompletedNormally(int id)
      Called when a worker completed normally, for example because all input messages were processed.
      Parameters:
      id - the id of the worker that completed
      Returns:
      the next action to perform
    • onWorkerCompletedExceptionally

      List<TaskAction> onWorkerCompletedExceptionally(int id, Throwable e)
      Called when a worker completed exceptionally by propagating an exception.
      Parameters:
      id - the id of the worker that completed
      e - the exception that caused the worker to complete exceptionally
      Returns:
      the next action to perform
    • onCancelRequested

      List<TaskAction> onCancelRequested()
      Called when the user has requested to cancel this task. In general, this means that the controller should stop all running workers and finish the task with an appropriate status as soon as possible.
      Returns:
      the next action to perform
      See Also:
    • onHeartbeat

      List<TaskAction> onHeartbeat()
      Called when no lifecycle events have occurred within the heartbeat interval. This ensures that the controller has periodic access to execute actions even if no lifecycle events are occurring, for example to start more workers in response to a backlog of messages, or stop workers in response to no backlog.
      Returns:
      the next action to perform
    • getHeartbeatInterval

      Duration getHeartbeatInterval()
      The maximum amount of time to wait for a lifecycle event, after which onHeartbeat() will be called.
    • onTaskSucceeded

      void onTaskSucceeded()
      Called when the task has been successfully completed. This is the last event that will be called.
    • onTaskCancelled

      void onTaskCancelled()
      Called when the task has been cancelled. This is the last event that will be called.
    • onTaskFailed

      void onTaskFailed(ExecutionException e)
      Called when the task has failed. This is the last event that will be called.
      Parameters:
      e - the exception that caused the task to fail