java.lang.Object
org.omnifaces.cdi.push.SocketChannelManager
- All Implemented Interfaces:
Serializable
This web socket channel manager holds all application and session scoped web socket channel identifiers registered by
<o:socket>.
- Since:
- 2.3
- Author:
- Bauke Scholtz
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classThis helps the web socket channel manager to hold view scoped web socket channel identifiers registered by<o:socket>. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidWhen current session scope is about to be destroyed, deregister all session scope channels and explicitly close any open web sockets associated with it to avoid stale websockets.protected voidDeserialize the push channel state after session restore or failover.protected ConcurrentHashMap<String, String> Returns the application scoped channels for this push transport.protected static StringgetChannelId(String channel, ConcurrentHashMap<String, String> applicationScope, Map<String, String> sessionScope, Map<String, String> viewScope) For internal usage only.protected org.omnifaces.cdi.push.PushSessionManager<?> Returns the push session manager for this push transport.protected org.omnifaces.cdi.push.PushUserManagerReturns the push user manager for this push transport.For internal usage only.protected ConcurrentHashMap<Serializable, String> For internal usage only.getViewScopedChannels(boolean create) Returns the view scoped channels for this push transport.protected Stringregister(String channel, String scope, Serializable user) Register given channel on given scope and return the channel identifier.protected voidserializeState(ObjectOutputStream output) Serialize the push channel state for session persistence or failover.protected voidswitchUser(String channel, String scope, Serializable oldUser, Serializable newUser) Switch the user on the given channel on the given scope from the given old user to the given new user.
-
Constructor Details
-
SocketChannelManager
public SocketChannelManager()
-
-
Method Details
-
switchUser
Switch the user on the given channel on the given scope from the given old user to the given new user.- Parameters:
channel- The web socket channel.scope- The web socket scope. Supported values areapplication,sessionandview, case insensitive. Ifnull, the default isapplication.oldUser- The user object representing the old owner of the given channel. If notnull, then scope may not beapplication.newUser- The user object representing the new owner of the given channel. If notnull, then scope may not beapplication.
-
deregisterSessionScope
When current session scope is about to be destroyed, deregister all session scope channels and explicitly close any open web sockets associated with it to avoid stale websockets. If any, also deregister session users. -
getApplicationScope
Returns the application scoped channels for this push transport.- Returns:
- The application scoped channels.
-
getPushSessions
protected org.omnifaces.cdi.push.PushSessionManager<?> getPushSessions()Returns the push session manager for this push transport.- Returns:
- The push session manager.
-
getPushUsers
protected org.omnifaces.cdi.push.PushUserManager getPushUsers()Returns the push user manager for this push transport.- Returns:
- The push user manager.
-
getViewScopedChannels
Returns the view scoped channels for this push transport.- Parameters:
create- Whether or not to auto-create the entry in Faces view scope.- Returns:
- View scope channel IDs.
-
register
Register given channel on given scope and return the channel identifier.- Parameters:
channel- The push channel.scope- The push scope. Supported values areapplication,sessionandview, case insensitive. Ifnull, the default isapplication.user- The user object representing the owner of the given channel. If notnull, then scope may not beapplication.- Returns:
- The push channel identifier.
- Throws:
IllegalArgumentException- When the scope is invalid or when channel already exists on a different scope.
-
getSessionScopedChannels
For internal usage only. This makes it possible to reference session scope channel IDs during injection time of push context implementations (the CDI session scope is not necessarily active during push send time). This should actually be package private, but package private methods in CDI beans are subject to memory leaks.- Returns:
- Session scope channel IDs.
-
getSessionUsers
For internal usage only. Returns the session user mappings. This should actually be package private, but package private methods in CDI beans are subject to memory leaks.- Returns:
- Session user mappings.
-
getChannelId
protected static String getChannelId(String channel, ConcurrentHashMap<String, String> applicationScope, Map<String, String> sessionScope, Map<String, String> viewScope) For internal usage only. This makes it possible to resolve the session and view scoped channel ID during push send time in push context implementations.- Parameters:
channel- The channel name.applicationScope- The application scope channel IDs.sessionScope- The session scope channel IDs.viewScope- The view scope channel IDs.- Returns:
- The channel ID, or
nullif not found.
-
serializeState
Serialize the push channel state for session persistence or failover.- Parameters:
output- The object output stream.- Throws:
IOException- When an I/O error occurs.
-
deserializeState
Deserialize the push channel state after session restore or failover.- Parameters:
input- The object input stream.- Throws:
IOException- When an I/O error occurs.ClassNotFoundException- When a serialized class is not found.
-