public class Timers extends Object implements Startable, Stoppable
Other than for statistical reasons, this class does not need to be called directly. It automatically discovers all parts registered for one of the timer interfaces (EveryMinute, EveryTenMinutes, EveryHour, EveryDay) and invokes them appropriately.
To access this class, a Part annotation can be used on a field of type TimerService.
Modifier and Type | Field and Description |
---|---|
static int |
LIFECYCLE_PRIORITY
Determines the start and stop order of the timers lifecycle.
|
protected static Log |
LOG |
static String |
TIMER_DAILY_PREFIX
Contains the config prefix to load settings for daily tasks from.
|
DEFAULT_PRIORITY
Constructor and Description |
---|
Timers() |
Modifier and Type | Method and Description |
---|---|
void |
addWatchedResource(URL url,
Runnable callback)
Adds the given file to the list of watched resources in DEVELOP mode (
Sirius.isDev() . |
Collection<EveryDay> |
getDailyTasks()
Returns all known daily tasks.
|
String |
getLastHourExecution()
Returns the timestamp of the last execution of the one hour timer.
|
String |
getLastOneMinuteExecution()
Returns the timestamp of the last execution of the one minute timer.
|
String |
getLastTenMinutesExecution()
Returns the timestamp of the last execution of the ten minutes timer.
|
String |
getLastTenSecondsExecution()
Returns the timestamp of the last execution of the 10 second timer.
|
int |
getPriority()
Returns the priority of this element.
|
void |
rundailyTimer(int currentHour,
EveryDay task)
Executes the given task if it is scheduled for the given hour.
|
void |
runEveryDayTimers(int currentHour)
Executes all daily timers (implementing EveryDay) if applicable, or if outOfASchedule is true.
|
void |
runOneHourTimers()
Executes all one hour timers (implementing EveryHour) now (out of schedule).
|
void |
runOneMinuteTimers()
Executes all one minute timers (implementing EveryMinute) now (out of schedule).
|
void |
runTenMinuteTimers()
Executes all ten minutes timers (implementing EveryTenMinutes) now (out of schedule).
|
void |
runTenSecondTimers()
Executes all one minute timers (implementing EveryTenSeconds) now (out of schedule).
|
void |
started()
Invoked when the framework starts up.
|
void |
stopped()
Invoked when the framework shuts down.
|
protected static final Log LOG
public static final String TIMER_DAILY_PREFIX
public static final int LIFECYCLE_PRIORITY
public int getPriority()
Priorized
getPriority
in interface Priorized
getPriority
in interface Startable
getPriority
in interface Stoppable
public String getLastTenSecondsExecution()
public String getLastOneMinuteExecution()
public String getLastTenMinutesExecution()
public String getLastHourExecution()
public void started()
Startable
public void stopped()
Stoppable
This method must not block (and wait for internals to stop). This can be done in
Killable.awaitTermination()
.
public void addWatchedResource(@Nonnull URL url, @Nonnull Runnable callback)
Sirius.isDev()
.
This is used to reload files like properties in development environments. In production systems, no reloading will be performed.
url
- the file to watchcallback
- the callback to invoke once the file has changedpublic void runTenSecondTimers()
public void runOneMinuteTimers()
public void runTenMinuteTimers()
public void runOneHourTimers()
public void runEveryDayTimers(int currentHour)
currentHour
- determines the current hour. Most probably this will be wall-clock time. However, for
out-of-schedule eecution, this can be set to any value.public Collection<EveryDay> getDailyTasks()
public void rundailyTimer(int currentHour, EveryDay task)
currentHour
- the hour to pretendtask
- the task to executeCopyright © 2018. All rights reserved.