Package org.eclipse.scout.testing.client
Class ClientSessionProviderWithCache
java.lang.Object
org.eclipse.scout.rt.client.session.ClientSessionProvider
org.eclipse.scout.testing.client.ClientSessionProviderWithCache
Central point to obtain cached client sessions.
If a session is found in cache, this session is returned, or else a new session created via
ClientSessionProvider
.
A session is identified by its sessionId, or if not specified its userId.
- Since:
- 5.1
-
Field Summary
Modifier and TypeFieldDescriptionstatic final ThreadLocal<ToIntFunction<IMessageBox>>
A thread local that stores an (optional) strategy how to handle message boxes in unit tests. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
afterStartSession
(IClientSession clientSession) protected void
beforeStartSession
(IClientSession clientSession, String sessionId) protected org.eclipse.scout.rt.platform.util.collection.ConcurrentExpiringMap<org.eclipse.scout.rt.platform.util.CompositeObject,
IClientSession> createSessionCache
(long ttl) protected void
handleMessageBox
(IMessageBox messageBox) Closes the message box with value determined by theMESSAGE_BOX_HANDLER_STRATEGY
, or as a default withIMessageBox.CANCEL_OPTION
.protected org.eclipse.scout.rt.platform.util.CompositeObject
newSessionCacheKey
(String sessionId, Subject subject) protected void
prepareSessionCreatingClientRunContext
(ClientRunContext clientRunContext) Hook method for adapting theClientRunContext
that is used for creating the newIClientSession
instance.<SESSION extends IClientSession>
SESSIONprovide
(String sessionId, ClientRunContext clientRunContext) Returns the cached client session for the given sessionId, or the context'sSubject
if sessionId is not specified.<SESSION extends IClientSession>
SESSIONprovide
(ClientRunContext clientRunContext) Returns the cached client session for the context'sSubject
.protected void
registerSessionForNotifications
(IClientSession session, String sessionId) protected void
stopSession
(IClientSession session) Methods inherited from class org.eclipse.scout.rt.client.session.ClientSessionProvider
currentSession, currentSession
-
Field Details
-
MESSAGE_BOX_HANDLER_STRATEGY
A thread local that stores an (optional) strategy how to handle message boxes in unit tests.When running a unit test,
handleMessageBox(IMessageBox)
closes all message boxes by default with theIMessageBox.CANCEL_OPTION
. If this is insufficient, this thread local provides the means to return another value.For convenient ways how to use this, see the
BlockingTestUtility
.- Since:
- 8.0.0
-
-
Constructor Details
-
ClientSessionProviderWithCache
public ClientSessionProviderWithCache()
-
-
Method Details
-
provide
Returns the cached client session for the context'sSubject
. On cache miss, a new session with a random sessionId is created viaClientSessionProvider
.- Overrides:
provide
in classClientSessionProvider
- Parameters:
clientRunContext
- applied during session start, and to get the session'sSubject
.- Returns:
- session found in cache, or a new session on cache miss.
- Throws:
RuntimeException
- if session creation failed.
-
provide
public <SESSION extends IClientSession> SESSION provide(String sessionId, ClientRunContext clientRunContext) Returns the cached client session for the given sessionId, or the context'sSubject
if sessionId is not specified. On cache miss, a new session is created viaClientSessionProvider
.- Overrides:
provide
in classClientSessionProvider
- Parameters:
sessionId
- unique session ID to identify the cached session. Ifnull
, the context'sSubject
is used for identification. On cache miss, this sessionId is used to create a new session, or a random UUID ifnull
.clientRunContext
- applied during session start, and to get the session'sSubject
.- Returns:
- session found in cache, or a new session on cache miss.
- Throws:
RuntimeException
- if session creation failed.
-
createSessionCache
protected org.eclipse.scout.rt.platform.util.collection.ConcurrentExpiringMap<org.eclipse.scout.rt.platform.util.CompositeObject,IClientSession> createSessionCache(long ttl) -
stopSession
-
newSessionCacheKey
-
prepareSessionCreatingClientRunContext
Hook method for adapting theClientRunContext
that is used for creating the newIClientSession
instance.- Since:
- 7.0
-
registerSessionForNotifications
- Overrides:
registerSessionForNotifications
in classClientSessionProvider
-
beforeStartSession
- Overrides:
beforeStartSession
in classClientSessionProvider
-
handleMessageBox
Closes the message box with value determined by theMESSAGE_BOX_HANDLER_STRATEGY
, or as a default withIMessageBox.CANCEL_OPTION
. -
afterStartSession
- Overrides:
afterStartSession
in classClientSessionProvider
-