Package org.mpi_sws.jmc.runtime
Class TaskManager
java.lang.Object
org.mpi_sws.jmc.runtime.TaskManager
Encapsulates all the operations related to Task objects used by the runtime Except the
SchedulerTask The encapsulation ensures no memory leak when creating many tasks.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumThe state of each task managed by the @RuntimeEnvironment is represented by one of the following. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAdds a new task to the TaskManager object.voidReturn all the tasks with the specified state.Return custom IDs of all the tasks.Return the state of the task with the specified custom ID.booleanisTaskOfStatus(Long taskId, TaskManager.TaskState state) Return true if the task with the specified system task ID is in the task pool and with status provided.voidmarkStatus(Long taskId, TaskManager.TaskState state) Update the state of the task with the specified custom ID.<T> CompletableFuture<T> Pauses the task with the specified custom ID.voidreset()Resets the TaskManager object.voidResumes the task with the specified custom ID.<T> voidintsize()Return the size of the task pool.voidstopAll()Stop all the tasks in the task pool.voidTerminates the task with the specified custom ID.<T> TWait for the task with the specified custom ID to complete.
-
Constructor Details
-
TaskManager
public TaskManager()Constructs a new TaskManager object.
-
-
Method Details
-
reset
public void reset()Resets the TaskManager object. -
addNextTask
Adds a new task to the TaskManager object. The task is assigned the next available task ID and a default name "Task-ID".- Returns:
- the ID of the task
-
pause
Pauses the task with the specified custom ID. A new future is created and stored in thetaskFuturesmap. If the task is already paused, aTaskAlreadyPausedexception is thrown.- Parameters:
taskId- the custom ID of the task- Returns:
- a future that completes when the task is resumed
- Throws:
TaskAlreadyPaused- if the task with the specified custom ID is already paused
-
resume
Resumes the task with the specified custom ID. The future associated with the task is completed.- Parameters:
taskId- the custom ID of the task- Throws:
TaskNotExists- if the task with the specified custom ID does not exist
-
resume
- Throws:
TaskNotExists
-
error
-
terminate
Terminates the task with the specified custom ID. The future associated with the task is completed.- Parameters:
taskId- the custom ID of the task
-
size
public int size()Return the size of the task pool.- Returns:
- the size of the task pool
-
markStatus
Update the state of the task with the specified custom ID.- Parameters:
taskId- the custom ID of the taskstate- the new state of the task
-
getStatus
Return the state of the task with the specified custom ID.- Parameters:
taskId- the custom ID of the task- Returns:
- the state of the task
-
findTasksWithStatus
Return all the tasks with the specified state.- Parameters:
state- the state of the tasks to find- Returns:
- a list of tasks with the specified state
-
getActiveTasks
Return custom IDs of all the tasks.- Returns:
- a list of custom IDs of all the tasks
-
isTaskOfStatus
Return true if the task with the specified system task ID is in the task pool and with status provided.- Parameters:
taskId- the custom ID of the taskstate- the state of the task- Returns:
- true if the task exists with status
-
wait
Wait for the task with the specified custom ID to complete.- Parameters:
taskId- the custom ID of the task- Throws:
InterruptedExceptionExecutionException
-
stopAll
public void stopAll()Stop all the tasks in the task pool.
-