Class ProcessSimulationSession

java.lang.Object
neqsim.process.processmodel.ProcessSimulationSession

public class ProcessSimulationSession extends Object
Session-scoped ProcessSystem manager for multi-user online simulation.

Manages isolated simulation sessions where each user/request gets their own copy of a ProcessSystem. Supports template-based creation (copy-on-create), automatic session expiry, and concurrent access control.

Usage from Python (via JPype):

# Create a session manager with a template process
manager = ProcessSimulationSession()

# Register a template
template = ProcessSystem("gas processing")
# ... build template ...
template.run()
manager.registerTemplate("gas_processing", template)

# Create a session from the template
sessionId = manager.createSession("gas_processing")

# Get the session's process system and modify it
process = manager.getSession(sessionId)
process.getUnit("feed").setFlowRate(60000.0, "kg/hr")
process.run()
report = process.getReport_json()

# Clean up
manager.destroySession(sessionId)

Usage with JSON builder:

manager = ProcessSimulationSession()
sessionId = manager.createSessionFromJson(jsonDefinition)
process = manager.getSession(sessionId)
result = process.runAndReport()
Version:
1.0
Author:
Even Solbraa
  • Field Details

    • logger

      private static final org.apache.logging.log4j.Logger logger
      Logger object for class.
    • DEFAULT_TIMEOUT_MINUTES

      private static final long DEFAULT_TIMEOUT_MINUTES
      Default session timeout in minutes.
      See Also:
    • DEFAULT_MAX_SESSIONS

      private static final int DEFAULT_MAX_SESSIONS
      Maximum number of concurrent sessions.
      See Also:
    • sessions

      Active sessions indexed by session ID.
    • templates

      private final ConcurrentHashMap<String, ProcessSystem> templates
      Named templates for copy-on-create.
    • timeoutMinutes

      private long timeoutMinutes
      Session timeout in minutes.
    • maxSessions

      private int maxSessions
      Maximum concurrent sessions.
    • cleanupExecutor

      private ScheduledExecutorService cleanupExecutor
      Scheduled executor for session cleanup.
  • Constructor Details

    • ProcessSimulationSession

      public ProcessSimulationSession()
      Creates a session manager with default settings (30 min timeout, 100 max sessions).
    • ProcessSimulationSession

      public ProcessSimulationSession(long timeoutMinutes, int maxSessions)
      Creates a session manager with custom settings.
      Parameters:
      timeoutMinutes - session timeout in minutes (0 = no timeout)
      maxSessions - maximum number of concurrent sessions
  • Method Details

    • registerTemplate

      public void registerTemplate(String name, ProcessSystem template)
      Registers a named template ProcessSystem for copy-on-create session instantiation.

      The template is deeply copied when creating new sessions, so modifications to the template after registration will not affect existing sessions.

      Parameters:
      name - the template name
      template - the process system to use as a template
    • removeTemplate

      public boolean removeTemplate(String name)
      Removes a named template.
      Parameters:
      name - the template name
      Returns:
      true if the template was found and removed
    • getTemplateNames

      public Set<String> getTemplateNames()
      Gets the names of all registered templates.
      Returns:
      unmodifiable set of template names
    • createSession

      public String createSession(String templateName)
      Creates a new session from a named template (copy-on-create).

      The template is deep-copied so the session gets an independent ProcessSystem.

      Parameters:
      templateName - the name of the registered template
      Returns:
      the session ID
      Throws:
      IllegalArgumentException - if template not found or max sessions reached
    • createEmptySession

      public String createEmptySession()
      Creates a new session with a blank ProcessSystem.
      Returns:
      the session ID
      Throws:
      IllegalStateException - if max sessions reached
    • createSessionFromJson

      public SimulationResult createSessionFromJson(String json)
      Creates a session from a JSON process definition.
      Parameters:
      json - the JSON process definition
      Returns:
      a SimulationResult containing the session ID on success
    • getSession

      public ProcessSystem getSession(String sessionId)
      Gets the ProcessSystem for an active session.
      Parameters:
      sessionId - the session ID
      Returns:
      the session's ProcessSystem
      Throws:
      IllegalArgumentException - if session not found or expired
    • runSession

      public SimulationResult runSession(String sessionId)
      Runs the simulation for a session and returns the result.
      Parameters:
      sessionId - the session ID
      Returns:
      a SimulationResult with the run report or errors
    • destroySession

      public boolean destroySession(String sessionId)
      Destroys a session and releases its resources.
      Parameters:
      sessionId - the session ID
      Returns:
      true if the session was found and destroyed
    • getActiveSessionCount

      public int getActiveSessionCount()
      Gets the number of active sessions.
      Returns:
      active session count
    • getMaxSessions

      public int getMaxSessions()
      Gets the maximum number of allowed sessions.
      Returns:
      max sessions limit
    • setMaxSessions

      public void setMaxSessions(int maxSessions)
      Sets the maximum number of allowed sessions.
      Parameters:
      maxSessions - the new limit
    • getTimeoutMinutes

      public long getTimeoutMinutes()
      Gets session timeout in minutes.
      Returns:
      timeout in minutes
    • getSessionInfo

      public Map<String,String> getSessionInfo()
      Gets information about all active sessions.
      Returns:
      map of session IDs to their template names (null if blank session)
    • cleanupExpiredSessions

      public int cleanupExpiredSessions()
      Removes all expired sessions.
      Returns:
      number of sessions removed
    • destroyAllSessions

      public void destroyAllSessions()
      Destroys all sessions and releases resources.
    • shutdown

      public void shutdown()
      Shuts down the session manager including the cleanup executor.