Class StatePersistenceRunner

java.lang.Object
neqsim.mcp.runners.StatePersistenceRunner

public final class StatePersistenceRunner extends Object
Simulation state persistence for the NeqSim MCP server.

Provides save/load/version-track capabilities for simulation sessions. Persists process definitions and results to disk as JSON files that can be shared, version-controlled, and restored across server restarts.

Capabilities:

  • Save session state to versioned JSON files
  • Load and restore sessions from saved files
  • List all saved simulations with metadata
  • Compare two saved versions (diff)
  • Export session as a standalone shareable JSON
Version:
1.0
Author:
Even Solbraa
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final com.google.gson.Gson
     
    private static String
    Default directory for saved simulations.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
    Private constructor — all methods are static.
  • Method Summary

    Modifier and Type
    Method
    Description
    private static void
    compareField(com.google.gson.JsonObject diff, com.google.gson.JsonObject obj1, com.google.gson.JsonObject obj2, String field)
    Compares a string field between two JSON objects.
    private static String
    compareVersions(com.google.gson.JsonObject input)
    Compares two saved versions and produces a diff.
    private static String
    deleteSaved(com.google.gson.JsonObject input)
    Deletes a saved state file.
    private static void
    Ensures the storage directory exists.
    private static String
    errorJson(String code, String message, String remediation)
    Creates a standard error JSON response.
    private static String
    exportSession(com.google.gson.JsonObject input)
    Exports a session as a standalone shareable JSON document.
    private static String
    Returns info about the persistence system.
    private static String
    listSaved(com.google.gson.JsonObject input)
    Lists all saved simulations with metadata.
    private static String
    loadState(com.google.gson.JsonObject input)
    Loads a saved simulation state and creates a new session from it.
    static String
    run(String json)
    Main entry point for state persistence operations.
    private static String
    Sanitizes a name for use as a filename.
    private static String
    saveState(com.google.gson.JsonObject input)
    Saves the current state of a session to a versioned JSON file.
    private static String
    setStorageDirectory(com.google.gson.JsonObject input)
    Sets the storage directory for saved simulations.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • GSON

      private static final com.google.gson.Gson GSON
    • storageDir

      private static volatile String storageDir
      Default directory for saved simulations.
  • Constructor Details

    • StatePersistenceRunner

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

    • run

      public static String run(String json)
      Main entry point for state persistence operations.
      Parameters:
      json - JSON with action and parameters
      Returns:
      JSON with results
    • saveState

      private static String saveState(com.google.gson.JsonObject input)
      Saves the current state of a session to a versioned JSON file.
      Parameters:
      input - JSON with sessionId, optional name and description
      Returns:
      JSON confirmation with file path
    • loadState

      private static String loadState(com.google.gson.JsonObject input)
      Loads a saved simulation state and creates a new session from it.
      Parameters:
      input - JSON with filename (or filePath)
      Returns:
      JSON with new sessionId and restored state
    • listSaved

      private static String listSaved(com.google.gson.JsonObject input)
      Lists all saved simulations with metadata.
      Parameters:
      input - optional JSON with filter criteria
      Returns:
      JSON with list of saved states
    • deleteSaved

      private static String deleteSaved(com.google.gson.JsonObject input)
      Deletes a saved state file.
      Parameters:
      input - JSON with filename
      Returns:
      JSON confirmation
    • compareVersions

      private static String compareVersions(com.google.gson.JsonObject input)
      Compares two saved versions and produces a diff.
      Parameters:
      input - JSON with file1 and file2 filenames
      Returns:
      JSON with differences
    • exportSession

      private static String exportSession(com.google.gson.JsonObject input)
      Exports a session as a standalone shareable JSON document.
      Parameters:
      input - JSON with sessionId
      Returns:
      JSON with complete standalone session
    • setStorageDirectory

      private static String setStorageDirectory(com.google.gson.JsonObject input)
      Sets the storage directory for saved simulations.
      Parameters:
      input - JSON with directory path
      Returns:
      JSON confirmation
    • getInfo

      private static String getInfo()
      Returns info about the persistence system.
      Returns:
      JSON with status
    • ensureStorageDir

      private static void ensureStorageDir() throws IOException
      Ensures the storage directory exists.
      Throws:
      IOException - if directory cannot be created
    • sanitizeFilename

      private static String sanitizeFilename(String name)
      Sanitizes a name for use as a filename.
      Parameters:
      name - the name to sanitize
      Returns:
      a safe filename
    • compareField

      private static void compareField(com.google.gson.JsonObject diff, com.google.gson.JsonObject obj1, com.google.gson.JsonObject obj2, String field)
      Compares a string field between two JSON objects.
      Parameters:
      diff - the diff object to populate
      obj1 - first object
      obj2 - second object
      field - the field name
    • errorJson

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