Class SessionRunner

java.lang.Object
neqsim.mcp.runners.SessionRunner

public final class SessionRunner extends Object
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
  • Field Details

  • Constructor Details

    • SessionRunner

      private SessionRunner()
      Private constructor — all methods are static.
  • Method Details

    • run

      public static String run(String json)
      Routes a session command based on the "action" field in the JSON.
      Parameters:
      json - the JSON command
      Returns:
      JSON result string
    • createSession

      private static String createSession(com.google.gson.JsonObject input)
      Creates a new session with a fluid definition.
      Parameters:
      input - JSON with fluid definition
      Returns:
      JSON with session ID
    • addEquipment

      private static String addEquipment(com.google.gson.JsonObject input)
      Adds equipment to an existing session.
      Parameters:
      input - JSON with sessionId and equipment definition
      Returns:
      JSON with updated process state
    • runSession

      private static String runSession(com.google.gson.JsonObject input)
      Runs the current session process.
      Parameters:
      input - JSON with sessionId
      Returns:
      JSON with simulation results
    • modifyParameter

      private static String modifyParameter(com.google.gson.JsonObject input)
      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

      private static String getSessionState(com.google.gson.JsonObject input)
      Returns the current state of a session.
      Parameters:
      input - JSON with sessionId
      Returns:
      JSON with session metadata and equipment list
    • listSessions

      private static String listSessions()
      Lists all active sessions.
      Returns:
      JSON with session summaries
    • closeSession

      private static String closeSession(com.google.gson.JsonObject input)
      Closes and removes a session.
      Parameters:
      input - JSON with sessionId
      Returns:
      JSON confirmation
    • buildFullProcessJson

      private static String buildFullProcessJson(SessionRunner.SessionState state)
      Builds the full process JSON from session state.
      Parameters:
      state - the session state
      Returns:
      the full JSON string for ProcessSystem.fromJsonAndRun
    • getEquipmentList

      private static com.google.gson.JsonArray getEquipmentList(ProcessSystem process)
      Gets the equipment list from a ProcessSystem.
      Parameters:
      process - the process system
      Returns:
      JSON array of equipment names and types
    • getValidSession

      private static SessionRunner.SessionState getValidSession(com.google.gson.JsonObject input)
      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

      private static String errorJson(String code, String message, String remediation)
      Creates a standard error JSON string.
      Parameters:
      code - the error code
      message - the error message
      remediation - the fix suggestion
      Returns:
      the error JSON string