Class WebsocketConnection.Builder<B extends WebsocketConnection.Builder<B>>

java.lang.Object
org.javagi.gobject.Builder<B>
org.gnome.gobject.GObject.Builder<B>
org.gnome.soup.WebsocketConnection.Builder<B>
Type Parameters:
B - the type of the Builder that is returned
All Implemented Interfaces:
BuilderInterface
Enclosing class:
WebsocketConnection

public static class WebsocketConnection.Builder<B extends WebsocketConnection.Builder<B>> extends GObject.Builder<B>
Inner class implementing a builder pattern to construct a GObject with properties.
  • Constructor Details

    • Builder

      protected Builder()
      Default constructor for a Builder object.
  • Method Details

    • build

      public WebsocketConnection build()
      Finish building the WebsocketConnection object. This will call GObject.withProperties(Type, String[], Value[]) to create a new GObject instance, which is then cast to WebsocketConnection.
      Overrides:
      build in class GObject.Builder<B extends WebsocketConnection.Builder<B>>
      Returns:
      a new instance of WebsocketConnection with the properties that were set in the Builder object.
    • setConnectionType

      public B setConnectionType(WebsocketConnectionType connectionType)
      The type of connection (client/server).
      Parameters:
      connectionType - the value for the connection-type property
      Returns:
      the Builder instance is returned, to allow method chaining
    • setExtensions

      public B setExtensions(MemorySegment extensions)
      List of WebsocketExtension objects that are active in the connection.
      Parameters:
      extensions - the value for the extensions property
      Returns:
      the Builder instance is returned, to allow method chaining
    • setIoStream

      public B setIoStream(IOStream ioStream)

      The underlying IO stream the WebSocket is communicating over.

      The input and output streams must be pollable streams.

      Parameters:
      ioStream - the value for the io-stream property
      Returns:
      the Builder instance is returned, to allow method chaining
    • setKeepaliveInterval

      public B setKeepaliveInterval(int keepaliveInterval)

      Interval in seconds on when to send a ping message which will serve as a keepalive message.

      If set to 0 the keepalive message is disabled.

      Parameters:
      keepaliveInterval - the value for the keepalive-interval property
      Returns:
      the Builder instance is returned, to allow method chaining
    • setKeepalivePongTimeout

      public B setKeepalivePongTimeout(int keepalivePongTimeout)

      Timeout in seconds for when the absence of a pong from a keepalive ping is assumed to be caused by a faulty connection. The WebSocket will be transitioned to a closed state when this happens.

      If set to 0 then the absence of pongs from keepalive pings is ignored.

      Parameters:
      keepalivePongTimeout - the value for the keepalive-pong-timeout property
      Returns:
      the Builder instance is returned, to allow method chaining
      Since:
      3.6
    • setMaxIncomingPayloadSize

      public B setMaxIncomingPayloadSize(long maxIncomingPayloadSize)

      The maximum payload size for incoming packets.

      The protocol expects or 0 to not limit it.

      Parameters:
      maxIncomingPayloadSize - the value for the max-incoming-payload-size property
      Returns:
      the Builder instance is returned, to allow method chaining
    • setOrigin

      public B setOrigin(String origin)
      The client's Origin.
      Parameters:
      origin - the value for the origin property
      Returns:
      the Builder instance is returned, to allow method chaining
    • setProtocol

      public B setProtocol(String protocol)
      The chosen protocol, or null if a protocol was not agreed upon.
      Parameters:
      protocol - the value for the protocol property
      Returns:
      the Builder instance is returned, to allow method chaining
    • setUri

      public B setUri(Uri uri)

      The URI of the WebSocket.

      For servers this represents the address of the WebSocket, and for clients it is the address connected to.

      Parameters:
      uri - the value for the uri property
      Returns:
      the Builder instance is returned, to allow method chaining
    • onClosed

      public B onClosed(WebsocketConnection.ClosedCallback handler)

      Emitted when the connection has completely closed.

      This happens either due to an orderly close from the peer, one initiated via WebsocketConnection.close(short, String) or a fatal error condition that caused a close.

      This signal will be emitted once.

      Parameters:
      handler - the signal handler
      Returns:
      the Builder instance is returned, to allow method chaining
      See Also:
    • onClosing

      public B onClosing(WebsocketConnection.ClosingCallback handler)
      This signal will be emitted during an orderly close.
      Parameters:
      handler - the signal handler
      Returns:
      the Builder instance is returned, to allow method chaining
      See Also:
    • onError

      public B onError(WebsocketConnection.ErrorCallback handler)

      Emitted when an error occurred on the WebSocket.

      This may be fired multiple times. Fatal errors will be followed by the WebsocketConnection::closed signal being emitted.

      Parameters:
      handler - the signal handler
      Returns:
      the Builder instance is returned, to allow method chaining
      See Also:
    • onMessage

      public B onMessage(WebsocketConnection.MessageCallback handler)

      Emitted when we receive a message from the peer.

      As a convenience, the message data will always be null-terminated, but the NUL byte will not be included in the length count.

      Parameters:
      handler - the signal handler
      Returns:
      the Builder instance is returned, to allow method chaining
      See Also:
    • onPong

      public B onPong(WebsocketConnection.PongCallback handler)

      Emitted when we receive a Pong frame (solicited or unsolicited) from the peer.

      As a convenience, the message data will always be null-terminated, but the NUL byte will not be included in the length count.

      Parameters:
      handler - the signal handler
      Returns:
      the Builder instance is returned, to allow method chaining
      See Also: