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.
        Parameters:
        intervalSeconds - interval between pings.
        failureLimit - limit of lost or malformed pongs after which the given connection is closed. Pongs received after pingIntervalSeconds count as failures. 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 ping 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 is sent each time and responses are not expected. Remaining 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:
        remaining registered connections.