Class WebSocketClient
java.lang.Object
com.cumulocity.sdk.client.notification2.internal.WebSocketClient
- All Implemented Interfaces:
WebSocketConnectorListener
This class is responsible for establishing and maintaining a websocket connection + connection token management.
It also notifies about received messages (notifications).
An instance of this class is created per subscription.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionWebSocketClient
(String webSocketBaseUrl, String subscriber, String subscriptionName, AckMode ackMode, String tenantId, String deviceId, NotificationListener notificationListener, Duration reconnectDelay, Duration tokenRefreshInterval, boolean isTokenShared, boolean isTokenPersistent, TokenApi tokenApi, WebSocketConnector connector) -
Method Summary
Modifier and TypeMethodDescriptionboolean
void
onWebsocketClosed
(int code, String reason) connection closedvoid
connection errorvoid
onWebsocketMessage
(String text) message receivedvoid
connection establishedvoid
start()
Connects to web socket and schedules token refresh job package privatevoid
stop
(boolean unsubscribe) Disconnects and stops the client including scheduled jobs for reconnection and token refresh
-
Field Details
-
MESSAGE_TOKEN_REFRESH
- See Also:
-
MESSAGE_SHUTDOWN
- See Also:
-
-
Constructor Details
-
WebSocketClient
public WebSocketClient(String webSocketBaseUrl, String subscriber, String subscriptionName, AckMode ackMode, String tenantId, String deviceId, NotificationListener notificationListener, Duration reconnectDelay, Duration tokenRefreshInterval, boolean isTokenShared, boolean isTokenPersistent, TokenApi tokenApi, WebSocketConnector connector)
-
-
Method Details
-
start
public void start()Connects to web socket and schedules token refresh job package private -
stop
public void stop(boolean unsubscribe) Disconnects and stops the client including scheduled jobs for reconnection and token refresh -
onWebsocketClosed
Description copied from interface:WebSocketConnectorListener
connection closed- Specified by:
onWebsocketClosed
in interfaceWebSocketConnectorListener
- Parameters:
code
- closing codereason
- closing reason
-
onWebsocketError
Description copied from interface:WebSocketConnectorListener
connection error- Specified by:
onWebsocketError
in interfaceWebSocketConnectorListener
- Parameters:
t
- exception details
-
onWebsocketOpen
public void onWebsocketOpen()Description copied from interface:WebSocketConnectorListener
connection established- Specified by:
onWebsocketOpen
in interfaceWebSocketConnectorListener
-
onWebsocketMessage
Description copied from interface:WebSocketConnectorListener
message received- Specified by:
onWebsocketMessage
in interfaceWebSocketConnectorListener
- Parameters:
text
- message text
-
getRawWebSocket
-
isRunning
public boolean isRunning()
-