Class GuiceRecurringDaemon

All Implemented Interfaces:
GuiceLifecycleListener, StoppableService, Runnable
Direct Known Subclasses:
BackgroundTaskDaemon, DeleteExpiredSessionDaemon, GuiceScheduledDaemon, HealthCheckWorker, NetworkConfigReloadDaemon

public abstract class GuiceRecurringDaemon extends GuiceDaemon
  • Field Details

    • sleepTime

      protected Timeout sleepTime
  • Constructor Details

    • GuiceRecurringDaemon

      protected GuiceRecurringDaemon(Timeout sleepTime)
      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 the execute() method
    • GuiceRecurringDaemon

      protected GuiceRecurringDaemon(boolean daemonThread, Timeout sleepTime)
      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 false
      sleepTime - the amount of time to sleep between calls to the execute() method
  • Method Details

    • isUserCodeRunning

      public boolean isUserCodeRunning()
    • setSleepTimeFromConfigIfSet

      @Inject public void setSleepTimeFromConfigIfSet(GuiceConfig config)
    • getInitialSleepTime

      public Timeout getInitialSleepTime()
    • getSleepTime

      public Timeout getSleepTime()
    • getCalls

      public com.codahale.metrics.Timer getCalls()
    • getExceptions

      public com.codahale.metrics.Meter getExceptions()
    • setSleepTime

      public void setSleepTime(Timeout sleepTime)
    • 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

      public Instant getLastRan()
    • executeException

      protected void executeException(Throwable t)

      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

      protected abstract void execute() throws Exception
      Run one iteration of the daemon
      Throws:
      Exception - if an exception occurs (the exception will be passed to executeException(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 interface GuiceLifecycleListener
      Overrides:
      postConstruct in class GuiceDaemon
    • 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