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 Link icon

    • ExternalSessionManager Link icon

      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 Link icon

    • getSessionTimeoutMillis Link icon

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

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

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

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

      public com.blueriq.component.api.IAquimaSession getSession(String aquimaSessionId)
      Specified by:
      getSession in interface com.blueriq.component.api.IAquimaSessionsMap
    • getSession Link icon

      public com.blueriq.component.api.IAquimaSession getSession(String aquimaSessionId, com.blueriq.component.api.FlushMode flushMode)
      Specified by:
      getSession in interface com.blueriq.component.api.IAquimaSessionsMap
    • updateSession Link icon

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

      public void closeSession(String aquimaSessionId)
      Specified by:
      closeSession in interface com.blueriq.component.api.IAquimaSessionsMap
    • cleanIdleSessions Link icon

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

      public void keepAlive(String aquimaSessionId)
      Specified by:
      keepAlive in interface com.blueriq.component.api.IAquimaSessionsMap
    • getAvailableSessionIds Link icon

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

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

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

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

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

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

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

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

      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 Link icon

      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