Class StatusChecker

  • All Implemented Interfaces:
    java.lang.Runnable

    class StatusChecker
    extends java.lang.Object
    implements java.lang.Runnable
    The StatusChecker object is used to perform health checks on connected sessions. Health is determined using the ping pong protocol defined in RFC 6455. The ping pong protocol requires that any endpoint must respond to a ping control frame with a pong control frame containing the same payload. This session checker will send out out ping controls frames and wait for a pong frame. If it does not receive a pong frame after a configured expiry time then it will close the associated session.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private Channel channel
      This is the underling TCP channel that is being checked.
      private FrameConnection connection
      This is the WebSocket this this pinger will be monitoring.
      private java.util.concurrent.atomic.AtomicLong counter
      This is a count of the number of unacknowledged ping frames.
      private Reason error
      The only reason for a close is for an unexpected error.
      private Frame frame
      This is the frame that contains the ping to send.
      private long frequency
      This is the frequency with which the checker should run.
      private StatusResultListener listener
      This is used to perform the monitoring of the sessions.
      private Reason normal
      The only reason for a close is for an unexpected error.
      private Scheduler scheduler
      This is the shared scheduler used to execute this checker.
      private Trace trace
      This is used to trace various events for this pinger.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      This is used to close the session and send a 1000 close code to the client indicating a normal closure.
      void failure()
      This is used to close the session and send a 1011 close code to the client indicating an internal server error.
      void refresh()
      If the connection gets a response to its ping message then this will reset the internal counter.
      void run()
      This method is used to check to see if a session has expired.
      void start()
      This is used to kick of the status checking.
      • Methods inherited from class java.lang.Object

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

      • listener

        private final StatusResultListener listener
        This is used to perform the monitoring of the sessions.
      • connection

        private final FrameConnection connection
        This is the WebSocket this this pinger will be monitoring.
      • scheduler

        private final Scheduler scheduler
        This is the shared scheduler used to execute this checker.
      • counter

        private final java.util.concurrent.atomic.AtomicLong counter
        This is a count of the number of unacknowledged ping frames.
      • channel

        private final Channel channel
        This is the underling TCP channel that is being checked.
      • normal

        private final Reason normal
        The only reason for a close is for an unexpected error.
      • error

        private final Reason error
        The only reason for a close is for an unexpected error.
      • trace

        private final Trace trace
        This is used to trace various events for this pinger.
      • frame

        private final Frame frame
        This is the frame that contains the ping to send.
      • frequency

        private final long frequency
        This is the frequency with which the checker should run.
    • Constructor Detail

      • StatusChecker

        public StatusChecker​(FrameConnection connection,
                             Request request,
                             Scheduler scheduler,
                             long frequency)
        Constructor for the StatusChecker object. This is used to create a pinger that will send out ping frames at a specified interval. If a session does not respond within three times the duration of the ping the connection is reset.
        Parameters:
        connection - this is the WebSocket to send the frames
        request - this is the associated request
        scheduler - this is the scheduler used to execute this
        frequency - this is the frequency with which to ping
    • Method Detail

      • start

        public void start()
        This is used to kick of the status checking. Here an initial ping is sent over the socket and the task is then scheduled to check the result after the frequency period has expired. If this method fails for any reason the TCP channel is closed.
      • run

        public void run()
        This method is used to check to see if a session has expired. If there have been three unacknowledged ping events then this will force a closure of the WebSocket connection. This is done to ensure only healthy connections are maintained within the server, also RFC 6455 recommends using the ping pong protocol.
        Specified by:
        run in interface java.lang.Runnable
      • refresh

        public void refresh()
        If the connection gets a response to its ping message then this will reset the internal counter. This ensure that the connection does not time out. If after three pings there is not response from the other side then the connection will be terminated.
      • failure

        public void failure()
        This is used to close the session and send a 1011 close code to the client indicating an internal server error. Closing of the session in this manner only occurs if there is an expiry of the session or an I/O error, both of which are unexpected and violate the behaviour as defined in RFC 6455.
      • close

        public void close()
        This is used to close the session and send a 1000 close code to the client indicating a normal closure. This will be called when there is a close notification dispatched to the status listener. Typically here a graceful closure is best.