Class ProcessSystemState

java.lang.Object
neqsim.process.processmodel.lifecycle.ProcessSystemState
All Implemented Interfaces:
Serializable

public class ProcessSystemState extends Object implements Serializable
Represents a serializable state snapshot of a ProcessSystem for lifecycle management.

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:
  • Field Details

  • Constructor Details

    • ProcessSystemState

      public ProcessSystemState()
      Default constructor.
  • Method Details

    • fromProcessSystem

      public static ProcessSystemState fromProcessSystem(ProcessSystem process)
      Creates a state snapshot from a ProcessSystem.
      Parameters:
      process - the process system to capture
      Returns:
      a new ProcessSystemState representing the current state
    • captureConnections

      private void captureConnections(ProcessSystem process)
      Captures stream connections between equipment in the process.
      Parameters:
      process - the process system to analyze
    • toProcessSystem

      public ProcessSystem 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

      public void saveToFile(String filePath)
      Saves this state to a JSON file.
      Parameters:
      filePath - path to the output file
    • saveToFile

      public void saveToFile(File file)
      Saves this state to a JSON file.
      Parameters:
      file - the output file
    • loadFromFile

      public static ProcessSystemState loadFromFile(String filePath)
      Loads a state from a JSON file.
      Parameters:
      filePath - path to the input file
      Returns:
      the loaded ProcessSystemState, or null if loading fails
    • loadFromFile

      public static ProcessSystemState loadFromFile(File file)
      Loads a state from a JSON file.
      Parameters:
      file - the input file
      Returns:
      the loaded ProcessSystemState, or null if loading fails
    • saveToCompressedFile

      public void saveToCompressedFile(String filePath)
      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

      public static ProcessSystemState loadFromCompressedFile(String filePath)
      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

      public void saveToCompressedFile(File file)
      Saves this state to a GZIP-compressed JSON file.
      Parameters:
      file - the output file (recommended extension: .neqsim)
    • loadFromCompressedFile

      public static ProcessSystemState loadFromCompressedFile(File file)
      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

      public void saveToFileAuto(String filePath)
      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

      public static ProcessSystemState loadFromFileAuto(String filePath)
      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

      public void saveToFileAuto(File file)
      Saves this state to a file, automatically detecting whether to use compression.
      Parameters:
      file - the output file
    • loadFromFileAuto

      public static ProcessSystemState loadFromFileAuto(File file)
      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

      public void applyTo(ProcessSystem process)
      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

      public String toJson()
      Exports this state to a JSON string.
      Returns:
      JSON representation of this state
    • fromJson

      public static ProcessSystemState fromJson(String json)
      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

      private static ProcessSystemState migrateIfNeeded(ProcessSystemState state, String filePath)
      Migrates a loaded state to the current schema version if needed.
      Parameters:
      state - the loaded state
      filePath - 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

      public String getSchemaVersion()
      Gets the schema version of this state.
      Returns:
      the schema version
    • getName

      public String getName()
    • getProcessName

      public String getProcessName()
      Gets the process name (alias for getName).
      Returns:
      the process name
    • getTimestamp

      public Instant getTimestamp()
      Gets the creation timestamp.
      Returns:
      the timestamp when this state was created
    • setName

      public void setName(String name)
    • getVersion

      public String getVersion()
    • setVersion

      public void setVersion(String version)
    • getDescription

      public String getDescription()
    • setDescription

      public void setDescription(String description)
    • getCreatedAt

      public Instant getCreatedAt()
    • getLastModifiedAt

      public Instant getLastModifiedAt()
    • getCreatedBy

      public String getCreatedBy()
    • setCreatedBy

      public void setCreatedBy(String createdBy)
    • getMetadata

      public ModelMetadata getMetadata()
    • setMetadata

      public void setMetadata(ModelMetadata metadata)
    • getEquipmentStates

      public List<ProcessSystemState.EquipmentState> getEquipmentStates()
    • getConnectionStates

      public List<ProcessSystemState.ConnectionState> getConnectionStates()
      Gets the connection states capturing stream topology.
      Returns:
      list of connection states
    • getCustomProperties

      public Map<String,Object> getCustomProperties()
    • setCustomProperty

      public void setCustomProperty(String key, Object value)
    • getChecksum

      public String getChecksum()