Class ExternalSessionManager

java.lang.Object
com.aquima.web.sessionmanager.ExternalSessionManager
All Implemented Interfaces:
IExternalSessionManager, com.blueriq.component.api.IAquimaSessionsMap, org.springframework.beans.factory.DisposableBean

public class ExternalSessionManager extends Object implements IExternalSessionManager, org.springframework.beans.factory.DisposableBean
An IAquimaSessionsMap implementation that stores IAquimaSession instances in an external IKeyValueStore.

In order to improve read performance and avoid multiple reads from the key-value store for the same session, this implementation uses an internal cache. All reads with getSession(String) are cached. All creation and update operations are buffered in the internal cache as well. Removal of sessions is immediately propagated to the key-value store and to the internal cache.

The internal cache may be flushed using the flush() method, which causes all sessions in the internal cache to be written to the key-value store and the internal cache to be cleared.

This implementation is best suited for use as a request-scoped component. It implements DisposableBean and flushes the cache when it is disposed.

WARNING: this implementation is not thread-safe! Since it is designed to be used as a request-scoped bean, it doesn't need to be thread-safe. This implementation should never be used as anything other than a request-scoped bean.

NOTE: this implementation does not support child sessions. The addChildSession(String, IAquimaSession) method always throws an UnsupportedOperationException, while getChildSessions(String) and getChildSessions(String, String) always return an empty list.

Since:
11.0
Author:
Petru Galanton
  • Constructor Details

    • ExternalSessionManager

      public ExternalSessionManager(NamespacedKeyValueStore keyValueStore, com.blueriq.component.api.IAquimaEngineFacade aquimaEngine, Duration timeout, ConcurrentSessionModificationMonitor monitor, String monitorNamespace)
      Creates a new instance.
      Parameters:
      keyValueStore - the key-value store used for storing sessions
      aquimaEngine - the AquimaEngine instance used to activate/passivate sessions
      timeout - the session timeout
      monitor - the monitor used for detecting concurrent session modifications
      monitorNamespace - the namespace used for registering monitored sessions with the monitor
  • Method Details

    • getSessionTimeoutMillis

      public long getSessionTimeoutMillis()
      Specified by:
      getSessionTimeoutMillis in interface com.blueriq.component.api.IAquimaSessionsMap
    • addSession

      public void addSession(com.blueriq.component.api.IAquimaSession aquimaSession)
      Specified by:
      addSession in interface com.blueriq.component.api.IAquimaSessionsMap
    • addChildSession

      public void addChildSession(String parentSessionId, com.blueriq.component.api.IAquimaSession session)
      Specified by:
      addChildSession in interface com.blueriq.component.api.IAquimaSessionsMap
    • hasSession

      public boolean hasSession(String aquimaSessionId)
      Specified by:
      hasSession in interface com.blueriq.component.api.IAquimaSessionsMap
    • getSession

      public com.blueriq.component.api.IAquimaSession getSession(String aquimaSessionId) throws com.blueriq.component.api.exception.UnknownSessionException
      Specified by:
      getSession in interface com.blueriq.component.api.IAquimaSessionsMap
      Throws:
      com.blueriq.component.api.exception.UnknownSessionException
    • getSession

      public com.blueriq.component.api.IAquimaSession getSession(String aquimaSessionId, com.blueriq.component.api.FlushMode flushMode) throws com.blueriq.component.api.exception.UnknownSessionException
      Specified by:
      getSession in interface com.blueriq.component.api.IAquimaSessionsMap
      Throws:
      com.blueriq.component.api.exception.UnknownSessionException
    • updateSession

      public void updateSession(com.blueriq.component.api.IAquimaSession aquimaSession)
      Specified by:
      updateSession in interface com.blueriq.component.api.IAquimaSessionsMap
    • closeSession

      public void closeSession(String aquimaSessionId) throws com.blueriq.component.api.exception.UnknownSessionException
      Specified by:
      closeSession in interface com.blueriq.component.api.IAquimaSessionsMap
      Throws:
      com.blueriq.component.api.exception.UnknownSessionException
    • cleanIdleSessions

      public void cleanIdleSessions()
      Specified by:
      cleanIdleSessions in interface com.blueriq.component.api.IAquimaSessionsMap
    • keepAlive

      public void keepAlive(String aquimaSessionId) throws com.blueriq.component.api.exception.UnknownSessionException
      Specified by:
      keepAlive in interface com.blueriq.component.api.IAquimaSessionsMap
      Throws:
      com.blueriq.component.api.exception.UnknownSessionException
    • getAvailableSessionIds

      public List<String> getAvailableSessionIds()
      Specified by:
      getAvailableSessionIds in interface com.blueriq.component.api.IAquimaSessionsMap
    • getMainSessionIds

      public List<String> getMainSessionIds()
      Specified by:
      getMainSessionIds in interface com.blueriq.component.api.IAquimaSessionsMap
    • getChildSessions

      public List<com.blueriq.component.api.IAquimaSession> getChildSessions(String sessionId)
      Specified by:
      getChildSessions in interface com.blueriq.component.api.IAquimaSessionsMap
    • getChildSessions

      public List<com.blueriq.component.api.IAquimaSession> getChildSessions(String sessionId, String pageName)
      Specified by:
      getChildSessions in interface com.blueriq.component.api.IAquimaSessionsMap
    • getRootSession

      public com.blueriq.component.api.IAquimaSession getRootSession(String currentSessionId)
      Specified by:
      getRootSession in interface com.blueriq.component.api.IAquimaSessionsMap
    • flush

      public void flush()
      Specified by:
      flush in interface com.blueriq.component.api.IAquimaSessionsMap
    • flush

      protected void flush(com.blueriq.component.api.IAquimaSession session)
    • destroy

      public void destroy() throws Exception
      Specified by:
      destroy in interface org.springframework.beans.factory.DisposableBean
      Throws:
      Exception
    • keyFor

      public String keyFor(String sessionId)
      Description copied from interface: IExternalSessionManager
      Returns the key where a session with the provided session id would be stored in the underlying key-value store.
      Specified by:
      keyFor in interface IExternalSessionManager
      Parameters:
      sessionId - the id of a session, must not be null
      Returns:
      the corresponding key in the key-value store
    • keyFor

      public String keyFor(com.blueriq.component.api.IAquimaSession session)
      Description copied from interface: IExternalSessionManager
      Returns the key where the provided session would be stored in the underlying key-value store.
      Specified by:
      keyFor in interface IExternalSessionManager
      Parameters:
      session - the session, must not be null
      Returns:
      the corresponding key in the key-value store