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 Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionint
protected abstract void
execute
(TaskContext ctx) Executes the Task.boolean
Returns if the Task is allowed to be executed.getID()
Returns the Task ID.long
Returns how the last execution duration of this Task.getName()
Returns the Task name.int
Returns the number of times this Task has been executed.(package private) Map
<String, Collection<Integer>> Returns the times this Task is eligible to be run.Returns the when this Task was last started on.int
hashCode()
boolean
Returns whether the Scheduled Task can be executed at the present time.(package private) boolean
isRunnable
(Instant dt) Determines whether this Scheduled Task is runnable at a particular date/time.protected void
Error logger, sends error details to Log4J and NewRelic.void
run()
Executes the Task.void
Executes the Task.void
setEnabled
(boolean enabled) Marks the Task as enabled to execute.void
Sets the Task ID.void
setLastExecTime
(long execTime) Overrides the last execution duration for this Task.void
setRunTimes
(String intervalType, String values) Sets the time of the day this Task may run in.void
setStartTime
(Instant dt) Overrides the last execution time for this Task.void
uncaughtException
(Thread t, Throwable e)
-
Field Details
-
TIME_OPTS
Time interval options. -
ANY
Wildcard for "All Intervals" -
log
-
-
Constructor Details
-
Task
-
-
Method Details
-
getID
-
getName
-
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
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
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
Sets the Task ID.- Parameters:
id
- the ID- Throws:
NullPointerException
- if id is null
-
setRunTimes
-
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
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'sexecute(TaskContext)
method. -
run
Executes the Task. This logs execution start/stop times and calls each Task implementation'sexecute(TaskContext)
method.- Parameters:
usr
- overrides the user executing the Task if not null
-
logError
-
compareTo
- Specified by:
compareTo
in interfaceComparable<Task>
-
hashCode
-
uncaughtException
- Specified by:
uncaughtException
in interfaceThread.UncaughtExceptionHandler
-
execute
Executes the Task.- Parameters:
ctx
- the TaskContext
-