Class SessionRunner
java.lang.Object
neqsim.mcp.runners.SessionRunner
Stateful session runner that maintains live ProcessSystem instances across multiple MCP calls.
Enables incremental flowsheet construction: create a session with a fluid, add equipment one-by-one, modify parameters, and re-run without re-sending the entire JSON each time. Sessions are stored in-memory with configurable TTL and max session count.
- Version:
- 1.0
- Author:
- Even Solbraa
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static classInternal session state holder. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final com.google.gson.Gsonprivate static final intMax sessions to prevent unbounded memory growth.private static final longSession TTL in milliseconds (30 minutes).private static final ConcurrentHashMap<String, SessionRunner.SessionState> Active sessions keyed by session ID. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivatePrivate constructor — all methods are static. -
Method Summary
Modifier and TypeMethodDescriptionprivate static StringaddEquipment(com.google.gson.JsonObject input) Adds equipment to an existing session.private static StringBuilds the full process JSON from session state.private static StringcloseSession(com.google.gson.JsonObject input) Closes and removes a session.private static StringcreateSession(com.google.gson.JsonObject input) Creates a new session with a fluid definition.private static StringCreates a standard error JSON string.private static voidRemoves sessions that have exceeded the TTL.private static com.google.gson.JsonArraygetEquipmentList(ProcessSystem process) Gets the equipment list from a ProcessSystem.private static StringgetSessionState(com.google.gson.JsonObject input) Returns the current state of a session.private static SessionRunner.SessionStategetValidSession(com.google.gson.JsonObject input) Retrieves and validates a session from the input JSON.private static StringLists all active sessions.private static StringmodifyParameter(com.google.gson.JsonObject input) Modifies a parameter in the session process and optionally re-runs.static StringRoutes a session command based on the "action" field in the JSON.private static StringrunSession(com.google.gson.JsonObject input) Runs the current session process.
-
Field Details
-
GSON
private static final com.google.gson.Gson GSON -
MAX_SESSIONS
private static final int MAX_SESSIONSMax sessions to prevent unbounded memory growth.- See Also:
-
SESSION_TTL_MS
private static final long SESSION_TTL_MSSession TTL in milliseconds (30 minutes).- See Also:
-
SESSIONS
Active sessions keyed by session ID.
-
-
Constructor Details
-
SessionRunner
private SessionRunner()Private constructor — all methods are static.
-
-
Method Details
-
run
-
createSession
Creates a new session with a fluid definition.- Parameters:
input- JSON with fluid definition- Returns:
- JSON with session ID
-
addEquipment
Adds equipment to an existing session.- Parameters:
input- JSON with sessionId and equipment definition- Returns:
- JSON with updated process state
-
runSession
Runs the current session process.- Parameters:
input- JSON with sessionId- Returns:
- JSON with simulation results
-
modifyParameter
Modifies a parameter in the session process and optionally re-runs.- Parameters:
input- JSON with sessionId, address, value, unit, and optional autoRun flag- Returns:
- JSON with modification result
-
getSessionState
Returns the current state of a session.- Parameters:
input- JSON with sessionId- Returns:
- JSON with session metadata and equipment list
-
listSessions
Lists all active sessions.- Returns:
- JSON with session summaries
-
closeSession
Closes and removes a session.- Parameters:
input- JSON with sessionId- Returns:
- JSON confirmation
-
buildFullProcessJson
Builds the full process JSON from session state.- Parameters:
state- the session state- Returns:
- the full JSON string for ProcessSystem.fromJsonAndRun
-
getEquipmentList
Gets the equipment list from a ProcessSystem.- Parameters:
process- the process system- Returns:
- JSON array of equipment names and types
-
getValidSession
Retrieves and validates a session from the input JSON.- Parameters:
input- the JSON input containing sessionId- Returns:
- the session state, or null if not found/expired
-
evictExpiredSessions
private static void evictExpiredSessions()Removes sessions that have exceeded the TTL. -
errorJson
-