Package com.ultikits.ultitools.utils
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
FieldsModifier and TypeFieldDescriptionprivate booleanSet when the state machine gave this attempt up; a late open is then closed at once.private final AgentConnection.SocketEventsprivate final BiConsumer<Level, String> private static final intprivate final AtomicReference<UpgradeRejection> Fields inherited from class org.java_websocket.client.WebSocketClient
uriFields inherited from class org.java_websocket.AbstractWebSocket
DEFAULT_READ_BUFFER_SIZE -
Constructor Summary
ConstructorsModifierConstructorDescription(package private)AgentSocket(URI uri, Map<String, String> headers, int connectTimeoutMs, AgentConnection.SocketEvents events, BiConsumer<Level, String> log) privateAgentSocket(URI uri, Map<String, String> headers, int connectTimeoutMs, AgentConnection.SocketEvents events, BiConsumer<Level, String> log, AtomicReference<UpgradeRejection> sink) -
Method Summary
Modifier and TypeMethodDescriptionvoidcloseAttempt(int code, String reason) Closes the attempt: the closing handshake when open, a forced close otherwise.private static String(package private) UpgradeRejectionvoidvoidvoidvoidonOpen(org.java_websocket.handshake.ServerHandshake handshake) booleanMethods 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, 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
-
MAX_ERROR_TEXT
private static final int MAX_ERROR_TEXT- See Also:
-
sink
-
events
-
log
-
abandoned
private volatile boolean abandonedSet when the state machine gave this attempt up; a late open is then closed at once.
-
-
Constructor Details
-
AgentSocket
AgentSocket(URI uri, Map<String, String> headers, int connectTimeoutMs, AgentConnection.SocketEvents events, BiConsumer<Level, String> log) - Parameters:
uri- the agent endpointheaders- the upgrade headers built byAgentConnection.buildHeaders(java.lang.String)connectTimeoutMs- the TCP connect timeoutevents- this attempt's event sinklog- the panel-connection log sink
-
AgentSocket
private AgentSocket(URI uri, Map<String, String> headers, int connectTimeoutMs, AgentConnection.SocketEvents events, BiConsumer<Level, String> log, AtomicReference<UpgradeRejection> sink)
-
-
Method Details
-
lastResponse
UpgradeRejection lastResponse()- Returns:
- the upgrade response the draft recorded, or
nullbefore one arrived
-
onOpen
public void onOpen(org.java_websocket.handshake.ServerHandshake handshake) - Specified by:
onOpenin classorg.java_websocket.client.WebSocketClient
-
onMessage
- Specified by:
onMessagein classorg.java_websocket.client.WebSocketClient
-
onClose
- Specified by:
onClosein classorg.java_websocket.client.WebSocketClient
-
onError
- Specified by:
onErrorin classorg.java_websocket.client.WebSocketClient
-
sendText
- Specified by:
sendTextin interfaceAgentConnection.Handle- Parameters:
text- the text frame- Returns:
- whether it was handed to an open socket
-
closeAttempt
Description copied from interface:AgentConnection.HandleCloses the attempt: the closing handshake when open, a forced close otherwise.- Specified by:
closeAttemptin interfaceAgentConnection.Handle- Parameters:
code- the close codereason- the close reason
-
describe
-