Class WebsocketPingerService

    • Field Detail

      • DEFAULT_INTERVAL

        public static final int DEFAULT_INTERVAL
        Majority of proxy and NAT routers have timeout of at least 60s.
        See Also:
        Constant Field Values
      • DEFAULT_FAILURE_LIMIT

        public static final int DEFAULT_FAILURE_LIMIT
        Arbitrarily chosen number.
        See Also:
        Constant Field Values
    • Constructor Detail

      • WebsocketPingerService

        public WebsocketPingerService​(int intervalSeconds,
                                      int failureLimit,
                                      int pingSize,
                                      boolean synchronizeSending)
        Configures and starts the service in ping-pong mode: timely pongs are expected and validated.
        Parameters:
        intervalSeconds - interval between pings and also timeout for pongs.
        failureLimit - limit of lost, malformed or timed out pongs after which the given connection is closed. Each valid, timely pong resets connection's failure counter.
        pingSize - size of the ping data to send. This comes from Random, so an economic value is recommended.
        synchronizeSending - whether to synchronize packet sending on the given connection. Whether it is necessary depends on the implementation of the container. For example it is not necessary on Jetty, but it is on Tomcat: see this bug report.
      • WebsocketPingerService

        public WebsocketPingerService​(int intervalSeconds,
                                      boolean synchronizeSending)
        Configures and starts the service in keep-alive-only mode: just 1-byte-unsolicited pong is sent each time and responses are not expected. The params have the same meaning as in WebsocketPingerService(int, int, int, boolean).
      • WebsocketPingerService

        public WebsocketPingerService​(int intervalSeconds)
        Calls WebsocketPingerService(intervalSeconds, false) (keep-alive-only mode).
    • Method Detail

      • getNumberOfConnections

        public int getNumberOfConnections()
        Returns the number of currently registered connections.
      • stop

        public Set<Session> stop()
        Stops the service. After a call to this method the service becomes no longer usable and should be discarded.
        Returns:
        connections that were registered at the time this method was called.