Class BuilderImpl
- java.lang.Object
-
- jdk.incubator.http.internal.websocket.BuilderImpl
-
- All Implemented Interfaces:
WebSocket.Builder
public final class BuilderImpl extends java.lang.Object implements WebSocket.Builder
-
-
Constructor Summary
Constructors Constructor Description BuilderImpl(HttpClient client, java.net.URI uri, WebSocket.Listener listener)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.concurrent.CompletableFuture<WebSocket>
buildAsync()
Builds aWebSocket
.WebSocket.Builder
connectTimeout(java.time.Duration timeout)
Sets a timeout for the opening handshake.WebSocket.Builder
header(java.lang.String name, java.lang.String value)
Adds the given name-value pair to the list of additional headers for the opening handshake.WebSocket.Builder
subprotocols(java.lang.String mostPreferred, java.lang.String... lesserPreferred)
Includes a request for the given subprotocols during the opening handshake.java.lang.String
toString()
-
-
-
Constructor Detail
-
BuilderImpl
public BuilderImpl(HttpClient client, java.net.URI uri, WebSocket.Listener listener)
-
-
Method Detail
-
header
public WebSocket.Builder header(java.lang.String name, java.lang.String value)
Description copied from interface:WebSocket.Builder
Adds the given name-value pair to the list of additional headers for the opening handshake.Headers defined in WebSocket Protocol are not allowed to be added.
- Specified by:
header
in interfaceWebSocket.Builder
- Parameters:
name
- the header namevalue
- the header value- Returns:
- this builder
-
subprotocols
public WebSocket.Builder subprotocols(java.lang.String mostPreferred, java.lang.String... lesserPreferred)
Description copied from interface:WebSocket.Builder
Includes a request for the given subprotocols during the opening handshake.Among the requested subprotocols at most one will be chosen by the server. This subprotocol will be available from
WebSocket.getSubprotocol()
. Subprotocols are specified in the order of preference.Each of the given subprotocols must conform to the relevant rules defined in the WebSocket Protocol.
If this method is not invoked then no subprotocols are requested.
- Specified by:
subprotocols
in interfaceWebSocket.Builder
- Parameters:
mostPreferred
- the most preferred subprotocollesserPreferred
- the lesser preferred subprotocols, with the least preferred at the end- Returns:
- this builder
-
connectTimeout
public WebSocket.Builder connectTimeout(java.time.Duration timeout)
Description copied from interface:WebSocket.Builder
Sets a timeout for the opening handshake.If the opening handshake does not complete within the specified duration then the
CompletableFuture
returned fromWebSocket.Builder.buildAsync()
completes exceptionally with aHttpTimeoutException
.If this method is not invoked then the timeout is deemed infinite.
- Specified by:
connectTimeout
in interfaceWebSocket.Builder
- Parameters:
timeout
- the timeout, non-negative, non-ZERO- Returns:
- this builder
-
buildAsync
public java.util.concurrent.CompletableFuture<WebSocket> buildAsync()
Description copied from interface:WebSocket.Builder
Builds aWebSocket
.Returns a
CompletableFuture<WebSocket>
which completes normally with theWebSocket
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 -
WebSocketHandshakeException
- if the opening handshake fails -
HttpTimeoutException
- if the opening handshake does not complete within the specified duration -
InterruptedException
- if the operation was interrupted -
SecurityException
- if a security manager is set, and the caller does not have aURLPermission
for the WebSocket URI -
IllegalArgumentException
- if any of the additionalheaders
are illegal; or if any of the WebSocket Protocol rules relevant tosubprotocols
are violated; or if theconnect timeout
is invalid;
- Specified by:
buildAsync
in interfaceWebSocket.Builder
- Returns:
- a
CompletableFuture
with theWebSocket
-
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-