Class TaskManager

java.lang.Object
org.mpi_sws.jmc.runtime.TaskManager

public class TaskManager extends Object
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.
  • Constructor Details

    • TaskManager

      public TaskManager()
      Constructs a new TaskManager object.
  • Method Details

    • reset

      public void reset()
      Resets the TaskManager object.
    • addNextTask

      public Long 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

      public <T> CompletableFuture<T> pause(Long taskId) throws TaskAlreadyPaused
      Pauses the task with the specified custom ID. A new future is created and stored in the taskFutures map. If the task is already paused, a TaskAlreadyPaused exception 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

      public void resume(Long taskId) throws TaskNotExists
      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

      public <T> void resume(Long taskId, T value) throws TaskNotExists
      Throws:
      TaskNotExists
    • error

      public void error(Long taskId, Exception e)
    • terminate

      public void terminate(Long taskId)
      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

      public void markStatus(Long taskId, TaskManager.TaskState state)
      Update the state of the task with the specified custom ID.
      Parameters:
      taskId - the custom ID of the task
      state - the new state of the task
    • getStatus

      public TaskManager.TaskState getStatus(Long taskId)
      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

      public List<Long> findTasksWithStatus(TaskManager.TaskState state)
      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

      public List<Long> getActiveTasks()
      Return custom IDs of all the tasks.
      Returns:
      a list of custom IDs of all the tasks
    • isTaskOfStatus

      public boolean isTaskOfStatus(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.
      Parameters:
      taskId - the custom ID of the task
      state - the state of the task
      Returns:
      true if the task exists with status
    • wait

      public <T> T wait(Long taskId) throws InterruptedException, ExecutionException
      Wait for the task with the specified custom ID to complete.
      Parameters:
      taskId - the custom ID of the task
      Throws:
      InterruptedException
      ExecutionException
    • stopAll

      public void stopAll()
      Stop all the tasks in the task pool.