Top Description Fields Constructors Methods
org.glassfish.tyrus.core.cluster

public abstract Class ClusterContext

extends Object
Class Inheritance
Imports
java.util.Map, .Set, java.util.concurrent.Future, jakarta.websocket.CloseReason, .SendHandler

Cluster related context.

There is exactly one instance per cluster node and all communication is realized using this instance.

Author
Pavel Bucek

Field Summary

Modifier and TypeField and Description
public static final String
CLUSTER_CONTEXT

ClusterContext registration property.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public abstract void
broadcastBinary(String
endpoint path identifying sessions alignment to the endpoint.
endpointPath
,
byte[]
data to be broadcasted.
data
)

Broadcast binary message.

public abstract void
broadcastText(String
endpoint path identifying sessions alignment to the endpoint.
endpointPath
,
String
message to be broadcasted.
text
)

Broadcast text message.

public abstract Future<Void>

Returns:

future representing the event. java.util.concurrent.Future#get() returns when there is an acknowledge from the other node that the command was successfully executed. If there is any exception, it will be wrapped into java.util.concurrent.ExecutionException and thrown.
close
(String
remote session id.
sessionId
)

Close remote session.

public abstract Future<Void>

Returns:

future representing the event. java.util.concurrent.Future#get() returns when there is an acknowledge from the other node that the command was successfully executed. If there is any exception, it will be wrapped into java.util.concurrent.ExecutionException and thrown.
close
(String
remote session id.
sessionId
,
CloseReason
custom close reason.
closeReason
)

Close remote session with custom jakarta.websocket.CloseReason.

public abstract String

Returns:

connection id.
createConnectionId
()

Create connection id. It has to be unique among all cluster nodes.

public abstract String

Returns:

session id.
createSessionId
()

Create session id. It has to be unique among all cluster nodes.

public abstract void
destroyDistributedUserProperties(String
connection id. Connection id may be shared among subsequent TCP connection - represents logical connection.
connectionId
)

Destroy map which holds distributed user properties.

public abstract Map<RemoteSession.DistributedMapKey, Object>

Returns:

distributed map containing session properties.
getDistributedSessionProperties
(String
remote session id.
sessionId
)

Get the map containing session properties to be shared among nodes.

public abstract Map<String, Object>

Returns:

distributed map containing session properties.
getDistributedUserProperties
(String
connection id. Connection id may be shared among subsequent TCP connection - represents logical connection.
connectionId
)

Get the map containing session user properties to be shared among nodes.

public abstract Set<String>

Returns:

set of sessions ids.
getRemoteSessionIds
(String
endpoint path identifying endpoint within the cluster.
endpointPath
)

Get set containing session ids of all remote sessions registered to given endpoint path.

public abstract boolean

Returns:

true when session is opened, false otherwise.
isSessionOpen
(String
remote session id.
sessionId
,
String
endpoint path identifying sessions alignment to the endpoint.
endpointPath
)

Get information about session state.

public abstract void
registerBroadcastListener(String
endpoint path identifying sessions alignment to the endpoint.
endpointPath
,
BroadcastListener
listener instance.
listener
)

Register broadcast listener.

public abstract void
registerSession(String
session id to be registered.
sessionId
,
String
endpoint path identifying sessions alignment to the endpoint.
endpointPath
,
SessionEventListener
session event listener. When remote node sends a message to this session, it will be invoked.
listener
)

Register local session.

public abstract void
registerSessionListener(String
endpoint path identifying sessions alignment to the endpoint.
endpointPath
,
SessionListener
listener instance.
listener
)

Register session listener.

public abstract void
removeSession(String
session id.
sessionId
,
String
endpoint path identifying sessions alignment to the endpoint.
endpointPath
)

Remove session from this Cluster context.

public abstract Future<Void>

Returns:

future representing the send event. java.util.concurrent.Future#get() returns when there is an acknowledge from the other node that the message has been successfully sent. If there is any exception, it will be wrapped into java.util.concurrent.ExecutionException and thrown.
sendBinary
(String
remote session id.
sessionId
,
byte[]
data to be sent.
data
)

Send binary message.

public abstract Future<Void>

Returns:

future representing the send event. java.util.concurrent.Future#get() returns when there is an acknowledge from the other node that the message has been successfully sent. If there is any exception, it will be wrapped into java.util.concurrent.ExecutionException and thrown.
sendBinary
(String
remote session id.
sessionId
,
byte[]
data to be sent.
data
,
boolean
true when the partial message being sent is the last part of the message.
isLast
)

Send partial binary message.

public abstract void
sendBinary(String
remote session id.
sessionId
,
byte[]
data to be sent.
data
,
SendHandler
sendhandler instance on which jakarta.websocket.SendHandler#onResult(jakarta.websocket.SendResult) will be invoked.
sendHandler
)

Send binary message with jakarta.websocket.SendHandler.

public abstract Future<Void>

Returns:

future representing the send event. java.util.concurrent.Future#get() returns when there is an acknowledge from the other node that the message has been successfully sent. If there is any exception, it will be wrapped into java.util.concurrent.ExecutionException and thrown.
sendPing
(String
remote session id.
sessionId
,
byte[]
data to be sent as ping message payload.
data
)

Send ping message.

public abstract Future<Void>

Returns:

future representing the send event. java.util.concurrent.Future#get() returns when there is an acknowledge from the other node that the message has been successfully sent. If there is any exception, it will be wrapped into java.util.concurrent.ExecutionException and thrown.
sendPong
(String
remote session id.
sessionId
,
byte[]
data to be sent as pong message payload.
data
)

Send pong message.

public abstract Future<Void>

Returns:

future representing the send event. java.util.concurrent.Future#get() returns when there is an acknowledge from the other node that the message has been successfully sent. If there is any exception, it will be wrapped into java.util.concurrent.ExecutionException and thrown.
sendText
(String
remote session id.
sessionId
,
String
text to be sent.
text
)

Send text message.

public abstract Future<Void>

Returns:

future representing the send event. java.util.concurrent.Future#get() returns when there is an acknowledge from the other node that the message has been successfully sent. If there is any exception, it will be wrapped into java.util.concurrent.ExecutionException and thrown.
sendText
(String
remote session id.
sessionId
,
String
text to be sent.
text
,
boolean
true when the partial message being sent is the last part of the message.
isLast
)

Send partial text message.

public abstract void
sendText(String
remote session id.
sessionId
,
String
text to be sent.
text
,
SendHandler
sendhandler instance on which jakarta.websocket.SendHandler#onResult(jakarta.websocket.SendResult) will be invoked.
sendHandler
)

Send text message with jakarta.websocket.SendHandler.

public abstract void
shutdown()

Shutdown this ClusterContext.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

CLUSTER_CONTEXTback to summary
public static final String CLUSTER_CONTEXT

ClusterContext registration property.

ClusterContext is registered to the Server container via properties passed to org.glassfish.tyrus.spi.ServerContainerFactory#createServerContainer(java.util.Map).

Constructor Detail

ClusterContextback to summary
public ClusterContext()

Method Detail

broadcastBinaryback to summary
public abstract void broadcastBinary(String endpointPath, byte[] data)

Broadcast binary message.

Parameters
endpointPath:String

endpoint path identifying sessions alignment to the endpoint.

data:byte[]

data to be broadcasted.

broadcastTextback to summary
public abstract void broadcastText(String endpointPath, String text)

Broadcast text message.

Parameters
endpointPath:String

endpoint path identifying sessions alignment to the endpoint.

text:String

message to be broadcasted.

closeback to summary
public abstract Future<Void> close(String sessionId)

Close remote session.

Parameters
sessionId:String

remote session id.

Returns:Future<Void>

future representing the event. java.util.concurrent.Future#get() returns when there is an acknowledge from the other node that the command was successfully executed. If there is any exception, it will be wrapped into java.util.concurrent.ExecutionException and thrown.

closeback to summary
public abstract Future<Void> close(String sessionId, CloseReason closeReason)

Close remote session with custom jakarta.websocket.CloseReason.

Parameters
sessionId:String

remote session id.

closeReason:CloseReason

custom close reason.

Returns:Future<Void>

future representing the event. java.util.concurrent.Future#get() returns when there is an acknowledge from the other node that the command was successfully executed. If there is any exception, it will be wrapped into java.util.concurrent.ExecutionException and thrown.

createConnectionIdback to summary
public abstract String createConnectionId()

Create connection id. It has to be unique among all cluster nodes.

Returns:String

connection id.

createSessionIdback to summary
public abstract String createSessionId()

Create session id. It has to be unique among all cluster nodes.

Returns:String

session id.

destroyDistributedUserPropertiesback to summary
public abstract void destroyDistributedUserProperties(String connectionId)

Destroy map which holds distributed user properties.

This method should be invoked only when session is properly closed.

Parameters
connectionId:String

connection id. Connection id may be shared among subsequent TCP connection - represents logical connection.

getDistributedSessionPropertiesback to summary
public abstract Map<RemoteSession.DistributedMapKey, Object> getDistributedSessionProperties(String sessionId)

Get the map containing session properties to be shared among nodes.

Changes must be propagated to remote instances.

Parameters
sessionId:String

remote session id.

Returns:Map<RemoteSession.DistributedMapKey, Object>

distributed map containing session properties.

getDistributedUserPropertiesback to summary
public abstract Map<String, Object> getDistributedUserProperties(String connectionId)

Get the map containing session user properties to be shared among nodes.

Changes must be propagated to remote instances.

Parameters
connectionId:String

connection id. Connection id may be shared among subsequent TCP connection - represents logical connection.

Returns:Map<String, Object>

distributed map containing session properties.

getRemoteSessionIdsback to summary
public abstract Set<String> getRemoteSessionIds(String endpointPath)

Get set containing session ids of all remote sessions registered to given endpoint path.

Parameters
endpointPath:String

endpoint path identifying endpoint within the cluster.

Returns:Set<String>

set of sessions ids.

isSessionOpenback to summary
public abstract boolean isSessionOpen(String sessionId, String endpointPath)

Get information about session state.

Parameters
sessionId:String

remote session id.

endpointPath:String

endpoint path identifying sessions alignment to the endpoint.

Returns:boolean

true when session is opened, false otherwise.

See Also
jakarta.websocket.Session#isOpen()
registerBroadcastListenerback to summary
public abstract void registerBroadcastListener(String endpointPath, BroadcastListener listener)

Register broadcast listener.

Gets notification about broadcasted messages. Used as an optimized variant of standard websocket broadcast pattern. In this case, only one message is sent to all cluster nodes (instead n when n represent number of clients connected to remote nodes).

Parameters
endpointPath:String

endpoint path identifying sessions alignment to the endpoint.

listener:BroadcastListener

listener instance.

See Also
org.glassfish.tyrus.core.cluster.BroadcastListener
registerSessionback to summary
public abstract void registerSession(String sessionId, String endpointPath, SessionEventListener listener)

Register local session.

Session id will be broadcasted to other nodes which will call getDistributedSessionProperties(String) and process its values. The map must be ready before this method is invoked.

Parameters
sessionId:String

session id to be registered.

endpointPath:String

endpoint path identifying sessions alignment to the endpoint.

listener:SessionEventListener

session event listener. When remote node sends a message to this session, it will be invoked.

See Also
org.glassfish.tyrus.core.cluster.SessionEventListener
registerSessionListenerback to summary
public abstract void registerSessionListener(String endpointPath, SessionListener listener)

Register session listener.

Gets notification about session creation .SessionListener#onSessionOpened(String) and destruction .SessionListener#onSessionClosed(String).

Parameters
endpointPath:String

endpoint path identifying sessions alignment to the endpoint.

listener:SessionListener

listener instance.

See Also
org.glassfish.tyrus.core.cluster.SessionListener
removeSessionback to summary
public abstract void removeSession(String sessionId, String endpointPath)

Remove session from this Cluster context.

Parameters
sessionId:String

session id.

endpointPath:String

endpoint path identifying sessions alignment to the endpoint.

sendBinaryback to summary
public abstract Future<Void> sendBinary(String sessionId, byte[] data)

Send binary message.

Parameters
sessionId:String

remote session id.

data:byte[]

data to be sent.

Returns:Future<Void>

future representing the send event. java.util.concurrent.Future#get() returns when there is an acknowledge from the other node that the message has been successfully sent. If there is any exception, it will be wrapped into java.util.concurrent.ExecutionException and thrown.

sendBinaryback to summary
public abstract Future<Void> sendBinary(String sessionId, byte[] data, boolean isLast)

Send partial binary message.

Parameters
sessionId:String

remote session id.

data:byte[]

data to be sent.

isLast:boolean

true when the partial message being sent is the last part of the message.

Returns:Future<Void>

future representing the send event. java.util.concurrent.Future#get() returns when there is an acknowledge from the other node that the message has been successfully sent. If there is any exception, it will be wrapped into java.util.concurrent.ExecutionException and thrown.

sendBinaryback to summary
public abstract void sendBinary(String sessionId, byte[] data, SendHandler sendHandler)

Send binary message with jakarta.websocket.SendHandler.

Parameters
sessionId:String

remote session id.

data:byte[]

data to be sent.

sendHandler:SendHandler

sendhandler instance on which jakarta.websocket.SendHandler#onResult(jakarta.websocket.SendResult) will be invoked.

See Also
jakarta.websocket.SendHandler
sendPingback to summary
public abstract Future<Void> sendPing(String sessionId, byte[] data)

Send ping message.

Parameters
sessionId:String

remote session id.

data:byte[]

data to be sent as ping message payload.

Returns:Future<Void>

future representing the send event. java.util.concurrent.Future#get() returns when there is an acknowledge from the other node that the message has been successfully sent. If there is any exception, it will be wrapped into java.util.concurrent.ExecutionException and thrown.

sendPongback to summary
public abstract Future<Void> sendPong(String sessionId, byte[] data)

Send pong message.

Parameters
sessionId:String

remote session id.

data:byte[]

data to be sent as pong message payload.

Returns:Future<Void>

future representing the send event. java.util.concurrent.Future#get() returns when there is an acknowledge from the other node that the message has been successfully sent. If there is any exception, it will be wrapped into java.util.concurrent.ExecutionException and thrown.

sendTextback to summary
public abstract Future<Void> sendText(String sessionId, String text)

Send text message.

Parameters
sessionId:String

remote session id.

text:String

text to be sent.

Returns:Future<Void>

future representing the send event. java.util.concurrent.Future#get() returns when there is an acknowledge from the other node that the message has been successfully sent. If there is any exception, it will be wrapped into java.util.concurrent.ExecutionException and thrown.

sendTextback to summary
public abstract Future<Void> sendText(String sessionId, String text, boolean isLast)

Send partial text message.

Parameters
sessionId:String

remote session id.

text:String

text to be sent.

isLast:boolean

true when the partial message being sent is the last part of the message.

Returns:Future<Void>

future representing the send event. java.util.concurrent.Future#get() returns when there is an acknowledge from the other node that the message has been successfully sent. If there is any exception, it will be wrapped into java.util.concurrent.ExecutionException and thrown.

sendTextback to summary
public abstract void sendText(String sessionId, String text, SendHandler sendHandler)

Send text message with jakarta.websocket.SendHandler.

Parameters
sessionId:String

remote session id.

text:String

text to be sent.

sendHandler:SendHandler

sendhandler instance on which jakarta.websocket.SendHandler#onResult(jakarta.websocket.SendResult) will be invoked.

See Also
jakarta.websocket.SendHandler
shutdownback to summary
public abstract void shutdown()

Shutdown this ClusterContext.

This will stop whole clustered node, any operation related to this cluster context will fail after this method is invoked.