Class StatusChecker
java.lang.Object
org.simpleframework.http.socket.service.StatusChecker
- All Implemented Interfaces:
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
FieldsModifier and TypeFieldDescriptionprivate final Channel
This is the underling TCP channel that is being checked.private final FrameConnection
This is the WebSocket this this pinger will be monitoring.private final AtomicLong
This is a count of the number of unacknowledged ping frames.private final Reason
The only reason for a close is for an unexpected error.private final Frame
This is the frame that contains the ping to send.private final long
This is the frequency with which the checker should run.private final StatusResultListener
This is used to perform the monitoring of the sessions.private final Reason
The only reason for a close is for an unexpected error.private final Scheduler
This is the shared scheduler used to execute this checker.private final Trace
This is used to trace various events for this pinger. -
Constructor Summary
ConstructorsConstructorDescriptionStatusChecker
(FrameConnection connection, Request request, Scheduler scheduler, long frequency) Constructor for theStatusChecker
object. -
Method Summary
Modifier and TypeMethodDescriptionvoid
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.
-
Field Details
-
listener
This is used to perform the monitoring of the sessions. -
connection
This is the WebSocket this this pinger will be monitoring. -
scheduler
This is the shared scheduler used to execute this checker. -
counter
This is a count of the number of unacknowledged ping frames. -
channel
This is the underling TCP channel that is being checked. -
normal
The only reason for a close is for an unexpected error. -
error
The only reason for a close is for an unexpected error. -
trace
This is used to trace various events for this pinger. -
frame
This is the frame that contains the ping to send. -
frequency
private final long frequencyThis is the frequency with which the checker should run.
-
-
Constructor Details
-
StatusChecker
public StatusChecker(FrameConnection connection, Request request, Scheduler scheduler, long frequency) Constructor for theStatusChecker
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 framesrequest
- this is the associated requestscheduler
- this is the scheduler used to execute thisfrequency
- this is the frequency with which to ping
-
-
Method Details
-
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. -
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.
-