Class StatePersistenceRunner
java.lang.Object
neqsim.mcp.runners.StatePersistenceRunner
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
FieldsModifier and TypeFieldDescriptionprivate static final com.google.gson.Gsonprivate static StringDefault directory for saved simulations. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivatePrivate constructor — all methods are static. -
Method Summary
Modifier and TypeMethodDescriptionprivate static voidcompareField(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 StringcompareVersions(com.google.gson.JsonObject input) Compares two saved versions and produces a diff.private static StringdeleteSaved(com.google.gson.JsonObject input) Deletes a saved state file.private static voidEnsures the storage directory exists.private static StringCreates a standard error JSON response.private static StringexportSession(com.google.gson.JsonObject input) Exports a session as a standalone shareable JSON document.private static StringgetInfo()Returns info about the persistence system.private static StringlistSaved(com.google.gson.JsonObject input) Lists all saved simulations with metadata.private static StringloadState(com.google.gson.JsonObject input) Loads a saved simulation state and creates a new session from it.static StringMain entry point for state persistence operations.private static StringsanitizeFilename(String name) Sanitizes a name for use as a filename.private static StringsaveState(com.google.gson.JsonObject input) Saves the current state of a session to a versioned JSON file.private static StringsetStorageDirectory(com.google.gson.JsonObject input) Sets the storage directory for saved simulations.
-
Field Details
-
GSON
private static final com.google.gson.Gson GSON -
storageDir
Default directory for saved simulations.
-
-
Constructor Details
-
StatePersistenceRunner
private StatePersistenceRunner()Private constructor — all methods are static.
-
-
Method Details
-
run
-
saveState
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
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
Lists all saved simulations with metadata.- Parameters:
input- optional JSON with filter criteria- Returns:
- JSON with list of saved states
-
deleteSaved
Deletes a saved state file.- Parameters:
input- JSON with filename- Returns:
- JSON confirmation
-
compareVersions
Compares two saved versions and produces a diff.- Parameters:
input- JSON with file1 and file2 filenames- Returns:
- JSON with differences
-
exportSession
Exports a session as a standalone shareable JSON document.- Parameters:
input- JSON with sessionId- Returns:
- JSON with complete standalone session
-
setStorageDirectory
Sets the storage directory for saved simulations.- Parameters:
input- JSON with directory path- Returns:
- JSON confirmation
-
getInfo
Returns info about the persistence system.- Returns:
- JSON with status
-
ensureStorageDir
Ensures the storage directory exists.- Throws:
IOException- if directory cannot be created
-
sanitizeFilename
-
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 populateobj1- first objectobj2- second objectfield- the field name
-
errorJson
-