Class BuilderImpl

    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.concurrent.CompletableFuture<WebSocket> buildAsync()
      Builds a WebSocket.
      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()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • 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 interface WebSocket.Builder
        Parameters:
        name - the header name
        value - 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 interface WebSocket.Builder
        Parameters:
        mostPreferred - the most preferred subprotocol
        lesserPreferred - 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 from WebSocket.Builder.buildAsync() completes exceptionally with a HttpTimeoutException.

        If this method is not invoked then the timeout is deemed infinite.

        Specified by:
        connectTimeout in interface WebSocket.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 a 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
        • 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 a URLPermission for the WebSocket URI
        • IllegalArgumentException - if any of the additional headers are illegal; or if any of the WebSocket Protocol rules relevant to subprotocols are violated; or if the connect timeout is invalid;
        Specified by:
        buildAsync in interface WebSocket.Builder
        Returns:
        a CompletableFuture with the WebSocket
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object