Class ExternalSessionManager
- All Implemented Interfaces:
IExternalSessionManager
,com.blueriq.component.api.IAquimaSessionsMap
,org.springframework.beans.factory.DisposableBean
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 Summary
ConstructorsConstructorDescriptionExternalSessionManager
(NamespacedKeyValueStore keyValueStore, com.blueriq.component.api.IAquimaEngineFacade aquimaEngine, Duration timeout, ConcurrentSessionModificationMonitor monitor, String monitorNamespace) Creates a new instance. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addChildSession
(String parentSessionId, com.blueriq.component.api.IAquimaSession session) void
addSession
(com.blueriq.component.api.IAquimaSession aquimaSession) void
void
closeSession
(String aquimaSessionId) void
destroy()
void
flush()
protected void
flush
(com.blueriq.component.api.IAquimaSession session) List
<com.blueriq.component.api.IAquimaSession> getChildSessions
(String sessionId) List
<com.blueriq.component.api.IAquimaSession> getChildSessions
(String sessionId, String pageName) com.blueriq.component.api.IAquimaSession
getRootSession
(String currentSessionId) com.blueriq.component.api.IAquimaSession
getSession
(String aquimaSessionId) com.blueriq.component.api.IAquimaSession
getSession
(String aquimaSessionId, com.blueriq.component.api.FlushMode flushMode) long
boolean
hasSession
(String aquimaSessionId) void
keyFor
(com.blueriq.component.api.IAquimaSession session) Returns the key where the provided session would be stored in the underlying key-value store.Returns the key where a session with the provided session id would be stored in the underlying key-value store.void
updateSession
(com.blueriq.component.api.IAquimaSession aquimaSession)
-
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 sessionsaquimaEngine
- the AquimaEngine instance used to activate/passivate sessionstimeout
- the session timeoutmonitor
- the monitor used for detecting concurrent session modificationsmonitorNamespace
- the namespace used for registering monitored sessions with the monitor
-
-
Method Details
-
getSessionTimeoutMillis
public long getSessionTimeoutMillis()- Specified by:
getSessionTimeoutMillis
in interfacecom.blueriq.component.api.IAquimaSessionsMap
-
addSession
public void addSession(com.blueriq.component.api.IAquimaSession aquimaSession) - Specified by:
addSession
in interfacecom.blueriq.component.api.IAquimaSessionsMap
-
addChildSession
public void addChildSession(String parentSessionId, com.blueriq.component.api.IAquimaSession session) - Specified by:
addChildSession
in interfacecom.blueriq.component.api.IAquimaSessionsMap
-
hasSession
- Specified by:
hasSession
in interfacecom.blueriq.component.api.IAquimaSessionsMap
-
getSession
- Specified by:
getSession
in interfacecom.blueriq.component.api.IAquimaSessionsMap
-
getSession
public com.blueriq.component.api.IAquimaSession getSession(String aquimaSessionId, com.blueriq.component.api.FlushMode flushMode) - Specified by:
getSession
in interfacecom.blueriq.component.api.IAquimaSessionsMap
-
updateSession
public void updateSession(com.blueriq.component.api.IAquimaSession aquimaSession) - Specified by:
updateSession
in interfacecom.blueriq.component.api.IAquimaSessionsMap
-
closeSession
- Specified by:
closeSession
in interfacecom.blueriq.component.api.IAquimaSessionsMap
-
cleanIdleSessions
public void cleanIdleSessions()- Specified by:
cleanIdleSessions
in interfacecom.blueriq.component.api.IAquimaSessionsMap
-
keepAlive
- Specified by:
keepAlive
in interfacecom.blueriq.component.api.IAquimaSessionsMap
-
getAvailableSessionIds
- Specified by:
getAvailableSessionIds
in interfacecom.blueriq.component.api.IAquimaSessionsMap
-
getMainSessionIds
- Specified by:
getMainSessionIds
in interfacecom.blueriq.component.api.IAquimaSessionsMap
-
getChildSessions
- Specified by:
getChildSessions
in interfacecom.blueriq.component.api.IAquimaSessionsMap
-
getChildSessions
public List<com.blueriq.component.api.IAquimaSession> getChildSessions(String sessionId, String pageName) - Specified by:
getChildSessions
in interfacecom.blueriq.component.api.IAquimaSessionsMap
-
getRootSession
- Specified by:
getRootSession
in interfacecom.blueriq.component.api.IAquimaSessionsMap
-
flush
public void flush()- Specified by:
flush
in interfacecom.blueriq.component.api.IAquimaSessionsMap
-
flush
protected void flush(com.blueriq.component.api.IAquimaSession session) -
destroy
- Specified by:
destroy
in interfaceorg.springframework.beans.factory.DisposableBean
- Throws:
Exception
-
keyFor
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 interfaceIExternalSessionManager
- Parameters:
sessionId
- the id of a session, must not be null- Returns:
- the corresponding key in the key-value store
-
keyFor
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 interfaceIExternalSessionManager
- Parameters:
session
- the session, must not be null- Returns:
- the corresponding key in the key-value store
-