Class HeartbeatMonitor


  • public class HeartbeatMonitor
    extends Object
    Monitor dealing with all the logic around sending out heartbeats.
    • Constructor Detail

      • HeartbeatMonitor

        public HeartbeatMonitor​(ScheduledExecutorService executor,
                                HeartbeatSender heartbeatSender,
                                Runnable onConnectionCorrupted)
        Constructs a HeartbeatMonitor.
        Parameters:
        executor - the ScheduledExecutorService used to schedule operations to validate if a heartbeat should be send with the given heartbeatSender
        heartbeatSender - the HeartbeatSender used to send heartbeats with
        onConnectionCorrupted - operation to perform if a heartbeat has been missed. Can be used to force a reconnect of a channel for example
    • Method Detail

      • enableHeartbeat

        public void enableHeartbeat​(long interval,
                                    long timeout,
                                    TimeUnit timeUnit)
        Turn on heartbeat sending by this HeartbeatMonitor.
        Parameters:
        interval - the interval at which heartbeats occur. Will use a minimal value of 500 milliseconds to reschedule heartbeat validation
        timeout - the timeout within which this monitor expects responses to the dispatched heartbeats. If this timeout is hit, the given onHeartbeatMissed on construction will be called
        timeUnit - the TimeUnit used to define in which time frame both the given interval and timeout reside. Will be used to change both values to their representative in milliseconds
      • disableHeartbeat

        public void disableHeartbeat()
        Turn off heartbeat sending by this HeartbeatMonitor.
      • pause

        public void pause()
        Pause the process of sending out heartbeats by this monitor.
      • resume

        public void resume()
        Resume the process of sending out heartbeats by this monitor.