Class SseChannelManager

java.lang.Object
org.omnifaces.cdi.push.SseChannelManager
All Implemented Interfaces:
Serializable

@SessionScoped public class SseChannelManager extends Object

This SSE channel manager holds all application and session scoped SSE channel identifiers registered by <o:sse>.

Since:
5.2
Author:
Bauke Scholtz
See Also:
  • Constructor Details

    • SseChannelManager

      public SseChannelManager()
  • Method Details

    • 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 SSE channel.
      scope - The SSE scope. Supported values are application, session and view, case insensitive. If null, the default is application.
      oldUser - The user object representing the old owner of the given channel. If not null, then scope may not be application.
      newUser - The user object representing the new owner of the given channel. If not null, then scope may not be application.
    • deregisterSessionScope

      @PreDestroy protected void deregisterSessionScope()
      When current session scope is about to be destroyed, deregister all session scope channels and explicitly close any open SSE connections associated with it to avoid stale connections. If any, also deregister session users.
    • getApplicationScope

      protected ConcurrentHashMap<String,String> 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

      protected Map<String,String> getViewScopedChannels(boolean create)
      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

      protected String register(String channel, String scope, Serializable user)
      Register given channel on given scope and return the channel identifier.
      Parameters:
      channel - The push channel.
      scope - The push scope. Supported values are application, session and view, case insensitive. If null, the default is application.
      user - The user object representing the owner of the given channel. If not null, then scope may not be application.
      Returns:
      The push channel identifier.
      Throws:
      IllegalArgumentException - When the scope is invalid or when channel already exists on a different scope.
    • getSessionScopedChannels

      protected Map<String,String> 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

      protected ConcurrentHashMap<Serializable,String> 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 null if not found.
    • serializeState

      protected void serializeState(ObjectOutputStream output) throws IOException
      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

      protected void deserializeState(ObjectInputStream input) throws IOException, ClassNotFoundException
      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.