Class TaskManager<WorkerMetricsT>
java.lang.Object
io.aleph0.yap.core.task.TaskManager<WorkerMetricsT>
- All Implemented Interfaces:
Measureable<TaskManager.Metrics<WorkerMetricsT>>
public class TaskManager<WorkerMetricsT>
extends Object
implements Measureable<TaskManager.Metrics<WorkerMetricsT>>
TaskManager manages the lifecycle of a logical pipeline task, including starting and stopping
workers, handling task actions, and notifying lifecycle listeners. It is designed to be used in a
multi-threaded environment and provides methods for managing worker threads and task actions.
The TaskManager delegates decision making to a TaskController instance, which is
responsible for deciding what actions to take based on the current state of the task and the
workers, and the TaskManager is responsible for executing those actions.
Internally, the TaskManager models the task state as a finite state machine with the following states:
READY ─► RUNNING ─► COMPLETED
│ │
│ └────► CANCELLED
│
└───────► FAILED
To ensure correctness, it enforces that the task can only perform the above transitions between
states. (So, for example, the TaskManager will fail if the controller attempts to transition from
COMPLETED to RUNNING or from FAILED to CANCELLED.) Within the
boundaries of these constraints, the TaskController is completely free to decide what actions to
take.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfacestatic final recordstatic enumstatic enumstatic interfacestatic interface -
Constructor Summary
ConstructorsConstructorDescriptionTaskManager(int pipeline, String id, Set<String> subscribers, ExecutorService executor, TaskController controller, TaskManager.WorkerBodyFactory<WorkerMetricsT> workerBodyFactory, Queue<?> queue, Topic<?> topic) -
Method Summary
Modifier and TypeMethodDescriptionvoidNon-destructive check of the metrics.Destructive read of the metrics.getId()intvoidvoidrun()protected io.aleph0.yap.core.task.TaskManager.StartedWorker<WorkerMetricsT> protected voidprotected int
-
Constructor Details
-
TaskManager
public TaskManager(int pipeline, String id, Set<String> subscribers, ExecutorService executor, TaskController controller, TaskManager.WorkerBodyFactory<WorkerMetricsT> workerBodyFactory, Queue<?> queue, Topic<?> topic)
-
-
Method Details
-
getPipeline
public int getPipeline() -
getId
-
getSubscribers
-
addLifecycleListener
-
removeLifecycleListener
-
run
-
startWorker
protected io.aleph0.yap.core.task.TaskManager.StartedWorker<WorkerMetricsT> startWorker() throws RejectedExecutionException- Throws:
RejectedExecutionException
-
stopAnyWorker
protected int stopAnyWorker() -
stopAllWorkers
protected void stopAllWorkers() -
checkMetrics
Description copied from interface:MeasureableNon-destructive check of the metrics. This should be used to check the state of metrics without clearing them, for example in aTaskController.- Specified by:
checkMetricsin interfaceMeasureable<WorkerMetricsT>- Returns:
- the metrics
-
flushMetrics
Description copied from interface:MeasureableDestructive read of the metrics. This should be used to check and reset the state of metrics, for example by the metrics checking thread.- Specified by:
flushMetricsin interfaceMeasureable<WorkerMetricsT>- Returns:
- the metrics
-