Class SessionManager
java.lang.Object
net.simplace.sim.wrapper.rest.session.SessionManager
Holds all open sessions in memory. Not persistent - a restart of the server loses all
sessions (with a stateful FWSimEngine this is the only honest option anyway). Sessions that
have not been accessed for the idle timeout are closed automatically (checked once a minute),
unless they still have a queued or running job.
ENGINE_LOCK: FWSimEngine is a classic singleton (static cIdentity field) - ProjectControler,
ResourceManager and OutputManager are implicitly connected through it, even though each
session has its own FWSimSession/simulation queue. To avoid data races between sessions,
RestServer serialises all engine calls server-wide with this lock: preparing sessions and
creating simulations as well as running, stepping, reading results and shutting down.
It is the process-wide
EngineLock.LOCK (shared with the web client if both run in
one JVM).
If it turns out that parallel runSimulations() calls of different sessions are actually
safe, this global lock can be replaced by finer-grained locks - the safe (slower) variant
was chosen as a starting point.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classThrown if a session id is unknown (mapped to HTTP 404 by RestServer). -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ReentrantLockProcess-wide lock serialising all calls into the (singleton) FWSimEngine, seeEngineLock. -
Constructor Summary
ConstructorsConstructorDescriptionSessionManager(Duration idleTimeout) Creates the session manager and starts the background task that closes idle sessions. -
Method Summary
Modifier and TypeMethodDescriptioncreate(SimplaceWrapper wrapper) Registers a new session with a random UUID.Returns a session and marks it as accessed.voidRemoves a session, drops its jobs and shuts down its wrapper.
-
Field Details
-
ENGINE_LOCK
Process-wide lock serialising all calls into the (singleton) FWSimEngine, seeEngineLock.
-
-
Constructor Details
-
SessionManager
Creates the session manager and starts the background task that closes idle sessions.- Parameters:
idleTimeout- time without access after which a session is closed
-
-
Method Details
-
create
Registers a new session with a random UUID.- Parameters:
wrapper- the prepared wrapper of the session- Returns:
- the new session holder
-
get
Returns a session and marks it as accessed.- Parameters:
id- session id- Returns:
- the session holder
- Throws:
SessionManager.NoSuchSessionException- if there is no session with this id
-
remove
Removes a session, drops its jobs and shuts down its wrapper. Unknown ids are ignored.- Parameters:
id- session id
-
getJobManager
- Returns:
- the job manager for asynchronous runs of all sessions
-