Top Description Fields Constructors Methods
com.sun.faces.push

public Class WebsocketSessionManager

extends Object
Class Inheritance
Annotations
@ApplicationScoped
Static Imports
com.sun.faces.cdi.CdiUtils.getBeanReference, com.sun.faces.push.WebsocketEndpoint.PARAM_CHANNEL, jakarta.websocket.CloseReason.CloseCodes.NORMAL_CLOSURE, java.lang.String.format, java.util.Collections.emptySet, java.util.logging.Level.WARNING

This web socket session manager holds all web socket sessions by their channel identifier.

Author
Bauke Scholtz
Since
2.3
See Also
Push

Field Summary

Modifier and TypeField and Description
private static final String
private static volatile WebsocketSessionManager
private static final Logger
private static final CloseReason
private static final AnnotationLiteral<WebsocketEvent.Closed>
private static final AnnotationLiteral<WebsocketEvent.Opened>
private final ConcurrentMap<String, Collection<Session>>
private WebsocketUserManager
private static final long
private static final long
private static final String

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected boolean

Returns:

true if given web socket session is accepted and is new, otherwise false.
add
(Session
The opened web socket session.
session
)

On open, add given web socket session to the mapping associated with its channel identifier and returns true if it's accepted (i.e. the channel identifier is known) and the same session hasn't been added before, otherwise false.

protected void
deregister(Iterable<String>
The channel identifiers to deregister.
channelIds
)

Deregister given channel identifiers and explicitly close all open web socket sessions associated with it.

private static void
fireEvent(Session session, CloseReason reason, AnnotationLiteral<?> qualifier)

private static String
private static String
pack-priv static WebsocketSessionManager
getInstance()

Internal usage only.

protected void
register(String
The channel identifier to register.
channelId
)

Register given channel identifier.

protected void
register(Iterable<String>
The channel identifiers to register.
channelIds
)

Register given channel identifiers.

protected void
remove(Session
The closed web socket session.
session
,
CloseReason
The close reason.
reason
)

On close, remove given web socket session from the mapping.

private Void
protected Set<Future<Void>>

Returns:

The results of the send operation. If it returns an empty set, then there was no open session associated with given channel identifier. The returned futures will return null on Future#get() if the message was successfully delivered and otherwise throw ExecutionException.
send
(String
The web socket channel identifier.
channelId
,
String
The push message string.
message
)

Encode the given message object as JSON and send it to all open web socket sessions associated with given web socket channel identifier.

private Future<Void>
send(Session session, String text, boolean retrySendTomcatWebSocket)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ERROR_TOMCAT_WEB_SOCKET_BOMBEDback to summary
private static final String ERROR_TOMCAT_WEB_SOCKET_BOMBED
instanceback to summary
private static volatile WebsocketSessionManager instance
loggerback to summary
private static final Logger logger
REASON_EXPIREDback to summary
private static final CloseReason REASON_EXPIRED
SESSION_CLOSEDback to summary
private static final AnnotationLiteral<WebsocketEvent.Closed> SESSION_CLOSED
SESSION_OPENEDback to summary
private static final AnnotationLiteral<WebsocketEvent.Opened> SESSION_OPENED
socketSessionsback to summary
private final ConcurrentMap<String, Collection<Session>> socketSessions
socketUsersback to summary
private WebsocketUserManager socketUsers
Annotations
@Inject
TOMCAT_WEB_SOCKET_MAX_RETRIESback to summary
private static final long TOMCAT_WEB_SOCKET_MAX_RETRIES
TOMCAT_WEB_SOCKET_RETRY_TIMEOUTback to summary
private static final long TOMCAT_WEB_SOCKET_RETRY_TIMEOUT
WARNING_TOMCAT_WEB_SOCKET_BOMBEDback to summary
private static final String WARNING_TOMCAT_WEB_SOCKET_BOMBED

Constructor Detail

WebsocketSessionManagerback to summary
public WebsocketSessionManager()

Method Detail

addback to summary
protected boolean add(Session session)

On open, add given web socket session to the mapping associated with its channel identifier and returns true if it's accepted (i.e. the channel identifier is known) and the same session hasn't been added before, otherwise false.

Parameters
session:Session

The opened web socket session.

Returns:boolean

true if given web socket session is accepted and is new, otherwise false.

deregisterback to summary
protected void deregister(Iterable<String> channelIds)

Deregister given channel identifiers and explicitly close all open web socket sessions associated with it.

Parameters
channelIds:Iterable<String>

The channel identifiers to deregister.

fireEventback to summary
private static void fireEvent(Session session, CloseReason reason, AnnotationLiteral<?> qualifier)
getChannelback to summary
private static String getChannel(Session session)
getChannelIdback to summary
private static String getChannelId(Session session)
getInstanceback to summary
pack-priv static WebsocketSessionManager getInstance()

Internal usage only. Awkward workaround for it being unavailable via @Inject in endpoint in Tomcat+Weld/OWB.

registerback to summary
protected void register(String channelId)

Register given channel identifier.

Parameters
channelId:String

The channel identifier to register.

registerback to summary
protected void register(Iterable<String> channelIds)

Register given channel identifiers.

Parameters
channelIds:Iterable<String>

The channel identifiers to register.

removeback to summary
protected void remove(Session session, CloseReason reason)

On close, remove given web socket session from the mapping.

Parameters
session:Session

The closed web socket session.

reason:CloseReason

The close reason.

retrySendTomcatWebSocketback to summary
private Void retrySendTomcatWebSocket(Session session, String text)
sendback to summary
protected Set<Future<Void>> send(String channelId, String message)

Encode the given message object as JSON and send it to all open web socket sessions associated with given web socket channel identifier.

Parameters
channelId:String

The web socket channel identifier.

message:String

The push message string.

Returns:Set<Future<Void>>

The results of the send operation. If it returns an empty set, then there was no open session associated with given channel identifier. The returned futures will return null on Future#get() if the message was successfully delivered and otherwise throw ExecutionException.

sendback to summary
private Future<Void> send(Session session, String text, boolean retrySendTomcatWebSocket)