Class WebsocketSessionManager

java.lang.Object
com.sun.faces.push.WebsocketSessionManager

@ApplicationScoped public class WebsocketSessionManager extends Object

This web socket session manager holds all web socket sessions by their channel identifier.

Since:
2.3
Author:
Bauke Scholtz
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected boolean
    add(jakarta.websocket.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.
    protected void
    deregister(Iterable<String> channelIds)
    Deregister given channel identifiers and explicitly close all open web socket sessions associated with it.
    protected void
    register(Iterable<String> channelIds)
    Register given channel identifiers.
    protected void
    register(String channelId)
    Register given channel identifier.
    protected void
    remove(jakarta.websocket.Session session, jakarta.websocket.CloseReason reason)
    On close, remove given web socket session from the mapping.
    protected Set<Future<Void>>
    send(String channelId, String message)
    Encode the given message object as JSON and send it to all open web socket sessions associated with given web socket channel identifier.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • WebsocketSessionManager

      public WebsocketSessionManager()
  • Method Details

    • 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.
    • add

      protected boolean add(jakarta.websocket.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 - The opened web socket session.
      Returns:
      true if given web socket session is accepted and is new, otherwise false.
    • send

      protected Set<Future<Void>> send(String channelId, String 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 - The web socket 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.
    • remove

      protected void remove(jakarta.websocket.Session session, jakarta.websocket.CloseReason reason)
      On close, remove given web socket session from the mapping.
      Parameters:
      session - The closed web socket session.
      reason - The close reason.
    • deregister

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