Class WebSocketAdapterConfiguration


  • public class WebSocketAdapterConfiguration
    extends Object
    A configuration holder to instantiate WebSocketAdapter.
    • Constructor Detail

      • WebSocketAdapterConfiguration

        public WebSocketAdapterConfiguration​(URI uri,
                                             List<String> subProtocols)
        Create an instance of a WebSocketAdapterConfiguration.
        Parameters:
        uri - The Websocket remote endpoint (not null)
        subProtocols - The Websocket sub-protocol list to support (not null)
    • Method Detail

      • openHandler

        public WebSocketAdapterConfiguration openHandler​(Consumer<WebSocketAdapter> openHandler)
        Supply an open handler executed once the websocket connection is established and completed. The handler is called once on the connection being successfully established and on any successful reconnections.
        Parameters:
        openHandler - the open handler (not null)
        Returns:
        this instance supporting a fluent API
      • closeHandler

        public WebSocketAdapterConfiguration closeHandler​(Consumer<Void> closeHandler)
        Supply a close handler executed once the client websocket connection being closed. That is, if the websocket is closed using its WebSocketAdapter.close() method then this handler will be executed on completion. It is not called on remote websocket disconnections or exceptions.
        Parameters:
        closeHandler - the close handler (not null)
        Returns:
        this instance supporting a fluent API
      • messageHandler

        public WebSocketAdapterConfiguration messageHandler​(Consumer<JsonValue> messageHandler)
        Supply a message handler capable of consuming server requests. The handler is called on receipt of a message on the websocket.
        Parameters:
        messageHandler - the message handler (not null)
        Returns:
        this instance supporting a fluent API
      • exceptionHandler

        public WebSocketAdapterConfiguration exceptionHandler​(Consumer<Throwable> exceptionHandler)
        Supply an exception handler capable of consuming websocket exceptions. The exception handler is called in the event of exceptions on the websocket and after reconnection attempts have failed.
        Parameters:
        exceptionHandler - the exception handler (not null)
        Returns:
        this instance supporting a fluent API
      • reconnect

        public WebSocketAdapterConfiguration reconnect​(Duration reconnectDelay,
                                                       int initialConnectionAttempts)
        Supply reconnect configuration to support reconnection attempts should the websocket be terminated remotely. This includes constraining the reconnection attempts to execute with a delay of reconnectDelay.
        Parameters:
        reconnectDelay - the delay after which a reconnect will be attempted (not null)
        initialConnectionAttempts - the number of retries allowed for the first connection
        Returns:
        this instance supporting a fluent API
      • getUri

        public URI getUri()
        The Websocket remote endpoint URI (guaranteed to be not null).
        Returns:
        The Websocket remote endpoint URI (guaranteed to be not null)
      • getOpenHandler

        public Consumer<WebSocketAdapter> getOpenHandler()
        The open handler (guaranteed to be not null).
        Returns:
        The open handler (guaranteed to be not null)
      • getCloseHandler

        public Consumer<Void> getCloseHandler()
        The close handler (guaranteed to be not null).
        Returns:
        The close handler (guaranteed to be not null)
      • getMessageHandler

        public Consumer<JsonValue> getMessageHandler()
        The message handler (guaranteed to be not null).
        Returns:
        The message handler (guaranteed to be not null)
      • getExceptionHandler

        public Consumer<Throwable> getExceptionHandler()
        The exception handler (guaranteed to be not null).
        Returns:
        The exception handler (guaranteed to be not null)
      • getSubProtocols

        public List<String> getSubProtocols()
        The subProtocols list to support (guaranteed to be not null).
        Returns:
        the subProtocols list to support (guaranteed to be not null)
      • getReconnectDelay

        public Duration getReconnectDelay()
        The delay after which a reconnect will be attempted.
        Returns:
        The delay after which a reconnect will be attempted
      • getInitialConnectionAttempts

        public int getInitialConnectionAttempts()
        The number of retries allowed for the first connection.
        Returns:
        The number of retries allowed for the first connection
      • getHeaderName

        public String getHeaderName()
        The SSO header name.
        Returns:
        The SSO header name
      • getHeartbeatExecutorService

        public ScheduledExecutorService getHeartbeatExecutorService()
        The executor service to use to schedule heartbeat tasks.
        Returns:
        The executor service to use to schedule heartbeat tasks.
      • getHeartbeatInterval

        public Duration getHeartbeatInterval()
        The interval between heartbeats. Duration.UNLIMITED and Duration.ZERO represent no heartbeat.
        Returns:
        The interval between heartbeats.