Class MemoryTasks

java.lang.Object
rife.scheduler.taskmanagers.MemoryTasks
All Implemented Interfaces:
TaskManager

public class MemoryTasks extends Object implements TaskManager
  • Constructor Details

    • MemoryTasks

      public MemoryTasks()
  • Method Details

    • setScheduler

      public void setScheduler(Scheduler scheduler)
      Description copied from interface: TaskManager
      Sets the scheduler that uses this task manager.
      Specified by:
      setScheduler in interface TaskManager
      Parameters:
      scheduler - this task manager's scheduler
    • getScheduler

      public Scheduler getScheduler()
      Description copied from interface: TaskManager
      Retrieves the scheduler of this task manager.
      Specified by:
      getScheduler in interface TaskManager
      Returns:
      this task manager's scheduler; or null if the scheduler hasn't been set
    • addTask

      public int addTask(Task task) throws TaskManagerException
      Description copied from interface: TaskManager
      Adds a new task.

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

      Specified by:
      addTask in interface TaskManager
      Parameters:
      task - the task to add
      Returns:
      this unique ID of the added task
      Throws:
      TaskManagerException - when an error occurred during the task addition
    • updateTask

      public boolean updateTask(Task task) throws TaskManagerException
      Description copied from interface: TaskManager
      Update an existing task.

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

      Specified by:
      updateTask in interface TaskManager
      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
    • getTask

      public Task getTask(int id) throws TaskManagerException
      Description copied from interface: TaskManager
      Retrieves a task from it's unique ID.
      Specified by:
      getTask in interface TaskManager
      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
    • getAllTasks

      public Collection<Task> getAllTasks() throws TaskManagerException
      Description copied from interface: TaskManager
      Retrieves all the tasks that are registered with this task manager.
      Specified by:
      getAllTasks in interface TaskManager
      Returns:
      a collection of all the task manager tasks
      Throws:
      TaskManagerException - when an error occurred during the collection of the tasks
    • getTasksToProcess

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

      public Collection<Task> getScheduledTasks() throws TaskManagerException
      Description copied from interface: TaskManager
      Retrieves the tasks that are not busy and that are schedule to execute some time in the future.
      Specified by:
      getScheduledTasks in interface TaskManager
      Returns:
      a collection of all the tasks that are scheduled
      Throws:
      TaskManagerException - when an error occurred during the collection of the tasks
    • removeTask

      public boolean removeTask(int id) throws TaskManagerException
      Description copied from interface: TaskManager
      Remove a task.
      Specified by:
      removeTask in interface TaskManager
      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
    • rescheduleTask

      public boolean rescheduleTask(Task task, long planned, Frequency frequency) throws TaskManagerException
      Description copied from interface: TaskManager
      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.

      Specified by:
      rescheduleTask in interface TaskManager
      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
    • concludeTask

      public boolean concludeTask(Task task) throws TaskManagerException
      Description copied from interface: TaskManager
      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.
      Specified by:
      concludeTask in interface TaskManager
      Parameters:
      task - the task to conclude
      Returns:
      Throws:
      TaskManagerException - when an error occurred during the conclusion of the task
    • activateTask

      public boolean activateTask(int id) throws TaskManagerException
      Description copied from interface: TaskManager
      This method will be called when the scheduler processes a particular task. While being processed, the task should be set as busy.
      Specified by:
      activateTask in interface TaskManager
      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
    • deactivateTask

      public boolean deactivateTask(int id) throws TaskManagerException
      Description copied from interface: TaskManager
      This method will be called when the task is fully done being executed. The task should be set as not busy.
      Specified by:
      deactivateTask in interface TaskManager
      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