Class Task

java.lang.Object
org.deltava.taskman.Task
All Implemented Interfaces:
Comparable<Task>, Runnable, Thread.UncaughtExceptionHandler
Direct Known Subclasses:
ACARSDataPurgeTask, ACARSPositionPurgeTask, ApplicantPurgeTask, AssignmentPurgeTask, AUSOTDownloadTask, CachedRoutePurgeTask, CachedRouteUpdateTask, CommandLogPurgeTask, CoursePurgeTask, CurrencyRatingTask, CurrencyRidePurgeTask, DraftPIREPPurgeTask, EliteScoringTask, EventAssignTask, FAAChartLoaderTask, FlightAggregateTask, GFSDownloadTask, HeldFlightTask, HTTPLogStatisticsTask, ImageLinkTestTask, InactivityUpdateTask, JobCloseTask, METARDownloadTask, NATDownloadTask, OnlineTrackTask, PACOTDownloadTask, PromotionListTask, PushInvalidationTask, QueueWarningTask, ScheduleFilterTask, SELCALPurgeTask, TAFDownloadTask, TransferPurgeTask

public abstract class Task extends Object implements Runnable, Comparable<Task>, Thread.UncaughtExceptionHandler
A class to support Scheduled Tasks. Scheduled Tasks are similar to UNIX cron jobs, and are scheduled for execution in much the same way.
Since:
1.0
Version:
11.1
Author:
Luke
  • Field Details

    • TIME_OPTS

      public static final String[] TIME_OPTS
      Time interval options.
    • ANY

      static final Integer ANY
      Wildcard for "All Intervals"
    • log

      protected final Logger log
  • Constructor Details

    • Task

      protected Task(String name, Class<?> loggerClass)
      Creates a new Scheduled Task with a given class name.
      Parameters:
      name - the task name
      loggerClass - the logger Class for Log4J
  • Method Details

    • getID

      public String getID()
      Returns the Task ID.
      Returns:
      the ID
    • getName

      public String getName()
      Returns the Task name.
      Returns:
      the name
    • getLastRunTime

      public long getLastRunTime()
      Returns how the last execution duration of this Task.
      Returns:
      the last execution duration in milliseconds, or 0 if the Task has never been executed
    • getRunCount

      public int getRunCount()
      Returns the number of times this Task has been executed.
      Returns:
      the number of executions
    • getStartTime

      public Instant getStartTime()
      Returns the when this Task was last started on.
      Returns:
      the date/time the Task was last started, or null if the Task has never been executed
    • getEnabled

      public boolean getEnabled()
      Returns if the Task is allowed to be executed.
      Returns:
      TRUE if the Task can be executed, otherwise FALSE
      See Also:
    • getRunTimes

      Map<String, Collection<Integer>> getRunTimes()
      Returns the times this Task is eligible to be run.
      Returns:
      a Map of interval types and values
      See Also:
    • isRunnable

      public boolean isRunnable()
      Returns whether the Scheduled Task can be executed at the present time.
      Returns:
      TRUE if the Task can be executed, otherwise FALSE
      See Also:
    • isRunnable

      boolean isRunnable(Instant dt)
      Determines whether this Scheduled Task is runnable at a particular date/time. This is package private for unit testing purposes.
      Parameters:
      dt - the date/time to execute the task at
      Returns:
      TRUE if the Task can be executed, otherwise FALSE
      See Also:
    • setID

      public void setID(String id)
      Sets the Task ID.
      Parameters:
      id - the ID
      Throws:
      NullPointerException - if id is null
    • setRunTimes

      public void setRunTimes(String intervalType, String values)
      Sets the time of the day this Task may run in.
      Parameters:
      intervalType - the time interval Type
      values - a comma-delimited set of numbers
      See Also:
    • setEnabled

      public void setEnabled(boolean enabled)
      Marks the Task as enabled to execute.
      Parameters:
      enabled - TRUE if the task is enabled, otherwise FALES
      See Also:
    • setStartTime

      public void setStartTime(Instant dt)
      Overrides the last execution time for this Task.
      Parameters:
      dt - the date/time this Task last executed
      See Also:
    • setLastExecTime

      public void setLastExecTime(long execTime)
      Overrides the last execution duration for this Task.
      Parameters:
      execTime - the last execution duration in milliseconds
      See Also:
    • run

      public void run()
      Executes the Task. This logs execution start/stop times and calls each Task implementation's execute(TaskContext) method.
      Specified by:
      run in interface Runnable
    • run

      public void run(Pilot usr)
      Executes the Task. This logs execution start/stop times and calls each Task implementation's execute(TaskContext) method.
      Parameters:
      usr - overrides the user executing the Task if not null
    • logError

      protected void logError(String msg, Throwable t)
      Error logger, sends error details to Log4J and NewRelic.
      Parameters:
      msg - the message preface
      t - a Throwable
    • compareTo

      public int compareTo(Task t2)
      Specified by:
      compareTo in interface Comparable<Task>
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • uncaughtException

      public void uncaughtException(Thread t, Throwable e)
      Specified by:
      uncaughtException in interface Thread.UncaughtExceptionHandler
    • execute

      protected abstract void execute(TaskContext ctx)
      Executes the Task.
      Parameters:
      ctx - the TaskContext