Class UltiPanelWebSocketClient

java.lang.Object
org.java_websocket.WebSocketAdapter
org.java_websocket.AbstractWebSocket
org.java_websocket.client.WebSocketClient
com.ultikits.ultitools.websocket.UltiPanelWebSocketClient
All Implemented Interfaces:
Runnable, org.java_websocket.WebSocket, org.java_websocket.WebSocketListener

@Deprecated(since="6.3.1", forRemoval=true) public class UltiPanelWebSocketClient extends org.java_websocket.client.WebSocketClient
Deprecated, for removal: This API element is subject to removal in a future version.
There is no replacement: the framework's own UltiCloud session (protocol 2.0.0) carries every panel request, and modules answer panel requests through PanelResponderRegistry. Removed in 6.4.0.
The UltiPanel protocol v1 WebSocket client, kept only so 6.3.0 code still links (plan 22-25).

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

    Fields
    Modifier and Type
    Field
    Description
    private LongSupplier
    Deprecated, for removal: This API element is subject to removal in a future version.
    Clock.
    private static final AtomicBoolean
    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.
    private static boolean
    Deprecated, 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.Gson
    Deprecated, for removal: This API element is subject to removal in a future version.
     
    private static final long
    Deprecated, for removal: This API element is subject to removal in a future version.
    Heartbeat interval, in seconds.
    Deprecated, 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 long
    Deprecated, for removal: This API element is subject to removal in a future version.
     
    private boolean
    Deprecated, for removal: This API element is subject to removal in a future version.
     
    private boolean
    Deprecated, for removal: This API element is subject to removal in a future version.
     
    private long
    Deprecated, for removal: This API element is subject to removal in a future version.
    Timestamp of the most recent ping sent.
    private long
    Deprecated, for removal: This API element is subject to removal in a future version.
    Timestamp of the most recent pong received.
    private long
    Deprecated, for removal: This API element is subject to removal in a future version.
    Most recently measured round-trip latency, in milliseconds.
    private static final int
    Deprecated, 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 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.
    private Runnable
    Deprecated, for removal: This API element is subject to removal in a future version.
     
    private Runnable
    Deprecated, for removal: This API element is subject to removal in a future version.
     
    private Consumer<String>
    Deprecated, for removal: This API element is subject to removal in a future version.
     
    private Runnable
    Deprecated, for removal: This API element is subject to removal in a future version.
     
    private static final long
    Deprecated, 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 int
    Deprecated, for removal: This API element is subject to removal in a future version.
     
    private final String
    Deprecated, for removal: This API element is subject to removal in a future version.
     
    private final String
    Deprecated, for removal: This API element is subject to removal in a future version.
     

    Fields inherited from class org.java_websocket.client.WebSocketClient

    uri

    Fields inherited from class org.java_websocket.AbstractWebSocket

    DEFAULT_READ_BUFFER_SIZE
  • Constructor Summary

    Constructors
    Constructor
    Description
    UltiPanelWebSocketClient(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 Type
    Method
    Description
    void
    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.
    boolean
    Deprecated, for removal: This API element is subject to removal in a future version.
    Opens no socket as of 6.3.1 (see connect()).
    boolean
    connectBlocking(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 (see connect()).
    void
    Deprecated, for removal: This API element is subject to removal in a future version.
    Disconnects the WebSocket connection.
    private static Map<String,String>
    Deprecated, for removal: This API element is subject to removal in a future version.
     
    long
    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.
    long
    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.
    (package private) void
    Deprecated, for removal: This API element is subject to removal in a future version.
    One heartbeat: check liveness first, then send a ping.
    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.
    boolean
    Deprecated, for removal: This API element is subject to removal in a future version.
    Whether the panel connection is up: onOpen has run and neither onClose nor onError has since, and the socket itself is still open.
    void
    onClose(int code, String reason, boolean remote)
    Deprecated, for removal: This API element is subject to removal in a future version.
     
    void
    Deprecated, for removal: This API element is subject to removal in a future version.
     
    void
    onMessage(String message)
    Deprecated, for removal: This API element is subject to removal in a future version.
     
    void
    onOpen(org.java_websocket.handshake.ServerHandshake handshakedata)
    Deprecated, for removal: This API element is subject to removal in a future version.
     
    (package private) 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.
    void
    Deprecated, for removal: This API element is subject to removal in a future version.
    Opens no socket as of 6.3.1 (see connect()).
    boolean
    Deprecated, for removal: This API element is subject to removal in a future version.
    Opens no socket as of 6.3.1 (see connect()).
    private void
    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.
    private static boolean
    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.
    (package private) static void
    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.
    void
    run()
    Deprecated, for removal: This API element is subject to removal in a future version.
    Opens no socket as of 6.3.1 (see connect()).
    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.
    void
    Deprecated, for removal: This API element is subject to removal in a future version.
    Sends a ping message.
    (package private) void
    Deprecated, for removal: This API element is subject to removal in a future version.
    Test-only clock substitution.
    void
    setMessageHandler(Consumer<com.google.gson.JsonObject> handler)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Sets the message handler.
    void
    Deprecated, for removal: This API element is subject to removal in a future version.
    Sets the on-connect handler.
    void
    Deprecated, for removal: This API element is subject to removal in a future version.
    Sets the on-disconnect handler.
    void
    Deprecated, for removal: This API element is subject to removal in a future version.
    Sets the error handler.
    void
    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 void
    Deprecated, for removal: This API element is subject to removal in a future version.
    Starts the heartbeat task.
    void
    Deprecated, for removal: This API element is subject to removal in a future version.
    Subscribes to a server's status.
    void
    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, setSocketFactory

    Methods inherited from class org.java_websocket.AbstractWebSocket

    getConnectionLostTimeout, getReceiveBufferSize, isDaemon, isReuseAddr, isTcpNoDelay, setConnectionLostTimeout, setDaemon, setReceiveBufferSize, setReuseAddr, setTcpNoDelay, startConnectionLostTimer, stopConnectionLostTimer

    Methods inherited from class org.java_websocket.WebSocketAdapter

    onPreparePing, onWebsocketHandshakeReceivedAsClient, onWebsocketHandshakeReceivedAsServer, onWebsocketHandshakeSentAsClient, onWebsocketPing, onWebsocketPong

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • serverId

      private final String serverId
      Deprecated, for removal: This API element is subject to removal in a future version.
    • token

      private final String token
      Deprecated, for removal: This API element is subject to removal in a future version.
    • heartbeatExecutor

      private final ScheduledExecutorService heartbeatExecutor
      Deprecated, for removal: This API element is subject to removal in a future version.
    • isConnected

      private volatile boolean isConnected
      Deprecated, for removal: This API element is subject to removal in a future version.
    • heartbeatTask

      private ScheduledFuture<?> heartbeatTask
      Deprecated, for removal: This API element is subject to removal in a future version.
    • gson

      private final com.google.gson.Gson gson
      Deprecated, for removal: This API element is subject to removal in a future version.
    • messageHandler

      private Consumer<com.google.gson.JsonObject> messageHandler
      Deprecated, for removal: This API element is subject to removal in a future version.
    • onConnectHandler

      private Runnable onConnectHandler
      Deprecated, for removal: This API element is subject to removal in a future version.
    • onDisconnectHandler

      private Runnable onDisconnectHandler
      Deprecated, for removal: This API element is subject to removal in a future version.
    • onErrorHandler

      private Consumer<String> onErrorHandler
      Deprecated, for removal: This API element is subject to removal in a future version.
    • onReconnectExhaustedHandler

      private Runnable onReconnectExhaustedHandler
      Deprecated, for removal: This API element is subject to removal in a future version.
    • MAX_RECONNECT_ATTEMPTS

      private static final int MAX_RECONNECT_ATTEMPTS
      Deprecated, 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_MS
      Deprecated, for removal: This API element is subject to removal in a future version.
      See Also:
    • reconnectAttempts

      private int reconnectAttempts
      Deprecated, for removal: This API element is subject to removal in a future version.
    • intentionalDisconnect

      private boolean intentionalDisconnect
      Deprecated, for removal: This API element is subject to removal in a future version.
    • HEARTBEAT_INTERVAL_SECONDS

      private static final long HEARTBEAT_INTERVAL_SECONDS
      Deprecated, 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_MS
      Deprecated, 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 lastPingTime
      Deprecated, for removal: This API element is subject to removal in a future version.
      Timestamp of the most recent ping sent.
    • lastPongTime

      private volatile long lastPongTime
      Deprecated, 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 latencyMs
      Deprecated, for removal: This API element is subject to removal in a future version.
      Most recently measured round-trip latency, in milliseconds.
    • clock

      private volatile LongSupplier clock
      Deprecated, for removal: This API element is subject to removal in a future version.
      Clock. In production this is simply System::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

      private static final Logger 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

      private static final AtomicBoolean 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 connectPermittedForTesting
      Deprecated, 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 URL
      serverId - the server ID
      token - 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: onOpen has run and neither onClose nor onError has 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 -- before onClose runs, 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

      private static Map<String,String> getHeaders(String token)
      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:
      connect in class org.java_websocket.client.WebSocketClient
    • connectBlocking

      public boolean connectBlocking() throws InterruptedException
      Deprecated, for removal: This API element is subject to removal in a future version.
      Opens no socket as of 6.3.1 (see connect()).
      Overrides:
      connectBlocking in class org.java_websocket.client.WebSocketClient
      Returns:
      false: no connection was made
      Throws:
      InterruptedException - never as of 6.3.1; kept from the overridden signature
    • connectBlocking

      public boolean connectBlocking(long timeout, TimeUnit timeUnit) throws InterruptedException
      Deprecated, for removal: This API element is subject to removal in a future version.
      Opens no socket as of 6.3.1 (see connect()).
      Overrides:
      connectBlocking in class org.java_websocket.client.WebSocketClient
      Parameters:
      timeout - ignored, nothing is awaited
      timeUnit - 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 (see connect()).
      Overrides:
      reconnect in class org.java_websocket.client.WebSocketClient
    • reconnectBlocking

      public boolean reconnectBlocking() throws InterruptedException
      Deprecated, for removal: This API element is subject to removal in a future version.
      Opens no socket as of 6.3.1 (see connect()).
      Overrides:
      reconnectBlocking in class org.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.
      Opens no socket as of 6.3.1 (see connect()). The inherited run() creates and connects the socket itself, so a caller that starts this client as a Runnable (for example new Thread(client).start()) would otherwise bypass the connect forms. It returns at once on any thread.
      Specified by:
      run in interface Runnable
      Overrides:
      run in class org.java_websocket.client.WebSocketClient
    • 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:
      sendPing in interface org.java_websocket.WebSocket
      Overrides:
      sendPing in class org.java_websocket.client.WebSocketClient
    • subscribeToServer

      public void subscribeToServer(String serverId)
      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

      public void unsubscribeFromServer(String serverId)
      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

      public void setMessageHandler(Consumer<com.google.gson.JsonObject> handler)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Sets the message handler.
      Parameters:
      handler - the message handler
    • setOnConnectHandler

      public void setOnConnectHandler(Runnable handler)
      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

      public void setOnDisconnectHandler(Runnable handler)
      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

      public void setOnErrorHandler(Consumer<String> handler)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Sets the error handler.
      Parameters:
      handler - the error handler
    • setOnReconnectExhaustedHandler

      public void setOnReconnectExhaustedHandler(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).
      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, onClose never 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 triggers onClose, 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

      @Internal void setClock(LongSupplier clock)
      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:
      onOpen in class org.java_websocket.client.WebSocketClient
    • onMessage

      public void onMessage(String message)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Specified by:
      onMessage in class org.java_websocket.client.WebSocketClient
    • onClose

      public void onClose(int code, String reason, boolean remote)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Specified by:
      onClose in class org.java_websocket.client.WebSocketClient
    • onError

      public void onError(Exception ex)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Specified by:
      onError in class org.java_websocket.client.WebSocketClient