Package org.eclipse.scout.testing.client
Class ClientSessionProviderWithCache
- java.lang.Object
-
- org.eclipse.scout.rt.client.session.ClientSessionProvider
-
- org.eclipse.scout.testing.client.ClientSessionProviderWithCache
-
public class ClientSessionProviderWithCache extends ClientSessionProvider
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
Fields Modifier and Type Field Description static ThreadLocal<ToIntFunction<IMessageBox>>
MESSAGE_BOX_HANDLER_STRATEGY
A thread local that stores an (optional) strategy how to handle message boxes in unit tests.
-
Constructor Summary
Constructors Constructor Description ClientSessionProviderWithCache()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected 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)
-
Methods inherited from class org.eclipse.scout.rt.client.session.ClientSessionProvider
currentSession, currentSession
-
-
-
-
Field Detail
-
MESSAGE_BOX_HANDLER_STRATEGY
public static final ThreadLocal<ToIntFunction<IMessageBox>> 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
-
-
Method Detail
-
provide
public <SESSION extends IClientSession> SESSION provide(ClientRunContext clientRunContext)
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)
-
newSessionCacheKey
protected org.eclipse.scout.rt.platform.util.CompositeObject newSessionCacheKey(String sessionId, Subject subject)
-
prepareSessionCreatingClientRunContext
protected void prepareSessionCreatingClientRunContext(ClientRunContext clientRunContext)
Hook method for adapting theClientRunContext
that is used for creating the newIClientSession
instance.- Since:
- 7.0
-
registerSessionForNotifications
protected void registerSessionForNotifications(IClientSession session, String sessionId)
- Overrides:
registerSessionForNotifications
in classClientSessionProvider
-
beforeStartSession
protected void beforeStartSession(IClientSession clientSession, String sessionId)
- Overrides:
beforeStartSession
in classClientSessionProvider
-
handleMessageBox
protected void handleMessageBox(IMessageBox messageBox)
Closes the message box with value determined by theMESSAGE_BOX_HANDLER_STRATEGY
, or as a default withIMessageBox.CANCEL_OPTION
.
-
afterStartSession
protected void afterStartSession(IClientSession clientSession)
- Overrides:
afterStartSession
in classClientSessionProvider
-
-