Class ProcessModelState
java.lang.Object
neqsim.process.processmodel.lifecycle.ProcessModelState
- All Implemented Interfaces:
Serializable
Represents a serializable state snapshot of a ProcessModel containing multiple ProcessSystems.
This class enables:
- Multi-Process Checkpointing: Save and restore complete multi-system models
- Cross-Process Connections: Track streams shared between ProcessSystems
- Version Control: Export models to JSON for Git-based versioning
- Digital Twin Lifecycle: Track model evolution through concept → design → operation
Usage Example:
ProcessModel model = new ProcessModel();
model.add("upstream", upstreamProcess);
model.add("downstream", downstreamProcess);
model.run();
// Export state
ProcessModelState state = ProcessModelState.fromProcessModel(model);
state.setVersion("1.0.0");
state.setDescription("Full field development model");
state.saveToFile("field_model_v1.json");
// Later: restore
ProcessModelState loaded = ProcessModelState.loadFromFile("field_model_v1.json");
ProcessModel restored = loaded.toProcessModel();
- Version:
- 1.0
- Author:
- ESOL
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classExecution configuration for ProcessModel.private static classInstant type adapter for Gson.static classRepresents a connection between two ProcessSystems.static classValidation result for ProcessModelState. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Instantprivate Stringprivate static final StringCurrent schema version for JSON format compatibility.Custom properties for extensibility.private StringExecution configuration.Connections between different ProcessSystems.private Instantprivate static final org.apache.logging.log4j.LoggerLogger for this class.private Stringprivate Map<String, ProcessSystemState> Map of process name to its state.private StringSchema version of this state (for migration support).private static final longprivate String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voidCaptures connections between different ProcessSystems in the model.private voidcheckAndAddInterProcessConnection(StreamInterface stream, String currentProcess, Map<String, String> streamToProcess) Checks if a stream comes from a different process and adds an inter-process connection.private static com.google.gson.GsonCreates a Gson instance with custom type adapters.static ProcessModelStatefromProcessModel(ProcessModel model) Creates a state snapshot from a ProcessModel.Gets when this state was created.Gets who created this state.Gets custom properties.Gets the description.Gets the execution configuration.Gets inter-process connections.Gets when this state was last modified.getName()Gets the name.intGets the number of ProcessSystems in this state.Gets the process states map.Gets the schema version.Gets the version.static ProcessModelStateloadFromFile(String filename) Loads a ProcessModelState from a file.private voidMigrates state from older schema versions if needed.voidsaveToFile(String filename) Saves this state to a file (JSON or compressed JSON based on extension).voidsetCreatedBy(String createdBy) Sets who created this state.voidsetCustomProperty(String key, Object value) Sets a custom property.voidsetDescription(String description) Sets the description.voidSets the name.voidsetVersion(String version) Sets the version.Reconstructs a ProcessModel from this state.validate()Validates the state for completeness and consistency.
-
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
-
processStates
Map of process name to its state. -
interProcessConnections
Connections between different ProcessSystems. -
customProperties
-
executionConfig
Execution configuration.
-
-
Constructor Details
-
ProcessModelState
public ProcessModelState()Default constructor.
-
-
Method Details
-
fromProcessModel
Creates a state snapshot from a ProcessModel.- Parameters:
model- the process model to capture- Returns:
- a new ProcessModelState representing the current state
-
captureInterProcessConnections
Captures connections between different ProcessSystems in the model.This detects when streams from one ProcessSystem are referenced by another, enabling proper reconstruction of complex multi-process models.
- Parameters:
model- the process model to analyze
-
checkAndAddInterProcessConnection
private void checkAndAddInterProcessConnection(StreamInterface stream, String currentProcess, Map<String, String> streamToProcess) Checks if a stream comes from a different process and adds an inter-process connection. -
toProcessModel
Reconstructs a ProcessModel from this state.This creates ProcessSystems for each captured state. Full equipment reconstruction requires the original equipment classes to be available.
- Returns:
- a new ProcessModel initialized with the captured state
-
saveToFile
Saves this state to a file (JSON or compressed JSON based on extension).- Parameters:
filename- the file path (use .json for plain JSON, .json.gz for compressed)
-
loadFromFile
Loads a ProcessModelState from a file.- Parameters:
filename- the file path to load from- Returns:
- the loaded ProcessModelState
-
migrateIfNeeded
private void migrateIfNeeded()Migrates state from older schema versions if needed. -
createGson
private static com.google.gson.Gson createGson()Creates a Gson instance with custom type adapters. -
validate
Validates the state for completeness and consistency.- Returns:
- a ValidationResult with any issues found
-
getSchemaVersion
-
getName
-
setName
-
getVersion
-
setVersion
-
getDescription
-
setDescription
Sets the description.- Parameters:
description- the description
-
getCreatedAt
-
getLastModifiedAt
Gets when this state was last modified.- Returns:
- last modification timestamp
-
getCreatedBy
-
setCreatedBy
Sets who created this state.- Parameters:
createdBy- creator identifier
-
getProcessStates
Gets the process states map.- Returns:
- map of process name to ProcessSystemState
-
getInterProcessConnections
Gets inter-process connections.- Returns:
- list of inter-process connections
-
getCustomProperties
-
setCustomProperty
-
getExecutionConfig
Gets the execution configuration.- Returns:
- execution configuration
-
getProcessCount
public int getProcessCount()Gets the number of ProcessSystems in this state.- Returns:
- number of process systems
-