Class UltiPanelWebSocketClient
- All Implemented Interfaces:
Runnable,org.java_websocket.WebSocket,org.java_websocket.WebSocketListener
As of 6.3.1 it never opens a socket. Protocol 2.0.0 has no v1 gateway, so
connect(), both connectBlocking forms, reconnect(),
reconnectBlocking() and the inherited Runnable.run() return without connecting
(the blocking forms return false), and the first such call in a run writes one INFO line that says so. The
framework itself never constructs this class; its own UltiCloud session speaks protocol 2.0.0.
The kept v1 senders in the managers still send over an instance a caller hands to their
deprecated entry points, and sendMessage(JsonObject) then reports the closed socket.
- Scheduled removal version:
- 6.4.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate LongSupplierDeprecated, for removal: This API element is subject to removal in a future version.Clock.private static final AtomicBooleanDeprecated, for removal: This API element is subject to removal in a future version.Whether this run has already said that a v1 client does not connect.private static booleanDeprecated, for removal: This API element is subject to removal in a future version.Test-only switch that lets the kept v1 log-stream tests reach a local socket server.private final com.google.gson.GsonDeprecated, for removal: This API element is subject to removal in a future version.private static final longDeprecated, for removal: This API element is subject to removal in a future version.Heartbeat interval, in seconds.private final ScheduledExecutorServiceDeprecated, for removal: This API element is subject to removal in a future version.private ScheduledFuture<?> Deprecated, for removal: This API element is subject to removal in a future version.private static final longDeprecated, for removal: This API element is subject to removal in a future version.private booleanDeprecated, for removal: This API element is subject to removal in a future version.private booleanDeprecated, for removal: This API element is subject to removal in a future version.private longDeprecated, for removal: This API element is subject to removal in a future version.Timestamp of the most recent ping sent.private longDeprecated, for removal: This API element is subject to removal in a future version.Timestamp of the most recent pong received.private longDeprecated, for removal: This API element is subject to removal in a future version.Most recently measured round-trip latency, in milliseconds.private static final intDeprecated, for removal: This API element is subject to removal in a future version.private Consumer<com.google.gson.JsonObject> Deprecated, for removal: This API element is subject to removal in a future version.private static final LoggerDeprecated, for removal: This API element is subject to removal in a future version.Where the one-per-run "no v1 gateway" line goes; a class logger, so it needs no plugin instance.private RunnableDeprecated, for removal: This API element is subject to removal in a future version.private RunnableDeprecated, for removal: This API element is subject to removal in a future version.Deprecated, for removal: This API element is subject to removal in a future version.private RunnableDeprecated, for removal: This API element is subject to removal in a future version.private static final longDeprecated, for removal: This API element is subject to removal in a future version.Threshold for declaring a connection "silently dead": no pong received across two heartbeat intervals.private intDeprecated, for removal: This API element is subject to removal in a future version.private final StringDeprecated, for removal: This API element is subject to removal in a future version.private final StringDeprecated, for removal: This API element is subject to removal in a future version.Fields inherited from class org.java_websocket.client.WebSocketClient
uriFields inherited from class org.java_websocket.AbstractWebSocket
DEFAULT_READ_BUFFER_SIZE -
Constructor Summary
ConstructorsConstructorDescriptionUltiPanelWebSocketClient(String url, String serverId, String token) Deprecated, for removal: This API element is subject to removal in a future version.Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidconnect()Deprecated, for removal: This API element is subject to removal in a future version.Opens no socket as of 6.3.1: protocol 2.0.0 has no v1 gateway.booleanDeprecated, for removal: This API element is subject to removal in a future version.Opens no socket as of 6.3.1 (seeconnect()).booleanconnectBlocking(long timeout, TimeUnit timeUnit) Deprecated, for removal: This API element is subject to removal in a future version.Opens no socket as of 6.3.1 (seeconnect()).voidDeprecated, for removal: This API element is subject to removal in a future version.Disconnects the WebSocket connection.getHeaders(String token) Deprecated, for removal: This API element is subject to removal in a future version.longDeprecated, for removal: This API element is subject to removal in a future version.Timestamp of the most recent pong received; 0 if none has ever been received.longDeprecated, for removal: This API element is subject to removal in a future version.Most recently measured round-trip latency, in milliseconds; -1 if not yet measured.(package private) voidDeprecated, for removal: This API element is subject to removal in a future version.One heartbeat: check liveness first, then send a ping.booleanisAlive(long timeoutMs) Deprecated, for removal: This API element is subject to removal in a future version.Determines whether the connection is still alive, based on pong responses.booleanDeprecated, for removal: This API element is subject to removal in a future version.Whether the panel connection is up:onOpenhas run and neitheronClosenoronErrorhas since, and the socket itself is still open.voidDeprecated, for removal: This API element is subject to removal in a future version.voidDeprecated, for removal: This API element is subject to removal in a future version.voidDeprecated, for removal: This API element is subject to removal in a future version.voidonOpen(org.java_websocket.handshake.ServerHandshake handshakedata) Deprecated, for removal: This API element is subject to removal in a future version.(package private) static voidpermitConnectForTesting(boolean permit) Deprecated, for removal: This API element is subject to removal in a future version.Test-only: lets a kept v1 log-stream test connect to its own local socket server.voidDeprecated, for removal: This API element is subject to removal in a future version.Opens no socket as of 6.3.1 (seeconnect()).booleanDeprecated, for removal: This API element is subject to removal in a future version.Opens no socket as of 6.3.1 (seeconnect()).private voidDeprecated, for removal: This API element is subject to removal in a future version.Called when a pong is received: records the time and computes the round-trip latency.private static booleanDeprecated, for removal: This API element is subject to removal in a future version.Whether a connect call must open nothing: always, outside the kept v1 log-stream tests.(package private) static voidDeprecated, for removal: This API element is subject to removal in a future version.Test-only: forgets that this run already logged the "opens no connection" line.voidrun()Deprecated, for removal: This API element is subject to removal in a future version.Opens no socket as of 6.3.1 (seeconnect()).voidsendMessage(com.google.gson.JsonObject message) Deprecated, for removal: This API element is subject to removal in a future version.Sends a message to the server.voidsendPing()Deprecated, for removal: This API element is subject to removal in a future version.Sends a ping message.(package private) voidsetClock(LongSupplier clock) Deprecated, for removal: This API element is subject to removal in a future version.Test-only clock substitution.voidsetMessageHandler(Consumer<com.google.gson.JsonObject> handler) Deprecated, for removal: This API element is subject to removal in a future version.Sets the message handler.voidsetOnConnectHandler(Runnable handler) Deprecated, for removal: This API element is subject to removal in a future version.Sets the on-connect handler.voidsetOnDisconnectHandler(Runnable handler) Deprecated, for removal: This API element is subject to removal in a future version.Sets the on-disconnect handler.voidsetOnErrorHandler(Consumer<String> handler) Deprecated, for removal: This API element is subject to removal in a future version.Sets the error handler.voidsetOnReconnectExhaustedHandler(Runnable handler) Deprecated, for removal: This API element is subject to removal in a future version.Sets the reconnect-exhausted handler (invoked once every reconnection attempt has failed).private voidDeprecated, for removal: This API element is subject to removal in a future version.Starts the heartbeat task.voidsubscribeToServer(String serverId) Deprecated, for removal: This API element is subject to removal in a future version.Subscribes to a server's status.voidunsubscribeFromServer(String serverId) Deprecated, for removal: This API element is subject to removal in a future version.Unsubscribes from a server's status.Methods inherited from class org.java_websocket.client.WebSocketClient
addHeader, clearHeaders, close, close, close, closeBlocking, closeConnection, getAttachment, getConnection, getConnections, getDraft, getLocalSocketAddress, getLocalSocketAddress, getProtocol, getReadyState, getRemoteSocketAddress, getRemoteSocketAddress, getResourceDescriptor, getSocket, getSSLSession, getURI, hasBufferedData, hasSSLSupport, isClosed, isClosing, isFlushAndClose, isOpen, onCloseInitiated, onClosing, onMessage, onSetSSLParameters, onWebsocketClose, onWebsocketCloseInitiated, onWebsocketClosing, onWebsocketError, onWebsocketMessage, onWebsocketMessage, onWebsocketOpen, onWriteDemand, removeHeader, send, send, send, sendFragmentedFrame, sendFrame, sendFrame, setAttachment, setDnsResolver, setProxy, setSocket, setSocketFactoryMethods inherited from class org.java_websocket.AbstractWebSocket
getConnectionLostTimeout, getReceiveBufferSize, isDaemon, isReuseAddr, isTcpNoDelay, setConnectionLostTimeout, setDaemon, setReceiveBufferSize, setReuseAddr, setTcpNoDelay, startConnectionLostTimer, stopConnectionLostTimerMethods inherited from class org.java_websocket.WebSocketAdapter
onPreparePing, onWebsocketHandshakeReceivedAsClient, onWebsocketHandshakeReceivedAsServer, onWebsocketHandshakeSentAsClient, onWebsocketPing, onWebsocketPong
-
Field Details
-
serverId
Deprecated, for removal: This API element is subject to removal in a future version. -
token
Deprecated, for removal: This API element is subject to removal in a future version. -
heartbeatExecutor
Deprecated, for removal: This API element is subject to removal in a future version. -
isConnected
private volatile boolean isConnectedDeprecated, for removal: This API element is subject to removal in a future version. -
heartbeatTask
Deprecated, for removal: This API element is subject to removal in a future version. -
gson
private final com.google.gson.Gson gsonDeprecated, for removal: This API element is subject to removal in a future version. -
messageHandler
Deprecated, for removal: This API element is subject to removal in a future version. -
onConnectHandler
Deprecated, for removal: This API element is subject to removal in a future version. -
onDisconnectHandler
Deprecated, for removal: This API element is subject to removal in a future version. -
onErrorHandler
Deprecated, for removal: This API element is subject to removal in a future version. -
onReconnectExhaustedHandler
Deprecated, for removal: This API element is subject to removal in a future version. -
MAX_RECONNECT_ATTEMPTS
private static final int MAX_RECONNECT_ATTEMPTSDeprecated, for removal: This API element is subject to removal in a future version.- See Also:
-
INITIAL_RECONNECT_DELAY_MS
private static final long INITIAL_RECONNECT_DELAY_MSDeprecated, for removal: This API element is subject to removal in a future version.- See Also:
-
reconnectAttempts
private int reconnectAttemptsDeprecated, for removal: This API element is subject to removal in a future version. -
intentionalDisconnect
private boolean intentionalDisconnectDeprecated, for removal: This API element is subject to removal in a future version. -
HEARTBEAT_INTERVAL_SECONDS
private static final long HEARTBEAT_INTERVAL_SECONDSDeprecated, for removal: This API element is subject to removal in a future version.Heartbeat interval, in seconds.- See Also:
-
PONG_TIMEOUT_MS
private static final long PONG_TIMEOUT_MSDeprecated, for removal: This API element is subject to removal in a future version.Threshold for declaring a connection "silently dead": no pong received across two heartbeat intervals.Two intervals rather than one, to tolerate a single dropped packet or one scheduling jitter - the cost of a false positive is kicking a good connection into reconnecting, while a false negative only delays detection by one interval.
- See Also:
-
lastPingTime
private volatile long lastPingTimeDeprecated, for removal: This API element is subject to removal in a future version.Timestamp of the most recent ping sent. -
lastPongTime
private volatile long lastPongTimeDeprecated, for removal: This API element is subject to removal in a future version.Timestamp of the most recent pong received. 0 means none has ever been received. -
latencyMs
private volatile long latencyMsDeprecated, for removal: This API element is subject to removal in a future version.Most recently measured round-trip latency, in milliseconds. -
clock
Deprecated, for removal: This API element is subject to removal in a future version.Clock. In production this is simplySystem::currentTimeMillis; tests can substitute a fake clock.The only reason this exists is so the "no pong received past the threshold" check can be covered by a unit test without
Thread.sleep- actually waiting out two heartbeat intervals is 120 seconds, and nobody keeps a test like that around. -
NOTICE_LOGGER
Deprecated, for removal: This API element is subject to removal in a future version.Where the one-per-run "no v1 gateway" line goes; a class logger, so it needs no plugin instance. -
CONNECT_NOTICE_LOGGED
Deprecated, for removal: This API element is subject to removal in a future version.Whether this run has already said that a v1 client does not connect. -
connectPermittedForTesting
private static volatile boolean connectPermittedForTestingDeprecated, for removal: This API element is subject to removal in a future version.Test-only switch that lets the kept v1 log-stream tests reach a local socket server.
-
-
Constructor Details
-
UltiPanelWebSocketClient
public UltiPanelWebSocketClient(String url, String serverId, String token) throws URISyntaxException Deprecated, for removal: This API element is subject to removal in a future version.Constructor.- Parameters:
url- the WebSocket server URLserverId- the server IDtoken- the auth token- Throws:
URISyntaxException- if the URL is malformed
-
-
Method Details
-
isConnected
public boolean isConnected()Deprecated, for removal: This API element is subject to removal in a future version.Whether the panel connection is up:onOpenhas run and neitheronClosenoronErrorhas since, and the socket itself is still open.The second half matters while a connection closes (as of 6.3.0, #486): the socket leaves the open state -- and
sendMessage(JsonObject)starts refusing to send -- beforeonCloseruns, which can take a long time when the closing handshake waits on a dead peer. Reporting "connected" in that window made a send that was quietly refused look delivered, and the log records in it were lost.- Returns:
- whether a message sent now can go out
-
getHeaders
Deprecated, for removal: This API element is subject to removal in a future version. -
connect
public void connect()Deprecated, for removal: This API element is subject to removal in a future version.Opens no socket as of 6.3.1: protocol 2.0.0 has no v1 gateway. The first call of any connect form in a run writes one INFO line naming the removal.- Overrides:
connectin classorg.java_websocket.client.WebSocketClient
-
connectBlocking
Deprecated, for removal: This API element is subject to removal in a future version.Opens no socket as of 6.3.1 (seeconnect()).- Overrides:
connectBlockingin classorg.java_websocket.client.WebSocketClient- Returns:
false: no connection was made- Throws:
InterruptedException- never as of 6.3.1; kept from the overridden signature
-
connectBlocking
Deprecated, for removal: This API element is subject to removal in a future version.Opens no socket as of 6.3.1 (seeconnect()).- Overrides:
connectBlockingin classorg.java_websocket.client.WebSocketClient- Parameters:
timeout- ignored, nothing is awaitedtimeUnit- ignored, nothing is awaited- Returns:
false: no connection was made- Throws:
InterruptedException- never as of 6.3.1; kept from the overridden signature
-
reconnect
public void reconnect()Deprecated, for removal: This API element is subject to removal in a future version.Opens no socket as of 6.3.1 (seeconnect()).- Overrides:
reconnectin classorg.java_websocket.client.WebSocketClient
-
reconnectBlocking
Deprecated, for removal: This API element is subject to removal in a future version.Opens no socket as of 6.3.1 (seeconnect()).- Overrides:
reconnectBlockingin classorg.java_websocket.client.WebSocketClient- Returns:
false: no connection was made- Throws:
InterruptedException- never as of 6.3.1; kept from the overridden signature
-
run
public void run()Deprecated, for removal: This API element is subject to removal in a future version. -
refuseConnect
private static boolean refuseConnect()Deprecated, for removal: This API element is subject to removal in a future version.Whether a connect call must open nothing: always, outside the kept v1 log-stream tests. Writes the one-per-run INFO line on the first refusal. -
permitConnectForTesting
static void permitConnectForTesting(boolean permit) Deprecated, for removal: This API element is subject to removal in a future version.Test-only: lets a kept v1 log-stream test connect to its own local socket server. -
resetConnectNoticeForTesting
static void resetConnectNoticeForTesting()Deprecated, for removal: This API element is subject to removal in a future version.Test-only: forgets that this run already logged the "opens no connection" line. -
disconnect
public void disconnect()Deprecated, for removal: This API element is subject to removal in a future version.Disconnects the WebSocket connection. -
sendMessage
public void sendMessage(com.google.gson.JsonObject message) Deprecated, for removal: This API element is subject to removal in a future version.Sends a message to the server.- Parameters:
message- the JSON message object
-
sendPing
public void sendPing()Deprecated, for removal: This API element is subject to removal in a future version.Sends a ping message.- Specified by:
sendPingin interfaceorg.java_websocket.WebSocket- Overrides:
sendPingin classorg.java_websocket.client.WebSocketClient
-
subscribeToServer
Deprecated, for removal: This API element is subject to removal in a future version.Subscribes to a server's status.- Parameters:
serverId- the server ID to subscribe to
-
unsubscribeFromServer
Deprecated, for removal: This API element is subject to removal in a future version.Unsubscribes from a server's status.- Parameters:
serverId- the server ID to unsubscribe from
-
setMessageHandler
Deprecated, for removal: This API element is subject to removal in a future version.Sets the message handler.- Parameters:
handler- the message handler
-
setOnConnectHandler
Deprecated, for removal: This API element is subject to removal in a future version.Sets the on-connect handler.- Parameters:
handler- the on-connect handler
-
setOnDisconnectHandler
Deprecated, for removal: This API element is subject to removal in a future version.Sets the on-disconnect handler.- Parameters:
handler- the on-disconnect handler
-
setOnErrorHandler
Deprecated, for removal: This API element is subject to removal in a future version.Sets the error handler.- Parameters:
handler- the error handler
-
setOnReconnectExhaustedHandler
Deprecated, for removal: This API element is subject to removal in a future version.Sets the reconnect-exhausted handler (invoked once every reconnection attempt has failed).- Parameters:
handler- the reconnect-exhausted handler
-
startHeartbeat
private void startHeartbeat()Deprecated, for removal: This API element is subject to removal in a future version.Starts the heartbeat task. -
heartbeatTick
void heartbeatTick()Deprecated, for removal: This API element is subject to removal in a future version.One heartbeat: check liveness first, then send a ping."Check liveness first" is the reason this method exists. Before it, the only signal of connection health was whether the socket had closed - and a TCP connection can go silently dead without ever producing
onClose(an intermediate device timing out, the peer process hanging, a NAT table entry expiring). In that state pings still go out,onClosenever fires, and reconnection logic never starts - the connection looks fine but is actually dead.When a silent failure is declared, this method **routes through
close()rather than starting a second reconnection path of its own**: closing triggersonClose, reusing the existing reconnect state machine (including the global budget #181 added). Starting a second path would become a second place deciding whether to reconnect - exactly what caused #181. -
recordPong
private void recordPong()Deprecated, for removal: This API element is subject to removal in a future version.Called when a pong is received: records the time and computes the round-trip latency.Called by
onMessage(String)before dispatching to messageHandler - a pong is a link-layer fact and should not depend on whether an upper-layer handler happens to be wired up. -
isAlive
public boolean isAlive(long timeoutMs) Deprecated, for removal: This API element is subject to removal in a future version.Determines whether the connection is still alive, based on pong responses.Returns true when no pong has ever been received. This is deliberate: otherwise a newly established connection would be declared dead within its first heartbeat interval. The cost is that this mechanism cannot detect "the peer never answers pong at all" - but that is the safe direction: if the panel simply never implemented pong, a good connection should not be repeatedly kicked. What it can detect is "used to answer, and stopped" - that is, a silent failure.
- Parameters:
timeoutMs- the liveness threshold, in milliseconds- Returns:
- true if the most recent pong is within the threshold, or none has ever been received
-
getLatencyMs
public long getLatencyMs()Deprecated, for removal: This API element is subject to removal in a future version.Most recently measured round-trip latency, in milliseconds; -1 if not yet measured.- Returns:
- the latency in milliseconds, or -1
-
getLastPongTime
public long getLastPongTime()Deprecated, for removal: This API element is subject to removal in a future version.Timestamp of the most recent pong received; 0 if none has ever been received.- Returns:
- the timestamp, in milliseconds
-
setClock
Deprecated, for removal: This API element is subject to removal in a future version.Test-only clock substitution. -
onOpen
public void onOpen(org.java_websocket.handshake.ServerHandshake handshakedata) Deprecated, for removal: This API element is subject to removal in a future version.- Specified by:
onOpenin classorg.java_websocket.client.WebSocketClient
-
onMessage
Deprecated, for removal: This API element is subject to removal in a future version.- Specified by:
onMessagein classorg.java_websocket.client.WebSocketClient
-
onClose
Deprecated, for removal: This API element is subject to removal in a future version.- Specified by:
onClosein classorg.java_websocket.client.WebSocketClient
-
onError
Deprecated, for removal: This API element is subject to removal in a future version.- Specified by:
onErrorin classorg.java_websocket.client.WebSocketClient
-
PanelResponderRegistry. Removed in 6.4.0.