Class SleepingTimer

  • All Implemented Interfaces:
    HeartbeatTimer

    @NotThreadSafe
    public final class SleepingTimer
    extends java.lang.Object
    implements HeartbeatTimer
    This class can be used for executing heartbeats periodically.
    • Constructor Summary

      Constructors 
      Constructor Description
      SleepingTimer​(java.lang.String threadName, long intervalMs)
      Creates a new instance of SleepingTimer.
      SleepingTimer​(java.lang.String threadName, long intervalMs, org.slf4j.Logger logger, java.time.Clock clock, Sleeper sleeper)
      Creates a new instance of SleepingTimer.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void setIntervalMs​(long intervalMs)
      Sets the heartbeat interval.
      void tick()
      Enforces the thread waits for the given interval between consecutive ticks.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • SleepingTimer

        public SleepingTimer​(java.lang.String threadName,
                             long intervalMs)
        Creates a new instance of SleepingTimer.
        Parameters:
        threadName - the thread name
        intervalMs - the heartbeat interval
      • SleepingTimer

        public SleepingTimer​(java.lang.String threadName,
                             long intervalMs,
                             org.slf4j.Logger logger,
                             java.time.Clock clock,
                             Sleeper sleeper)
        Creates a new instance of SleepingTimer.
        Parameters:
        threadName - the thread name
        intervalMs - the heartbeat interval
        logger - the logger to log to
        clock - for telling the current time
        sleeper - the utility to use for sleeping
    • Method Detail

      • setIntervalMs

        public void setIntervalMs​(long intervalMs)
        Description copied from interface: HeartbeatTimer
        Sets the heartbeat interval.
        Specified by:
        setIntervalMs in interface HeartbeatTimer
        Parameters:
        intervalMs - the heartbeat interval in ms
      • tick

        public void tick()
                  throws java.lang.InterruptedException
        Enforces the thread waits for the given interval between consecutive ticks.
        Specified by:
        tick in interface HeartbeatTimer
        Throws:
        java.lang.InterruptedException - if the thread is interrupted while waiting