Class WebSocketAdapterConfiguration
- java.lang.Object
-
- org.forgerock.openig.tools.notifications.ws.WebSocketAdapterConfiguration
-
public class WebSocketAdapterConfiguration extends Object
A configuration holder to instantiateWebSocketAdapter
.
-
-
Constructor Summary
Constructors Constructor Description WebSocketAdapterConfiguration(URI uri, List<String> subProtocols)
Create an instance of aWebSocketAdapterConfiguration
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description WebSocketAdapterConfiguration
closeHandler(Consumer<Void> closeHandler)
Supply a close handler executed once the client websocket connection being closed.WebSocketAdapterConfiguration
exceptionHandler(Consumer<Throwable> exceptionHandler)
Supply an exception handler capable of consuming websocket exceptions.Consumer<Void>
getCloseHandler()
The close handler (guaranteed to be notnull
).Consumer<Throwable>
getExceptionHandler()
The exception handler (guaranteed to be notnull
).String
getHeaderName()
The SSO header name.ScheduledExecutorService
getHeartbeatExecutorService()
The executor service to use to schedule heartbeat tasks.Duration
getHeartbeatInterval()
The interval between heartbeats.int
getInitialConnectionAttempts()
The number of retries allowed for the first connection.Consumer<JsonValue>
getMessageHandler()
The message handler (guaranteed to be notnull
).Consumer<WebSocketAdapter>
getOpenHandler()
The open handler (guaranteed to be notnull
).Duration
getReconnectDelay()
The delay after which a reconnect will be attempted.List<String>
getSubProtocols()
The subProtocols list to support (guaranteed to be notnull
).AsyncRefreshableSupplier<SsoToken,AuthenticationException>
getTokenProvider()
The SSO token value provider.URI
getUri()
The Websocket remote endpoint URI (guaranteed to be notnull
).WebSocketAdapterConfiguration
heartbeat(Duration interval, ScheduledExecutorService executorService)
Supply The heartbeat setup to keep the websocket session busy.WebSocketAdapterConfiguration
messageHandler(Consumer<JsonValue> messageHandler)
Supply a message handler capable of consuming server requests.WebSocketAdapterConfiguration
openHandler(Consumer<WebSocketAdapter> openHandler)
Supply an open handler executed once the websocket connection is established and completed.WebSocketAdapterConfiguration
reconnect(Duration reconnectDelay, int initialConnectionAttempts)
Supply reconnect configuration to support reconnection attempts should the websocket be terminated remotely.WebSocketAdapterConfiguration
ssoHeader(String headerName, AsyncRefreshableSupplier<SsoToken,AuthenticationException> tokenProvider)
Provide values for a SSO token header.
-
-
-
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 (notnull
)- 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 itsWebSocketAdapter.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 (notnull
)- 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 (notnull
)- 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 (notnull
)- Returns:
this
instance supporting a fluent API
-
ssoHeader
public WebSocketAdapterConfiguration ssoHeader(String headerName, AsyncRefreshableSupplier<SsoToken,AuthenticationException> tokenProvider)
Provide values for a SSO token header.- Parameters:
headerName
- The SSO header name (notnull
)tokenProvider
- The SSO token value provider (notnull
)- 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 (notnull
)initialConnectionAttempts
- the number of retries allowed for the first connection- Returns:
this
instance supporting a fluent API
-
heartbeat
public WebSocketAdapterConfiguration heartbeat(Duration interval, ScheduledExecutorService executorService)
Supply The heartbeat setup to keep the websocket session busy.- Parameters:
interval
- the interval between heartbeats.null
is an invalid value,Duration.UNLIMITED
andDuration.ZERO
represent no heartbeat.executorService
- the executor service to use to schedule heartbeat tasks.- Returns:
this
instance supporting a fluent API
-
getUri
public URI getUri()
The Websocket remote endpoint URI (guaranteed to be notnull
).- Returns:
- The Websocket remote endpoint URI (guaranteed to be not
null
)
-
getOpenHandler
public Consumer<WebSocketAdapter> getOpenHandler()
The open handler (guaranteed to be notnull
).- Returns:
- The open handler (guaranteed to be not
null
)
-
getCloseHandler
public Consumer<Void> getCloseHandler()
The close handler (guaranteed to be notnull
).- Returns:
- The close handler (guaranteed to be not
null
)
-
getMessageHandler
public Consumer<JsonValue> getMessageHandler()
The message handler (guaranteed to be notnull
).- Returns:
- The message handler (guaranteed to be not
null
)
-
getExceptionHandler
public Consumer<Throwable> getExceptionHandler()
The exception handler (guaranteed to be notnull
).- Returns:
- The exception handler (guaranteed to be not
null
)
-
getSubProtocols
public List<String> getSubProtocols()
The subProtocols list to support (guaranteed to be notnull
).- 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
-
getTokenProvider
public AsyncRefreshableSupplier<SsoToken,AuthenticationException> getTokenProvider()
The SSO token value provider.- Returns:
- The SSO token value provider
-
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
andDuration.ZERO
represent no heartbeat.- Returns:
- The interval between heartbeats.
-
-