public class WebSocketConnection
extends java.lang.Object
client.ws("ws://server/path", msg -> {
// Message received; "msg" is a JSON structure
String value = msg.get("key", "defaultValue");
});
Advanced usage; WebSocket client with custom parameters:
WebSocketConnection ws = client.ws("ws://server/path", msg -> {
// Message received; "msg" is a JSON structure
String value = msg.get("key", "defaultValue");
}, params -> {
// Configure connection
params.setHeartbeatInterval(60);
params.setHeader("key", "value");
}, false);
// Create connection
ws.connect();
| Modifier and Type | Field and Description |
|---|---|
protected java.util.concurrent.atomic.AtomicBoolean |
closed |
protected java.util.function.Consumer<WebSocketParams> |
configurator |
protected java.util.concurrent.atomic.AtomicReference<io.datatree.Promise> |
connected |
protected java.util.concurrent.atomic.AtomicReference<io.datatree.Promise> |
disconnected |
protected WebSocketHandler |
handler |
protected HttpClient |
httpClient |
protected static org.slf4j.Logger |
logger |
protected WebSocketParams |
params |
protected java.util.concurrent.atomic.AtomicLong |
receivedAt |
protected java.util.concurrent.atomic.AtomicReference<java.util.concurrent.ScheduledFuture<?>> |
reconnectTimer |
protected java.util.concurrent.atomic.AtomicLong |
submittedAt |
protected java.lang.String |
url |
protected java.util.concurrent.atomic.AtomicReference<org.asynchttpclient.ws.WebSocket> |
webSocket |
| Modifier | Constructor and Description |
|---|---|
protected |
WebSocketConnection(HttpClient httpClient,
java.lang.String url,
WebSocketHandler handler,
java.util.function.Consumer<WebSocketParams> configurator) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
closeConnection(org.asynchttpclient.ws.WebSocket targetSocket) |
io.datatree.Promise |
connect() |
io.datatree.Promise |
disconnect() |
protected void |
finalize() |
protected void |
openConnection() |
protected void |
reconnect() |
void |
waitForConnection(long timeout,
java.util.concurrent.TimeUnit unit)
Waiting for "connected" status.
|
protected static final org.slf4j.Logger logger
protected final HttpClient httpClient
protected final java.lang.String url
protected final WebSocketHandler handler
protected final java.util.function.Consumer<WebSocketParams> configurator
protected final java.util.concurrent.atomic.AtomicReference<org.asynchttpclient.ws.WebSocket> webSocket
protected final java.util.concurrent.atomic.AtomicReference<java.util.concurrent.ScheduledFuture<?>> reconnectTimer
protected final java.util.concurrent.atomic.AtomicReference<io.datatree.Promise> connected
protected final java.util.concurrent.atomic.AtomicReference<io.datatree.Promise> disconnected
protected final java.util.concurrent.atomic.AtomicBoolean closed
protected final java.util.concurrent.atomic.AtomicLong submittedAt
protected final java.util.concurrent.atomic.AtomicLong receivedAt
protected WebSocketParams params
protected WebSocketConnection(HttpClient httpClient, java.lang.String url, WebSocketHandler handler, java.util.function.Consumer<WebSocketParams> configurator)
public io.datatree.Promise connect()
protected void openConnection()
public void waitForConnection(long timeout,
java.util.concurrent.TimeUnit unit)
throws java.lang.Exception
timeout - the maximum time to waitunit - the time unit of the timeout argumentjava.lang.Exception - any (interruption, execution, user-level, etc.) exceptionpublic io.datatree.Promise disconnect()
protected void closeConnection(org.asynchttpclient.ws.WebSocket targetSocket)
protected void finalize()
throws java.lang.Throwable
finalize in class java.lang.Objectjava.lang.Throwableprotected void reconnect()