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 classRepresents the difference between two ProcessModelState instances.static classOptions controlling JSON serialization of ProcessModelState.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 TypeMethodDescriptionvoidAdds an inter-process connection manually.private 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.static ProcessModelState.ModelDiffcompare(ProcessModelState oldState, ProcessModelState newState) Compares two ProcessModelState instances and returns a diff describing the changes.private static com.google.gson.GsonCreates a Gson instance with custom type adapters.static ProcessModelStatefromCompressedBytes(byte[] data) Deserializes a ProcessModelState from a compressed byte array (GZIP-compressed JSON).static ProcessModelStateDeserializes a ProcessModelState from a JSON string.static ProcessModelStatefromProcessModel(ProcessModel model) Creates a state snapshot from a ProcessModel.getConnectionsTo(String processName) Gets all inter-process connections targeting a specific process.Gets when this state was created.Gets who created this state.Gets custom properties.getCustomProperty(String key) Gets a single custom property by key.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 ProcessModelStateloadFromCompressedFile(String filename) Loads a ProcessModelState from a GZIP-compressed JSON file.static ProcessModelStateloadFromFile(String filename) Loads a ProcessModelState from a file.static ProcessModelStatemigrate(ProcessModelState state, String targetVersion) Migrates a ProcessModelState to the specified target schema version.private voidMigrates state from older schema versions if needed.voidsaveToCompressedFile(String filename) Saves this state to a GZIP-compressed JSON file.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.byte[]Serializes this state to a compressed byte array (GZIP-compressed JSON).toJson()Serializes this state to a JSON string.Serializes this state to JSON with the given serialization options.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.- Parameters:
stream- the stream to checkcurrentProcess- the name of the current processstreamToProcess- map from stream names to their originating process
-
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.- Returns:
- configured Gson instance
-
toJson
-
fromJson
Deserializes a ProcessModelState from a JSON string.- Parameters:
json- the JSON string to parse- Returns:
- the deserialized ProcessModelState
-
saveToCompressedFile
Saves this state to a GZIP-compressed JSON file.- Parameters:
filename- the file path (typically ending in .json.gz)
-
loadFromCompressedFile
Loads a ProcessModelState from a GZIP-compressed JSON file.- Parameters:
filename- the file path (typically ending in .json.gz)- Returns:
- the loaded ProcessModelState
-
addInterProcessConnection
Adds an inter-process connection manually.- Parameters:
connection- the connection to add
-
getConnectionsTo
Gets all inter-process connections targeting a specific process.- Parameters:
processName- the target process name- Returns:
- list of connections targeting the specified process
-
toCompressedBytes
Serializes this state to a compressed byte array (GZIP-compressed JSON).- Returns:
- the compressed byte array
- Throws:
IOException- if compression fails
-
fromCompressedBytes
Deserializes a ProcessModelState from a compressed byte array (GZIP-compressed JSON).- Parameters:
data- the compressed byte array- Returns:
- the deserialized ProcessModelState
- Throws:
IOException- if decompression fails
-
toJson
Serializes this state to JSON with the given serialization options.- Parameters:
options- serialization options controlling output format- Returns:
- JSON string
-
compare
public static ProcessModelState.ModelDiff compare(ProcessModelState oldState, ProcessModelState newState) Compares two ProcessModelState instances and returns a diff describing the changes.- Parameters:
oldState- the baseline statenewState- the updated state- Returns:
- a ModelDiff describing differences
-
migrate
Migrates a ProcessModelState to the specified target schema version.- Parameters:
state- the state to migratetargetVersion- the target schema version string- Returns:
- the migrated state (may be the same instance if already at target version)
-
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
-
getCustomProperty
-
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
-