Class SessionListener

java.lang.Object
com.vaadin.kubernetes.starter.sessiontracker.SessionListener
All Implemented Interfaces:
jakarta.servlet.http.HttpSessionAttributeListener, jakarta.servlet.http.HttpSessionIdListener, jakarta.servlet.http.HttpSessionListener, EventListener

public class SessionListener extends Object implements jakarta.servlet.http.HttpSessionListener, jakarta.servlet.http.HttpSessionIdListener, jakarta.servlet.http.HttpSessionAttributeListener
An HttpSessionListener implementation that handles population and destruction of session data stored on a distributed storage.

In presence of a tracking Cookie set by SessionTrackerFilter, on session creation, the distributed storage is queried for persisted attributes that are then used to populate the newly created HttpSession.

Data is fetched in binary format from the distributed storage by a BackendConnector and then deserialized and copied into HTTP session by SessionSerializer.

When HTTP session is destroyed, also relative data on distribute storage is deleted by the backend connector.

See Also:
  • Constructor Details

    • SessionListener

      public SessionListener(BackendConnector sessionBackendConnector, SessionSerializer sessionSerializer)
      Creates a new SessionListener instance.
      Parameters:
      sessionBackendConnector - backend connector to fetch and delete session data from distributed storage.
      sessionSerializer - component to perform deserialization of data from distributed storage.
  • Method Details

    • sessionCreated

      public void sessionCreated(jakarta.servlet.http.HttpSessionEvent se)
      Specified by:
      sessionCreated in interface jakarta.servlet.http.HttpSessionListener
    • sessionDestroyed

      public void sessionDestroyed(jakarta.servlet.http.HttpSessionEvent se)
      Specified by:
      sessionDestroyed in interface jakarta.servlet.http.HttpSessionListener
    • sessionIdChanged

      public void sessionIdChanged(jakarta.servlet.http.HttpSessionEvent event, String oldSessionId)
      Specified by:
      sessionIdChanged in interface jakarta.servlet.http.HttpSessionIdListener
    • attributeAdded

      public void attributeAdded(jakarta.servlet.http.HttpSessionBindingEvent event)
      Specified by:
      attributeAdded in interface jakarta.servlet.http.HttpSessionAttributeListener
    • attributeReplaced

      public void attributeReplaced(jakarta.servlet.http.HttpSessionBindingEvent event)
      Specified by:
      attributeReplaced in interface jakarta.servlet.http.HttpSessionAttributeListener
    • activeSessionChecker

      public Predicate<String> activeSessionChecker()
      Gets a predicate that tests if the given identifier matches an active HTTP session.
      Returns:
      a predicate to check if an HTTP session is active or not.
    • stop

      public void stop()
      Stops this session listener to skip any further HttpSessionEvent handling.