public static interface WebSocket.Builder
WebSocket instances.
To build a WebSocket, instantiate a builder, configure it
as required by calling intermediate methods (the ones that return the
builder itself), then finally call buildAsync() to get a CompletableFuture with resulting WebSocket.
If an intermediate method has not been called, an appropriate default value (or behavior) will be used. Unless otherwise noted, a repeated call to an intermediate method overwrites the previous value (or overrides the previous behaviour), if no exception is thrown.
Instances of Builder may not be safe for use by multiple
threads.
| Modifier and Type | Method | Description |
|---|---|---|
CompletableFuture<WebSocket> |
buildAsync() |
Builds a
WebSocket. |
WebSocket.Builder |
connectTimeout(Duration timeout) |
Sets a timeout for the opening handshake.
|
WebSocket.Builder |
header(String name,
String value) |
Adds the given name-value pair to the list of additional headers for
the opening handshake.
|
WebSocket.Builder |
subprotocols(String mostPreferred,
String... lesserPreferred) |
Includes a request for the given subprotocols during the opening
handshake.
|
WebSocket.Builder header(String name, String value)
Headers defined in WebSocket Protocol are not allowed to be added.
name - the header namevalue - the header valueIllegalArgumentException - if the name is a WebSocket defined header nameWebSocket.Builder subprotocols(String mostPreferred, String... lesserPreferred)
Among the requested subprotocols at most one will be chosen by
the server. When the WebSocket is connected, the subprotocol
in use is available from WebSocket.getSubprotocol().
Subprotocols may be specified in the order of preference.
Each of the given subprotocols must conform to the relevant rules defined in the WebSocket Protocol.
mostPreferred - the most preferred subprotocollesserPreferred - the lesser preferred subprotocols, with the least preferred
at the endIllegalArgumentException - if any of the WebSocket Protocol rules relevant to
subprotocols are violatedWebSocket.Builder connectTimeout(Duration timeout)
If the opening handshake is not finished within the specified
amount of time then buildAsync() completes exceptionally
with a HttpTimeoutException.
If this method is not invoked then the timeout is deemed infinite.
timeout - the timeoutCompletableFuture<WebSocket> buildAsync()
WebSocket.
Returns a CompletableFuture<WebSocket> which completes
normally with the WebSocket when it is connected or completes
exceptionally if an error occurs.
CompletableFuture may complete exceptionally with the
following errors:
IOException
if an I/O error occurs
InterruptedException
if the operation was interrupted
SecurityException
if a security manager is set, and the caller does not
have a URLPermission for the WebSocket URI
WebSocketHandshakeException
if the opening handshake fails
CompletableFuture with the WebSocket Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2016, Oracle and/or its affiliates. All rights reserved.
DRAFT 9-Ubuntu+0-9b143-1ubuntu1