- java.lang.Object
-
- org.omnifaces.cdi.push.SocketChannelManager
-
- All Implemented Interfaces:
Serializable
@SessionScoped public class SocketChannelManager extends Object implements 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:
Socket
, Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
SocketChannelManager.ViewScope
This helps the web socket channel manager to hold view scoped web socket channel identifiers registered by<o:socket>
.
-
Constructor Summary
Constructors Constructor Description SocketChannelManager()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
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.protected Map<String,String>
getSessionScopedChannels()
For internal usage only.protected Map<String,String>
getViewScopedChannels(boolean create)
For internal usage only.protected String
register(String channel, String scope, Serializable user)
Register given channel on given scope and returns the web socket channel identifier.protected void
switchUser(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.
-
-
-
Method Detail
-
register
protected String register(String channel, String scope, Serializable user)
Register given channel on given scope and returns the web socket channel identifier.- Parameters:
channel
- The web socket channel.scope
- The web socket scope. Supported values areapplication
,session
andview
, 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 web socket channel identifier. This can be used as web socket URI.
- Throws:
IllegalArgumentException
- When the scope is invalid or when channel already exists on a different scope.
-
switchUser
protected void switchUser(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.- Parameters:
channel
- The web socket channel.scope
- The web socket scope. Supported values areapplication
,session
andview
, 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
@PreDestroy protected void 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.
-
getSessionScopedChannels
protected Map<String,String> getSessionScopedChannels()
For internal usage only. This makes it possible to reference session scope channel IDs during injection time ofSocketPushContext
(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.
-
getViewScopedChannels
protected Map<String,String> getViewScopedChannels(boolean create)
For internal usage only. This makes it possible to reference view scope channel IDs during injection time ofSocketPushContext
(the Faces view 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.- Parameters:
create
- Whether or not to auto-create the entry in Faces view scope.- Returns:
- View scope channel IDs.
-
-