Class SseSessionManager

java.lang.Object
org.omnifaces.cdi.push.SseSessionManager

@ApplicationScoped public class SseSessionManager extends Object

This SSE session manager holds all SSE connections by their channel identifier.

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

    • SseSessionManager

      public SseSessionManager()
  • Method Details

    • add

      protected boolean add(String channelId, String channel, AsyncContext asyncContext)
      On open, add given async context to the mapping associated with given channel identifier and return true if it's accepted (i.e. the channel identifier is known), otherwise false.
      Parameters:
      channelId - The channel identifier.
      channel - The channel name.
      asyncContext - The opened async context.
      Returns:
      true if given async context is accepted, otherwise false.
    • remove

      protected void remove(String channelId, AsyncContext asyncContext)
      Remove given async context from the mapping associated with given channel identifier.
      Parameters:
      channelId - The channel identifier.
      asyncContext - The async context to remove.
    • sendToSession

      protected Future<Void> sendToSession(AsyncContext asyncContext, String message)
      Send the given message to the given session.
      Parameters:
      asyncContext - The transport session.
      message - The push message string.
      Returns:
      The result of the send operation, or null if the session is no longer usable.
    • closeSession

      protected void closeSession(AsyncContext asyncContext)
      Close the given session.
      Parameters:
      asyncContext - The transport session to close.
    • register

      protected void register(String channelId)
      Register given channel identifier.
      Parameters:
      channelId - The channel identifier to register.
    • register

      protected void register(Iterable<String> channelIds)
      Register given channel identifiers.
      Parameters:
      channelIds - The channel identifiers to register.
    • send

      protected Set<Future<Void>> send(String channelId, String message)
      Send the given message to all open sessions associated with given channel identifier.
      Parameters:
      channelId - The channel identifier.
      message - The push message string.
      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.
    • deregister

      protected void deregister(Iterable<String> channelIds)
      Deregister given channel identifiers and explicitly close all open sessions associated with them.
      Parameters:
      channelIds - The channel identifiers to deregister.
    • isOpen

      protected boolean isOpen(AsyncContext session)
      Returns whether the given session is still open.
      Parameters:
      session - The transport session.
      Returns:
      true if the session is open.
    • isRegistered

      protected boolean isRegistered(String channelId)
      Returns whether the given channel identifier is registered.
      Parameters:
      channelId - The channel identifier.
      Returns:
      true if the channel identifier is registered, otherwise false.
    • addSession

      protected boolean addSession(String channelId, AsyncContext session)
      Add a session to the collection associated with the given channel identifier.
      Parameters:
      channelId - The channel identifier.
      session - The transport session to add.
      Returns:
      true if the channel identifier is known and the session was added, otherwise false.
    • removeSession

      protected boolean removeSession(String channelId, AsyncContext session)
      Remove a session from the collection associated with the given channel identifier.
      Parameters:
      channelId - The channel identifier.
      session - The transport session to remove.
      Returns:
      true if the session was present and removed, otherwise false.