Package com.gmt2001.wspinger
Class WSPinger
java.lang.Object
com.gmt2001.wspinger.WSPinger
- All Implemented Interfaces:
- WsClientFrameHandler
Pings the remote endpoint periodically; closes the socket if a PONG is not received after a defined number of PING attempts
- Author:
- gmt2001
- 
Constructor SummaryConstructorsConstructorDescriptionConstructor that uses RFC6455 PING/PONG framesWSPinger(Duration interval, Duration timeout, int failureLimit, PingPongSupplierPredicate supplierPredicate) ConstructorWSPinger(Duration interval, Duration timeout, int failureLimit, Supplier<WebSocketFrame> pingFrameFactory, Predicate<WebSocketFrame> pongParser) Constructor
- 
Method SummaryModifier and TypeMethodDescriptionvoidhandleFrame(ChannelHandlerContext ctx, WebSocketFrame frame) Passed receivedPongWebSocketFrametoreceivedPong()voidInitializes failureCount and lastPong, then starts the ping timervoidonClose()Cancels future execution of the timers when the socket closesvoidsendPing()Sends a PING frame with the value of payload, if enabled, then starts the failure timer, increases the payload for the next frame, and ensures payload won't overflowLong.MAX_VALUE.voidStores theWSClientthat this pinger is linked to
- 
Constructor Details- 
WSPingerConstructor that uses RFC6455 PING/PONG frames- Parameters:
- interval- A- Durationindicating the interval at which to send PING frames
- timeout- A- Durationindicating the timeout during which a PONG must be received before the PING fails
- failureLimit- The number of timeouts before the connection is considered failing and is closed
- Throws:
- IllegalArgumentException- interval or timeout was less than 5 seconds; failureLimit was less than 1
 
- 
WSPingerpublic WSPinger(Duration interval, Duration timeout, int failureLimit, Supplier<WebSocketFrame> pingFrameFactory, Predicate<WebSocketFrame> pongParser) Constructor- Parameters:
- interval- A- Durationindicating the interval at which to send PING frames
- timeout- A- Durationindicating the timeout during which a PONG must be received before the PING fails
- failureLimit- The number of timeouts before the connection is considered failing and is closed
- pingFrameFactory- A factory method that emits a- WebSocketFramethat can be sent as a PING
- pongParser- A method that determines if a given frame is a valid PONG
- Throws:
- IllegalArgumentException- interval or timeout was less than 5 seconds; failureLimit was less than 1; Any value was null
 
- 
WSPingerpublic WSPinger(Duration interval, Duration timeout, int failureLimit, PingPongSupplierPredicate supplierPredicate) Constructor- Parameters:
- interval- A- Durationindicating the interval at which to send PING frames
- timeout- A- Durationindicating the timeout during which a PONG must be received before the PING fails
- failureLimit- The number of timeouts before the connection is considered failing and is closed
- supplierPredicate- An object implementing both the PING supplier and the PONG predicate. Defaults to- RFC6455PingPongif- null
- Throws:
- IllegalArgumentException- interval or timeout was less than 5 seconds; failureLimit was less than 1; Any value was null
 
 
- 
- 
Method Details- 
handleFramePassed receivedPongWebSocketFrametoreceivedPong()- Specified by:
- handleFramein interface- WsClientFrameHandler
- Parameters:
- ctx-
- frame-
 
- 
handshakeCompleteInitializes failureCount and lastPong, then starts the ping timer- Specified by:
- handshakeCompletein interface- WsClientFrameHandler
- Parameters:
- ctx-
 
- 
onClosepublic void onClose()Cancels future execution of the timers when the socket closes- Specified by:
- onClosein interface- WsClientFrameHandler
 
- 
setClientStores theWSClientthat this pinger is linked to- Parameters:
- client-
 
- 
sendPingpublic void sendPing()Sends a PING frame with the value of payload, if enabled, then starts the failure timer, increases the payload for the next frame, and ensures payload won't overflowLong.MAX_VALUE. No-op if client isnull, {@link WSClient.connected()} isfalse, or the timerFuture is null, done, or canceled
 
-