@Contract(threading=STATELESS) public abstract class CloseableWebSocketClient extends Object implements WebSocketClient, ModalCloseable
CloseableHttpAsyncClient's shape.
Subclasses provide the actual connect implementation in
doConnect(URI, WebSocketListener, WebSocketClientConfig, HttpContext).
Overloads of connect(...) funnel into that single method.
This type is a ModalCloseable; use ModalCloseable.close(CloseMode) to select
graceful or immediate shutdown. A graceful close allows in-flight I/O to finish,
while immediate close aborts active operations.
| Constructor and Description |
|---|
CloseableWebSocketClient() |
| Modifier and Type | Method and Description |
|---|---|
abstract void |
awaitShutdown(TimeValue waitTime)
Best-effort await of shutdown.
|
CompletableFuture<WebSocket> |
connect(URI uri,
WebSocketListener listener)
Convenience overload that uses the client's default configuration and
a fresh
HttpCoreContext. |
CompletableFuture<WebSocket> |
connect(URI uri,
WebSocketListener listener,
WebSocketClientConfig cfg)
Convenience overload that uses a fresh
HttpCoreContext. |
CompletableFuture<WebSocket> |
connect(URI uri,
WebSocketListener listener,
WebSocketClientConfig cfg,
HttpContext context)
Initiates an asynchronous WebSocket connection to the given target URI.
|
protected abstract CompletableFuture<WebSocket> |
doConnect(URI uri,
WebSocketListener listener,
WebSocketClientConfig cfg,
HttpContext context)
Core connect hook for subclasses.
|
abstract IOReactorStatus |
getStatus()
Current I/O reactor status.
|
abstract void |
initiateShutdown()
Initiate shutdown (non-blocking).
|
abstract void |
start()
Start underlying I/O.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitclosepublic abstract void start()
public abstract IOReactorStatus getStatus()
public abstract void awaitShutdown(TimeValue waitTime) throws InterruptedException
InterruptedExceptionpublic abstract void initiateShutdown()
protected abstract CompletableFuture<WebSocket> doConnect(URI uri, WebSocketListener listener, WebSocketClientConfig cfg, HttpContext context)
uri - target WebSocket URI (ws:// or wss://)listener - application callbackscfg - optional per-connection config (may be null for defaults)context - optional HTTP context (may be null)public final CompletableFuture<WebSocket> connect(URI uri, WebSocketListener listener)
HttpCoreContext.uri - target WebSocket URI (ws or wss)listener - callback for WebSocket eventsWebSocketpublic final CompletableFuture<WebSocket> connect(URI uri, WebSocketListener listener, WebSocketClientConfig cfg)
HttpCoreContext.uri - target WebSocket URI (ws or wss)listener - callback for WebSocket eventscfg - per-connection configuration, or null for defaultsWebSocketpublic final CompletableFuture<WebSocket> connect(URI uri, WebSocketListener listener, WebSocketClientConfig cfg, HttpContext context)
The URI must use the ws or wss scheme. This method
performs an HTTP/1.1 upgrade to the WebSocket protocol and, on success,
creates a WebSocket associated with the supplied
WebSocketListener.
The operation is fully asynchronous. The returned
CompletableFuture completes when the opening WebSocket
handshake has either succeeded or failed.
connect in interface WebSocketClienturi - target WebSocket URI, must not be null.listener - callback that receives WebSocket events, must not be null.cfg - optional per-connection configuration; if null, the
client’s default configuration is used.context - optional HTTP context for the underlying upgrade request;
may be null.WebSocket on
success, or completes exceptionally if the connection attempt
or protocol handshake fails.Copyright © 1999–2021 The Apache Software Foundation. All rights reserved.