Class SessionManager

java.lang.Object
net.simplace.sim.wrapper.rest.session.SessionManager

public class SessionManager extends Object
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.
  • Field Details

    • ENGINE_LOCK

      public static final ReentrantLock ENGINE_LOCK
      Process-wide lock serialising all calls into the (singleton) FWSimEngine, see EngineLock.
  • Constructor Details

    • SessionManager

      public SessionManager(Duration idleTimeout)
      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

      public SessionHolder create(SimplaceWrapper wrapper)
      Registers a new session with a random UUID.
      Parameters:
      wrapper - the prepared wrapper of the session
      Returns:
      the new session holder
    • get

      public SessionHolder get(String id)
      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

      public void remove(String id)
      Removes a session, drops its jobs and shuts down its wrapper. Unknown ids are ignored.
      Parameters:
      id - session id
    • getJobManager

      public JobManager getJobManager()
      Returns:
      the job manager for asynchronous runs of all sessions