Class GuiceRecurringDaemon
java.lang.Object
com.peterphi.std.threading.Daemon
com.peterphi.std.guice.common.daemon.GuiceDaemon
com.peterphi.std.guice.common.daemon.GuiceRecurringDaemon
- All Implemented Interfaces:
GuiceLifecycleListener
,StoppableService
,Runnable
- Direct Known Subclasses:
BackgroundTaskDaemon
,DeleteExpiredSessionDaemon
,GuiceScheduledDaemon
,HealthCheckWorker
,NetworkConfigReloadDaemon
-
Field Summary
-
Constructor Summary
ModifierConstructorDescriptionprotected
GuiceRecurringDaemon
(boolean daemonThread, Timeout sleepTime) Creates a new Daemon; the Daemon will start once the guice object is fully constructedprotected
GuiceRecurringDaemon
(Timeout sleepTime) Creates a new Daemon; the Daemon will start once the guice object is fully constructed -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract void
execute()
Run one iteration of the daemonprotected void
Called when theexecute()
method throws an exception.com.codahale.metrics.Timer
getCalls()
com.codahale.metrics.Meter
boolean
void
Enable Verbose Tracing for the next run of this daemonvoid
Called after this object has been fully and successfully constructedvoid
run()
void
setSleepTime
(Timeout sleepTime) void
boolean
Returns true if the execution of user code should proceed; ordinarily this will return true.void
trigger()
Trigger the user code to run ASAPMethods inherited from class com.peterphi.std.guice.common.daemon.GuiceDaemon
getBreaker, getBreakerNames, getName, getThreadName, notifyBreakerChange, shouldStartAsDaemon, shutdown, sleep, sleep
Methods inherited from class com.peterphi.std.threading.Daemon
getTextState, getTextStateUpdated, getThread, isRunning, isThreadRunning, setTextState, startThread, startThread, stopAll, stopThread, waitForTermination, waitForTermination
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.peterphi.std.guice.common.shutdown.iface.StoppableService
preShutdown
-
Field Details
-
sleepTime
-
-
Constructor Details
-
GuiceRecurringDaemon
Creates a new Daemon; the Daemon will start once the guice object is fully constructed- Parameters:
sleepTime
- the amount of time to sleep between calls to theexecute()
method
-
GuiceRecurringDaemon
Creates a new Daemon; the Daemon will start once the guice object is fully constructed- Parameters:
daemonThread
- true if the thread should be started as a daemon thread, otherwise falsesleepTime
- the amount of time to sleep between calls to theexecute()
method
-
-
Method Details
-
isUserCodeRunning
public boolean isUserCodeRunning() -
setSleepTimeFromConfigIfSet
-
getInitialSleepTime
-
getSleepTime
-
getCalls
public com.codahale.metrics.Timer getCalls() -
getExceptions
public com.codahale.metrics.Meter getExceptions() -
setSleepTime
-
makeNextRunVerbose
public void makeNextRunVerbose()Enable Verbose Tracing for the next run of this daemon -
run
public void run() -
shouldContinue
public boolean shouldContinue()Returns true if the execution of user code should proceed; ordinarily this will return true. If this method returns false then:- If in user code, the user code SHOULD attempt to return control as soon as possible, without leaving any work undone that would not be completed on the next invocation of the user code
- If not in user code, the control logic WILL ensure that user code is not invoked;
Daemon.isRunning()
will also be tested to determine if the daemon should shutdown
- Returns:
-
getLastRan
-
executeException
Called when the
execute()
method throws an exception. This method can be overridden by subclasses to record exception details or to take remedial action. By default it will log the exception at the ERROR level.Note: Any exception thrown by this method will cause the thread to terminate
- Parameters:
t
- the exception that was caught
-
execute
Run one iteration of the daemon- Throws:
Exception
- if an exception occurs (the exception will be passed toexecuteException(Throwable)
but otherwise ignored)
-
postConstruct
public void postConstruct()Description copied from interface:GuiceLifecycleListener
Called after this object has been fully and successfully constructed- Specified by:
postConstruct
in interfaceGuiceLifecycleListener
- Overrides:
postConstruct
in classGuiceDaemon
-
trigger
public void trigger()Trigger the user code to run ASAP- Throws:
IllegalStateException
- if the user code is already running or if the daemon is stopped
-