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, java.util.Collections.emptySet, javax.websocket.CloseReason.CloseCodes.NORMAL_CLOSURE

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 volatile WebsocketSessionManager
private static final CloseReason
private static final AnnotationLiteral<WebsocketEvent.Closed>
private static final AnnotationLiteral<WebsocketEvent.Opened>
private final ConcurrentMap<String, Collection<Session>>
private WebsocketUserManager

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.

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
,
Object
The push message object.
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 void
send(Session session, String text, Set<Future<Void>> results)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

instanceback to summary
private static volatile WebsocketSessionManager instance
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

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.

sendback to summary
protected Set<Future<Void>> send(String channelId, Object 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:Object

The push message object.

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 void send(Session session, String text, Set<Future<Void>> results)