Class AgentSocket

java.lang.Object
org.java_websocket.WebSocketAdapter
org.java_websocket.AbstractWebSocket
org.java_websocket.client.WebSocketClient
com.ultikits.ultitools.utils.AgentSocket
All Implemented Interfaces:
AgentConnection.Handle, Runnable, org.java_websocket.WebSocket, org.java_websocket.WebSocketListener

final class AgentSocket extends org.java_websocket.client.WebSocketClient implements AgentConnection.Handle
One attempt's Java-WebSocket client for the UltiCloud /v1/agent socket (as of 6.3.1).

It decides nothing: it forwards open, text, refusal and close to the AgentConnection state machine through the attempt's AgentConnection.SocketEvents. A close whose upgrade was answered with a status other than 101 (recorded by StatusCapturingDraft) is reported as onUpgradeRefused; every other close as onClosed.

The TCP connect is bounded by the constructor's connect timeout (Java-WebSocket 1.6.0 has no setConnectTimeout); the library's ping control frames are disabled with setConnectionLostTimeout(0) because liveness is the application heartbeat's job (contract answer 2). The bearer exists only in the header map handed to the superclass: this class never logs it, keeps it in a field of its own, or prints it from toString.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private boolean
    Set when the state machine gave this attempt up; a late open is then closed at once.
     
    private final BiConsumer<Level,String>
     
    private static final int
     
     

    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
    Modifier
    Constructor
    Description
    (package private)
    AgentSocket(URI uri, Map<String,String> headers, int connectTimeoutMs, AgentConnection.SocketEvents events, BiConsumer<Level,String> log)
     
    private
    AgentSocket(URI uri, Map<String,String> headers, int connectTimeoutMs, AgentConnection.SocketEvents events, BiConsumer<Level,String> log, AtomicReference<UpgradeRejection> sink)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    closeAttempt(int code, String reason)
    Closes the attempt: the closing handshake when open, a forced close otherwise.
    private static String
     
    (package private) UpgradeRejection
     
    void
    onClose(int code, String reason, boolean remote)
     
    void
     
    void
    onMessage(String message)
     
    void
    onOpen(org.java_websocket.handshake.ServerHandshake handshake)
     
    boolean
     

    Methods inherited from class org.java_websocket.client.WebSocketClient

    addHeader, clearHeaders, close, close, close, closeBlocking, closeConnection, connect, connectBlocking, connectBlocking, 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, reconnect, reconnectBlocking, removeHeader, run, send, send, send, sendFragmentedFrame, sendFrame, sendFrame, sendPing, 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 Object

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

  • Constructor Details

  • Method Details

    • lastResponse

      UpgradeRejection lastResponse()
      Returns:
      the upgrade response the draft recorded, or null before one arrived
    • onOpen

      public void onOpen(org.java_websocket.handshake.ServerHandshake handshake)
      Specified by:
      onOpen in class org.java_websocket.client.WebSocketClient
    • onMessage

      public void onMessage(String message)
      Specified by:
      onMessage in class org.java_websocket.client.WebSocketClient
    • onClose

      public void onClose(int code, String reason, boolean remote)
      Specified by:
      onClose in class org.java_websocket.client.WebSocketClient
    • onError

      public void onError(Exception ex)
      Specified by:
      onError in class org.java_websocket.client.WebSocketClient
    • sendText

      public boolean sendText(String text)
      Specified by:
      sendText in interface AgentConnection.Handle
      Parameters:
      text - the text frame
      Returns:
      whether it was handed to an open socket
    • closeAttempt

      public void closeAttempt(int code, String reason)
      Description copied from interface: AgentConnection.Handle
      Closes the attempt: the closing handshake when open, a forced close otherwise.
      Specified by:
      closeAttempt in interface AgentConnection.Handle
      Parameters:
      code - the close code
      reason - the close reason
    • describe

      private static String describe(Exception ex)