Interface TaskManager

All Known Implementing Classes:
DatabaseTasks, MemoryTasks

public interface TaskManager
This interface defines the methods that classes with TaskManager functionalities have to implement.
Since:
1.0
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    activateTask(int id)
    This method will be called when the scheduler processes a particular task.
    int
    addTask(Task task)
    Adds a new task.
    boolean
    This method will be called by the scheduler when the task has done processing, any resources should be cleaned up and any task rescheduling, removal or deactivation should be done by the manager here.
    boolean
    This method will be called when the task is fully done being executed.
    Retrieves all the tasks that are registered with this task manager.
    Retrieves the tasks that are not busy and that are schedule to execute some time in the future.
    Retrieves the scheduler of this task manager.
    getTask(int id)
    Retrieves a task from it's unique ID.
    Retrieves the tasks that are not busy and that should be processed next by the scheduled based on the current time.
    boolean
    removeTask(int id)
    Remove a task.
    boolean
    rescheduleTask(Task task, long planned, Frequency frequency)
    Reschedule an existing task at a particular timestamp.
    void
    Sets the scheduler that uses this task manager.
    boolean
    Update an existing task.
  • Method Details

    • setScheduler

      void setScheduler(Scheduler scheduler)
      Sets the scheduler that uses this task manager.
      Parameters:
      scheduler - this task manager's scheduler
      Since:
      1.0
    • getScheduler

      Scheduler getScheduler()
      Retrieves the scheduler of this task manager.
      Returns:
      this task manager's scheduler; or null if the scheduler hasn't been set
      Since:
      1.0
    • addTask

      int addTask(Task task) throws TaskManagerException
      Adds a new task.

      After the task addition, the unique ID of the task should be stored in the provided task instance.

      Parameters:
      task - the task to add
      Returns:
      this unique ID of the added task
      Throws:
      TaskManagerException - when an error occurred during the task addition
      Since:
      1.0
    • updateTask

      boolean updateTask(Task task) throws TaskManagerException
      Update an existing task.

      The task instance should have the unique ID set to be able to update the existing one.

      Parameters:
      task - the updated task
      Returns:
      true if the task was successfully updated; or false otherwise
      Throws:
      TaskManagerException - when an error occurred during the task update
      Since:
      1.0
    • getTask

      Task getTask(int id) throws TaskManagerException
      Retrieves a task from it's unique ID.
      Parameters:
      id - the unique ID of the task to retrieve
      Returns:
      the retrieved task; or null if no such task could be found
      Throws:
      TaskManagerException - when an error occurred during the task retrieval
      Since:
      1.0
    • removeTask

      boolean removeTask(int id) throws TaskManagerException
      Remove a task.
      Parameters:
      id - the unique ID of the task to remove
      Returns:
      true if the task was successfully removed; or false otherwise
      Throws:
      TaskManagerException - when an error occurred during the task removal
      Since:
      1.0
    • getAllTasks

      Collection<Task> getAllTasks() throws TaskManagerException
      Retrieves all the tasks that are registered with this task manager.
      Returns:
      a collection of all the task manager tasks
      Throws:
      TaskManagerException - when an error occurred during the collection of the tasks
      Since:
      1.0
    • getTasksToProcess

      Collection<Task> getTasksToProcess() throws TaskManagerException
      Retrieves the tasks that are not busy and that should be processed next by the scheduled based on the current time.
      Returns:
      a collection of all the tasks that need to be processed
      Throws:
      TaskManagerException - when an error occurred during the collection of the tasks
      Since:
      1.0
    • getScheduledTasks

      Collection<Task> getScheduledTasks() throws TaskManagerException
      Retrieves the tasks that are not busy and that are schedule to execute some time in the future.
      Returns:
      a collection of all the tasks that are scheduled
      Throws:
      TaskManagerException - when an error occurred during the collection of the tasks
      Since:
      1.0
    • rescheduleTask

      boolean rescheduleTask(Task task, long planned, Frequency frequency) throws TaskManagerException
      Reschedule an existing task at a particular timestamp.

      This method will also change the task instance that's provided.

      The task instance should have the unique ID set to be able to update the existing one.

      Parameters:
      task - the task to reschedule
      planned - the planned timestamp in milliseconds since epoch
      frequency - the new frequency of the task
      Returns:
      true if the task was successfully rescheduled; or false otherwise
      Throws:
      TaskManagerException - when an error occurred during the rescheduling of the task
      Since:
      1.0
    • activateTask

      boolean activateTask(int id) throws TaskManagerException
      This method will be called when the scheduler processes a particular task. While being processed, the task should be set as busy.
      Parameters:
      id - the unique ID of the task to activate
      Returns:
      true if the task was successfully activated; or false otherwise
      Throws:
      TaskManagerException - when an error occurred during the activation of the task
      Since:
      1.0
    • deactivateTask

      boolean deactivateTask(int id) throws TaskManagerException
      This method will be called when the task is fully done being executed. The task should be set as not busy.
      Parameters:
      id - the unique ID of the task to deactivate
      Returns:
      true if the task was successfully deactivated; or false otherwise
      Throws:
      TaskManagerException - when an error occurred during the deactivation of the task
      Since:
      1.0
    • concludeTask

      boolean concludeTask(Task task) throws TaskManagerException
      This method will be called by the scheduler when the task has done processing, any resources should be cleaned up and any task rescheduling, removal or deactivation should be done by the manager here.
      Parameters:
      task - the task to conclude
      Returns:
      Throws:
      TaskManagerException - when an error occurred during the conclusion of the task
      Since:
      1.0