Interface WebSocket.Builder

  • Enclosing interface:
    WebSocket

    public static interface WebSocket.Builder
    A builder for creating WebSocket instances.
    Incubating Feature. Will be removed in a future release.

    To obtain a WebSocket configure a builder as required by calling intermediate methods (the ones that return the builder itself), then call buildAsync(). If an intermediate method is not called, an appropriate default value (or behavior) will be assumed.

    Unless otherwise stated, null arguments will cause methods of Builder to throw NullPointerException.

    Since:
    9
    • 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 name
        value - 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 WebSocket will fail with HttpTimeoutException. If this method is not invoked then the infinite timeout is assumed.

        Parameters:
        timeout - the timeout, non-negative, non-ZERO
        Returns:
        this builder
      • subprotocols

        WebSocket.Builder subprotocols​(String mostPreferred,
                                       String... lesserPreferred)
        Sets a request for the given subprotocols.

        After the WebSocket has been built, the actual subprotocol can be queried via WebSocket.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 subprotocol
        lesserPreferred - the lesser preferred subprotocols
        Returns:
        this builder