Class PongHandler
java.lang.Object
com.ultikits.ultitools.websocket.handlers.PongHandler
- All Implemented Interfaces:
WebSocketMessageHandler
Handler for pong/heartbeat response messages.
处理 pong/心跳响应消息的处理器。
本类的能力已于 issue #235 全部搬进 UltiPanelWebSocketClient 的心跳路径
—— 延迟测量、最后一次 pong 时间、以及 isAlive(long) 存活判定都在那边了,并且
接上了「超过阈值未收到 pong 就主动重连」这条活路径(本类从来没有接线,见 #233)。
因此本类现在可以被安全删除,删除动作由 #233 执行。留着它只会造成 「registry 模式部分启用」的中间态。
- Since:
- 6.2.0
- Version:
- 1.0.0
- Author:
- wisdomme
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate longprivate longprivate longprivate static final Logger -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionlongGets the time of the last pong received.longGets the measured latency.Gets the message type this handler processes.voidhandle(com.google.gson.JsonObject message) Handles the incoming message.booleanisAlive(long timeoutMs) Checks if the connection appears to be alive based on pong responses.voidRecords when a ping was sent (for latency calculation).Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.ultikits.ultitools.websocket.WebSocketMessageHandler
getPriority
-
Field Details
-
logger
-
lastPongTime
private volatile long lastPongTime -
latency
private volatile long latency -
lastPingTime
private volatile long lastPingTime
-
-
Constructor Details
-
PongHandler
public PongHandler()
-
-
Method Details
-
getMessageType
Description copied from interface:WebSocketMessageHandlerGets the message type this handler processes. 获取此处理器处理的消息类型。- Specified by:
getMessageTypein interfaceWebSocketMessageHandler- Returns:
- the message type string (e.g., "pong", "server_status")
-
handle
public void handle(com.google.gson.JsonObject message) Description copied from interface:WebSocketMessageHandlerHandles the incoming message. 处理传入的消息。- Specified by:
handlein interfaceWebSocketMessageHandler- Parameters:
message- the JSON message to handle
-
recordPing
public void recordPing()Records when a ping was sent (for latency calculation). 记录发送 ping 的时间(用于计算延迟)。 -
getLastPongTime
public long getLastPongTime()Gets the time of the last pong received. 获取最后收到 pong 的时间。- Returns:
- timestamp in milliseconds
-
getLatency
public long getLatency()Gets the measured latency. 获取测量的延迟。- Returns:
- latency in milliseconds
-
isAlive
public boolean isAlive(long timeoutMs) Checks if the connection appears to be alive based on pong responses. 根据 pong 响应检查连接是否存活。- Parameters:
timeoutMs- the timeout threshold in milliseconds- Returns:
- true if last pong was within the timeout
-