Interface WebSocketAdapter
-
- All Superinterfaces:
AutoCloseable
,Closeable
public interface WebSocketAdapter extends Closeable
Basic websocket application interface facilitating different provider implementations. See implementation documentation to understand specific configuration options.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
close()
WebSocketAdapter
closeHandler(Consumer<Void> closeHandler)
Supply a close handler executed once the client websocket connection being closed.WebSocketAdapter
exceptionHandler(Consumer<Throwable> exceptionHandler)
Supply an exception handler capable of consuming websocket exceptions.WebSocketAdapter
messageHandler(Consumer<JsonValue> messageHandler)
Supply a message handler capable of consuming server requests.WebSocketAdapter
openHandler(Consumer<WebSocketAdapter> openHandler)
Supply an open handler executed once the websocket connection is established and completed.WebSocketAdapter
reconnect(Duration reconnectDelay)
Supply reconnect configuration to support reconnection attempts should the websocket be terminated remotely.Promise<Void,IOException>
sendObject(Object request)
Send the supplied request over the websocket to the remote party.WebSocketAdapter
ssoHeader(String headerName, String token)
Provide values for a SSO token header.WebSocketAdapter
start()
Start the websocket client and connect to the remote endpoint.WebSocketAdapter
subprotocols(List<String> subprotocols)
Supply a list of protocols supported by this websocket client.
-
-
-
Method Detail
-
start
WebSocketAdapter start()
Start the websocket client and connect to the remote endpoint.- Returns:
this
instance supporting a fluent API
-
close
void close() throws IOException
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-
sendObject
Promise<Void,IOException> sendObject(Object request)
Send the supplied request over the websocket to the remote party.- Parameters:
request
- The request to transmit- Returns:
Promise
of anyIOException
that occurred in the event of a send failure
-
openHandler
WebSocketAdapter 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
WebSocketAdapter closeHandler(Consumer<Void> closeHandler)
Supply a close handler executed once the client websocket connection being closed. That is, if the websocket is closed using itsclose()
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
WebSocketAdapter 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
WebSocketAdapter 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
-
subprotocols
WebSocketAdapter subprotocols(List<String> subprotocols)
Supply a list of protocols supported by this websocket client.- Parameters:
subprotocols
- the supported subprotocols (notnull
)- Returns:
this
instance supporting a fluent API
-
ssoHeader
WebSocketAdapter ssoHeader(String headerName, String token)
Provide values for a SSO token header.- Parameters:
headerName
- The SSO header name (notnull
)token
- The SSO token value (notnull
)- Returns:
this
instance supporting a fluent API
-
reconnect
WebSocketAdapter reconnect(Duration reconnectDelay)
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 seconds.- Parameters:
reconnectDelay
- the relay after which a reconnect will be attempted, in seconds (notnull
)- Returns:
this
instance supporting a fluent API
-
-