Class Task

All Implemented Interfaces:
Cloneable, Constrained, MetaDataBeanAware, MetaDataMerged, Validated

public class Task extends MetaData implements Cloneable
A task contains all the information for the scheduler to plan its execution.

For a task to be valid, it needs to have a type and either the one-shat planned execution needs to be specified, or the repeating frequency.

Since:
1.0
  • Constructor Details

    • Task

      public Task()
      Create a new task.
      Since:
      1.0
  • Method Details

    • activateMetaData

      public void activateMetaData()
      Description copied from class: MetaData
      This method is called at least once and maximum once when any meta-data introspection logic is executed.

      You need to implement this method since it will be called after the underlying validation context has been initialized. Incidentally, by doing all your metadata setup here, you don't enforce a performance penalty at each object construction like when you do this in the default constructor.

      Overrides:
      activateMetaData in class MetaData
    • setTaskManager

      public void setTaskManager(TaskManager taskManager)
      Sets this task's task manager.

      This is not intended to be used by the user and will be set by RIFE2 when processing tasks.

      Parameters:
      taskManager - the task manager to set
      Since:
      1.0
    • getTaskManager

      public TaskManager getTaskManager()
      Retrieve this task's task manager.
      Returns:
      this task's task manager; or null if no task manager has been assigned to this task
      Since:
      1.0
    • getTaskOptionValue

      public String getTaskOptionValue(String name) throws SchedulerException
      Retrieve the value of a named task option for this task.

      This method relies on RIFE2 having set the task manager first, without that, the option value will always be null.

      Parameters:
      name - the name of the task option to retrieve
      Returns:
      the value for the named option; or null if the option wasn't available or couldn't be found
      Throws:
      SchedulerException - when an error occurs during the retrieval of the task option
      Since:
      1.0
    • getNextTimestamp

      public long getNextTimestamp() throws FrequencyException
      Calculate the next timestamp in milliseconds since epoch at which this task should execute.
      Returns:
      the next execution timestamp; or -1 if there's no next scheduled time
      Throws:
      FrequencyException - when an error occurred during the timestamp calculation
      Since:
      1.0
    • getNextTimestamp

      public long getNextTimestamp(long start) throws FrequencyException
      Calculate the next timestamp in milliseconds since epoch at which this task should execute, starting from a provided timestamp.
      Parameters:
      start - the starting timestamp in milliseconds since epoch to look for the next execution timestamp
      Returns:
      the next execution timestamp; or -1 if there's no next scheduled time
      Throws:
      FrequencyException - when an error occurred during the timestamp calculation
      Since:
      1.0
    • setType

      public void setType(String type)
      Sets the type of the task, which will be used to execute this task with the Executor that handles the same task type.
      Parameters:
      type - this task's type
      Since:
      1.0
    • type

      public Task type(String type)
      Sets the type of the task, which will be used to execute this task with the Executor that handles the same task type.
      Parameters:
      type - this task's type
      Returns:
      this task instance
      Since:
      1.0
    • getType

      public String getType()
      Retrieves the type of this task
      Returns:
      this task's type; or null if no type was set
    • setPlanned

      public void setPlanned(Date planned)
      Sets the planned timestamp at which this task should execute next.

      This can be set manually for one-shot task execution, or when providing a frequency, RIFE2 will automatically set the planned timestamp based on the frequency specification.

      Parameters:
      planned - the date instance for one-shot task execution
      Since:
      1.0
    • setPlanned

      public void setPlanned(long planned)
      Sets the planned timestamp at which this task should execute next.

      This can be set manually for one-shot task execution, or when providing a frequency, RIFE2 will automatically set the planned timestamp based on the frequency specification.

      Parameters:
      planned - the timestamp in milliseconds since epoch for one-shot task execution
      Since:
      1.0
    • planned

      public Task planned(Date planned)
      Sets the planned timestamp at which this task should execute next.

      This can be set manually for one-shot task execution, or when providing a frequency, RIFE2 will automatically set the planned timestamp based on the frequency specification.

      Parameters:
      planned - the date instance for one-shot task execution
      Returns:
      this task instance
      Since:
      1.0
    • planned

      public Task planned(long planned)
      Sets the planned timestamp at which this task should execute next.
      Parameters:
      planned - the timestamp in milliseconds since epoch for one-shot task execution
      Returns:
      this task instance
      Since:
      1.0
    • getPlanned

      public long getPlanned()
      Retrieve the timestamp at which this task is scheduled for the next execution.
      Returns:
      the next execution timestamp in milliseconds since epoch
      Since:
      1.0
    • setFrequency

      public void setFrequency(Frequency frequency)
      Sets the frequency at which this task should execute repeatedly.
      Parameters:
      frequency - this task's frequency
      Since:
      1.0
    • frequency

      public Task frequency(Frequency frequency)
      Sets the frequency at which this task should execute repeatedly.
      Parameters:
      frequency - this task's frequency
      Returns:
      this task instance
      Since:
      1.0
    • getFrequency

      public Frequency getFrequency()
      Retrieves the frequency at which this task should execute repeatedly.
      Returns:
      this task's frequency; or null if the frequency hasn't been set
      Since:
      1.0
    • setFrequencySpecification

      public void setFrequencySpecification(String specification) throws FrequencyException
      Sets the frequency crontab-like specification at which this task should execute repeatedly.
      Parameters:
      specification - the frequency specification
      Throws:
      FrequencyException - when an error occurred during the parsing of the frequency specification
      Since:
      1.0
    • frequencySpecification

      public Task frequencySpecification(String specification) throws FrequencyException
      Sets the frequency crontab-like specification at which this task should execute repeatedly.
      Parameters:
      specification - the frequency specification
      Returns:
      this task instance
      Throws:
      FrequencyException - when an error occurred during the parsing of the frequency specification
      Since:
      1.0
    • getFrequencySpecification

      public String getFrequencySpecification()
      Retrieves the frequency specification at which this task should execute repeatedly.
      Returns:
      this task's frequency specification; or null if the frequency hasn't been set
      Since:
      1.0
    • createTaskOption

      public TaskOption createTaskOption()
      Create a new task option for this task.

      Make sure to first add this task to a task manager or scheduler so that it receives its unique ID. Without this, the task option will not be properly associated with the task.

      Returns:
      the newly created task option.
      Since:
      1.0
    • setId

      public void setId(int id)
      Sets the unique ID of this task.

      This is intended to be used internally by RIFE2.

      Parameters:
      id - the unique ID of this task.
      Since:
      1.0
    • getId

      public int getId()
      Retrieves the unique ID of this task.
      Returns:
      this task's unique ID; or -1 if the ID hasn't been set yet
      Since:
      1.0
    • setBusy

      public void setBusy(boolean busy)
      Sets whether the task is currently busy being processed by an Executor.

      This is intended to be used internally by RIFE2.

      Parameters:
      busy - true if the task is busy; or false otherwise
      Since:
      1.0
    • isBusy

      public boolean isBusy()
      Indicates whether this task is currently being processed by an Executor.
      Returns:
      true if the task is busy; or false otherwise
      Since:
      1.0
    • clone

      public Task clone() throws CloneNotSupportedException
      Overrides:
      clone in class MetaData
      Throws:
      CloneNotSupportedException
    • equals

      public boolean equals(Object object)
      Overrides:
      equals in class Object