Class ProcessSystemState
- All Implemented Interfaces:
Serializable
This class enables:
- Checkpointing: Save and restore simulation state
- Digital Twin Lifecycle: Track model evolution through concept → design → operation
- Version Control: Export models to JSON for Git-based versioning
- Knowledge Preservation: Maintain institutional knowledge despite staff turnover
Usage Example:
ProcessSystem process = new ProcessSystem();
// ... configure process ...
// Export state
ProcessSystemState state = ProcessSystemState.fromProcessSystem(process);
state.setVersion("1.2.3");
state.setDescription("Post-commissioning tuned model");
state.saveToFile("asset_model_v1.2.3.json");
// Later: restore
ProcessSystemState loaded = ProcessSystemState.loadFromFile("asset_model_v1.2.3.json");
ProcessSystem restored = loaded.toProcessSystem();
- Version:
- 1.0
- Author:
- ESOL
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classRepresents a connection between two pieces of equipment.static classRepresents the state of a single piece of equipment.static classRepresents the thermodynamic state of a fluid.private static classGson adapter for Instant serialization.static classResult of state validation. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Stringprivate List<ProcessSystemState.ConnectionState> private Instantprivate Stringprivate static final StringCurrent schema version for JSON format compatibility.private Stringprivate List<ProcessSystemState.EquipmentState> private Instantprivate static final org.apache.logging.log4j.LoggerLogger for this class.private ModelMetadataprivate Stringprivate StringSchema version of this state (for migration support).private static final longprivate String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidapplyTo(ProcessSystem process) Applies this saved state to an existing ProcessSystem.private voidcaptureConnections(ProcessSystem process) Captures stream connections between equipment in the process.private static com.google.gson.Gsonstatic ProcessSystemStateCreates a ProcessSystemState from a JSON string.static ProcessSystemStatefromProcessSystem(ProcessSystem process) Creates a state snapshot from a ProcessSystem.Gets the connection states capturing stream topology.getName()Gets the process name (alias for getName).Gets the schema version of this state.Gets the creation timestamp.static ProcessSystemStateloadFromCompressedFile(File file) Loads a state from a GZIP-compressed JSON file.static ProcessSystemStateloadFromCompressedFile(String filePath) Loads a state from a GZIP-compressed JSON file.static ProcessSystemStateloadFromFile(File file) Loads a state from a JSON file.static ProcessSystemStateloadFromFile(String filePath) Loads a state from a JSON file.static ProcessSystemStateloadFromFileAuto(File file) Loads a state from a file, automatically detecting whether it is compressed.static ProcessSystemStateloadFromFileAuto(String filePath) Loads a state from a file, automatically detecting whether it is compressed.private static ProcessSystemStatemigrateIfNeeded(ProcessSystemState state, String filePath) Migrates a loaded state to the current schema version if needed.voidsaveToCompressedFile(File file) Saves this state to a GZIP-compressed JSON file.voidsaveToCompressedFile(String filePath) Saves this state to a GZIP-compressed JSON file.voidsaveToFile(File file) Saves this state to a JSON file.voidsaveToFile(String filePath) Saves this state to a JSON file.voidsaveToFileAuto(File file) Saves this state to a file, automatically detecting whether to use compression.voidsaveToFileAuto(String filePath) Saves this state to a file, automatically detecting whether to use compression.voidsetCreatedBy(String createdBy) voidsetCustomProperty(String key, Object value) voidsetDescription(String description) voidsetMetadata(ModelMetadata metadata) voidvoidsetVersion(String version) toJson()Exports this state to a JSON string.Reconstructs a ProcessSystem from this state.private voidvalidate()Validates that this state is compatible with the current NeqSim version.booleanValidates the integrity of this state.
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
CURRENT_SCHEMA_VERSION
Current schema version for JSON format compatibility.- See Also:
-
logger
private static final org.apache.logging.log4j.Logger loggerLogger for this class. -
schemaVersion
Schema version of this state (for migration support). -
name
-
version
-
description
-
createdAt
-
lastModifiedAt
-
createdBy
-
metadata
-
equipmentStates
-
connectionStates
-
customProperties
-
checksum
-
-
Constructor Details
-
ProcessSystemState
public ProcessSystemState()Default constructor.
-
-
Method Details
-
fromProcessSystem
Creates a state snapshot from a ProcessSystem.- Parameters:
process- the process system to capture- Returns:
- a new ProcessSystemState representing the current state
-
captureConnections
Captures stream connections between equipment in the process.- Parameters:
process- the process system to analyze
-
toProcessSystem
Reconstructs a ProcessSystem from this state.Note: Full reconstruction requires the original equipment classes to be available. This method provides a foundation for model serialization; complete reconstruction may require additional factory methods.
- Returns:
- a new ProcessSystem initialized with the captured state
-
saveToFile
Saves this state to a JSON file.- Parameters:
filePath- path to the output file
-
saveToFile
Saves this state to a JSON file.- Parameters:
file- the output file
-
loadFromFile
Loads a state from a JSON file.- Parameters:
filePath- path to the input file- Returns:
- the loaded ProcessSystemState, or null if loading fails
-
loadFromFile
Loads a state from a JSON file.- Parameters:
file- the input file- Returns:
- the loaded ProcessSystemState, or null if loading fails
-
saveToCompressedFile
Saves this state to a GZIP-compressed JSON file.Compressed files typically achieve 5-20x size reduction compared to plain JSON, making them ideal for large process models with many equipment states.
- Parameters:
filePath- path to the output file (recommended extension: .neqsim)
-
loadFromCompressedFile
Loads a state from a GZIP-compressed JSON file.- Parameters:
filePath- path to the compressed input file (.neqsim)- Returns:
- the loaded ProcessSystemState, or null if loading fails
-
saveToCompressedFile
Saves this state to a GZIP-compressed JSON file.- Parameters:
file- the output file (recommended extension: .neqsim)
-
loadFromCompressedFile
Loads a state from a GZIP-compressed JSON file.- Parameters:
file- the compressed input file (.neqsim)- Returns:
- the loaded ProcessSystemState, or null if loading fails
-
saveToFileAuto
Saves this state to a file, automatically detecting whether to use compression.If the file path ends with ".neqsim", the file will be GZIP-compressed. Otherwise, it will be saved as plain JSON.
- Parameters:
filePath- path to the output file
-
loadFromFileAuto
Loads a state from a file, automatically detecting whether it is compressed.If the file path ends with ".neqsim", it will be read as a GZIP-compressed file. Otherwise, it will be read as plain JSON.
- Parameters:
filePath- path to the input file- Returns:
- the loaded ProcessSystemState, or null if loading fails
-
saveToFileAuto
Saves this state to a file, automatically detecting whether to use compression.- Parameters:
file- the output file
-
loadFromFileAuto
Loads a state from a file, automatically detecting whether it is compressed.- Parameters:
file- the input file- Returns:
- the loaded ProcessSystemState, or null if loading fails
-
applyTo
Applies this saved state to an existing ProcessSystem.This method attempts to restore equipment states from the saved snapshot. The process structure must match the saved state for successful restoration.
- Parameters:
process- the process system to apply the state to
-
toJson
Exports this state to a JSON string.- Returns:
- JSON representation of this state
-
fromJson
Creates a ProcessSystemState from a JSON string.- Parameters:
json- the JSON string- Returns:
- the parsed ProcessSystemState
-
createGson
private static com.google.gson.Gson createGson() -
migrateIfNeeded
Migrates a loaded state to the current schema version if needed.- Parameters:
state- the loaded statefilePath- the source file path (for logging)- Returns:
- the migrated state
-
updateChecksum
private void updateChecksum() -
validateIntegrity
public boolean validateIntegrity()Validates the integrity of this state.- Returns:
- true if the checksum matches
-
validate
Validates that this state is compatible with the current NeqSim version.Checks for:
- Schema version compatibility
- Known equipment types
- Required fields present
- Returns:
- a ValidationResult containing any warnings or errors
-
getSchemaVersion
-
getName
-
getProcessName
-
getTimestamp
Gets the creation timestamp.- Returns:
- the timestamp when this state was created
-
setName
-
getVersion
-
setVersion
-
getDescription
-
setDescription
-
getCreatedAt
-
getLastModifiedAt
-
getCreatedBy
-
setCreatedBy
-
getMetadata
-
setMetadata
-
getEquipmentStates
-
getConnectionStates
Gets the connection states capturing stream topology.- Returns:
- list of connection states
-
getCustomProperties
-
setCustomProperty
-
getChecksum
-