Class ProcessSimulationSession
java.lang.Object
neqsim.process.processmodel.ProcessSimulationSession
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classInternal session entry tracking creation time and last access. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate ScheduledExecutorServiceScheduled executor for session cleanup.private static final intMaximum number of concurrent sessions.private static final longDefault session timeout in minutes.private static final org.apache.logging.log4j.LoggerLogger object for class.private intMaximum concurrent sessions.private final ConcurrentHashMap<String, ProcessSimulationSession.SessionEntry> Active sessions indexed by session ID.private final ConcurrentHashMap<String, ProcessSystem> Named templates for copy-on-create.private longSession timeout in minutes. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a session manager with default settings (30 min timeout, 100 max sessions).ProcessSimulationSession(long timeoutMinutes, int maxSessions) Creates a session manager with custom settings. -
Method Summary
Modifier and TypeMethodDescriptionintRemoves all expired sessions.Creates a new session with a blank ProcessSystem.createSession(String templateName) Creates a new session from a named template (copy-on-create).createSessionFromJson(String json) Creates a session from a JSON process definition.voidDestroys all sessions and releases resources.booleandestroySession(String sessionId) Destroys a session and releases its resources.intGets the number of active sessions.intGets the maximum number of allowed sessions.getSession(String sessionId) Gets the ProcessSystem for an active session.Gets information about all active sessions.Gets the names of all registered templates.longGets session timeout in minutes.voidregisterTemplate(String name, ProcessSystem template) Registers a named template ProcessSystem for copy-on-create session instantiation.booleanremoveTemplate(String name) Removes a named template.runSession(String sessionId) Runs the simulation for a session and returns the result.voidsetMaxSessions(int maxSessions) Sets the maximum number of allowed sessions.voidshutdown()Shuts down the session manager including the cleanup executor.
-
Field Details
-
logger
private static final org.apache.logging.log4j.Logger loggerLogger object for class. -
DEFAULT_TIMEOUT_MINUTES
private static final long DEFAULT_TIMEOUT_MINUTESDefault session timeout in minutes.- See Also:
-
DEFAULT_MAX_SESSIONS
private static final int DEFAULT_MAX_SESSIONSMaximum number of concurrent sessions.- See Also:
-
sessions
Active sessions indexed by session ID. -
templates
Named templates for copy-on-create. -
timeoutMinutes
private long timeoutMinutesSession timeout in minutes. -
maxSessions
private int maxSessionsMaximum concurrent sessions. -
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
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 nametemplate- the process system to use as a template
-
removeTemplate
Removes a named template.- Parameters:
name- the template name- Returns:
- true if the template was found and removed
-
getTemplateNames
-
createSession
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
Creates a new session with a blank ProcessSystem.- Returns:
- the session ID
- Throws:
IllegalStateException- if max sessions reached
-
createSessionFromJson
Creates a session from a JSON process definition.- Parameters:
json- the JSON process definition- Returns:
- a SimulationResult containing the session ID on success
-
getSession
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
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
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
-
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.
-