-
- Enclosing interface:
- WebSocket
public static interface WebSocket.BuilderA builder for creatingWebSocketinstances.
Incubating Feature. Will be removed in a future release.To obtain a
WebSocketconfigure a builder as required by calling intermediate methods (the ones that return the builder itself), then callbuildAsync(). If an intermediate method is not called, an appropriate default value (or behavior) will be assumed.Unless otherwise stated,
nullarguments will cause methods ofBuilderto throwNullPointerException.- Since:
- 9
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description CompletableFuture<WebSocket>buildAsync(URI uri, WebSocket.Listener listener)WebSocket.BuilderconnectTimeout(Duration timeout)Sets a timeout for establishing a WebSocket connection.WebSocket.Builderheader(String name, String value)Adds the given name-value pair to the list of additional HTTP headers sent during the opening handshake.WebSocket.Buildersubprotocols(String mostPreferred, String... lesserPreferred)Sets a request for the given subprotocols.
-
-
-
Method Detail
-
header
WebSocket.Builder header(String name, String value)
Adds the given name-value pair to the list of additional HTTP headers sent during the opening handshake.Headers defined in WebSocket Protocol are illegal. If this method is not invoked, no additional HTTP headers will be sent.
- Parameters:
name- the header namevalue- the header value- Returns:
- this builder
-
connectTimeout
WebSocket.Builder connectTimeout(Duration timeout)
Sets a timeout for establishing a WebSocket connection.If the connection is not established within the specified duration then building of the
WebSocketwill fail withHttpTimeoutException. If this method is not invoked then the infinite timeout is assumed.
-
subprotocols
WebSocket.Builder subprotocols(String mostPreferred, String... lesserPreferred)
Sets a request for the given subprotocols.After the
WebSockethas been built, the actual subprotocol can be queried viaWebSocket.getSubprotocol().Subprotocols are specified in the order of preference. The most preferred subprotocol is specified first. If there are any additional subprotocols they are enumerated from the most preferred to the least preferred.
Subprotocols not conforming to the syntax of subprotocol identifiers are illegal. If this method is not invoked then no subprotocols will be requested.
- Parameters:
mostPreferred- the most preferred subprotocollesserPreferred- the lesser preferred subprotocols- Returns:
- this builder
-
buildAsync
CompletableFuture<WebSocket> buildAsync(URI uri, WebSocket.Listener listener)
Builds aWebSocketconnected to the givenURIand associated with the givenListener.Returns a
CompletableFuturewhich will either complete normally with the resultingWebSocketor complete exceptionally with one of the following errors:-
IOException- if an I/O error occurs -
WebSocketHandshakeException- if the opening handshake fails -
HttpTimeoutException- if the opening handshake does not complete within the timeout -
InterruptedException- if the operation is interrupted -
SecurityException- if a security manager has been installed and it deniesaccesstouri. Security checks contains more information relating to the security context in which the the listener is invoked. -
IllegalArgumentException- if any of the arguments of this builder's methods are illegal
- Parameters:
uri- the WebSocket URIlistener- the listener- Returns:
- a
CompletableFuturewith theWebSocket
-
-
-