Class InMemoryMachineStateStorage

java.lang.Object
me.ahoo.cosid.machine.InMemoryMachineStateStorage
All Implemented Interfaces:
MachineStateStorage

public class InMemoryMachineStateStorage extends Object implements MachineStateStorage
In-memory implementation of MachineStateStorage.

Stores machine states in a ConcurrentHashMap for fast access. This implementation is not persistent and should only be used for testing or single-instance deployments.

  • Constructor Details

    • InMemoryMachineStateStorage

      public InMemoryMachineStateStorage()
  • Method Details

    • get

      public @NonNull MachineState get(String namespace, InstanceId instanceId)
      Description copied from interface: MachineStateStorage
      Gets the machine state for a given namespace and instance.
      Specified by:
      get in interface MachineStateStorage
      Parameters:
      namespace - the namespace
      instanceId - the instance ID
      Returns:
      the machine state, or NOT_FOUND if not found
    • set

      public void set(String namespace, int machineId, InstanceId instanceId)
      Description copied from interface: MachineStateStorage
      Sets the machine state for a given namespace and instance.
      Specified by:
      set in interface MachineStateStorage
      Parameters:
      namespace - the namespace
      machineId - the machine ID
      instanceId - the instance ID
    • remove

      public void remove(String namespace, InstanceId instanceId)
      Description copied from interface: MachineStateStorage
      Removes the machine state for a given namespace and instance.
      Specified by:
      remove in interface MachineStateStorage
      Parameters:
      namespace - the namespace
      instanceId - the instance ID
    • clear

      public void clear(String namespace)
      Description copied from interface: MachineStateStorage
      Clears all machine states for a given namespace.
      Specified by:
      clear in interface MachineStateStorage
      Parameters:
      namespace - the namespace
    • size

      public int size(String namespace)
      Description copied from interface: MachineStateStorage
      Gets the number of machine states in a namespace.
      Specified by:
      size in interface MachineStateStorage
      Parameters:
      namespace - the namespace
      Returns:
      the number of machine states
    • exists

      public boolean exists(String namespace, InstanceId instanceId)
      Description copied from interface: MachineStateStorage
      Checks if a machine state exists for a given namespace and instance.
      Specified by:
      exists in interface MachineStateStorage
      Parameters:
      namespace - the namespace
      instanceId - the instance ID
      Returns:
      true if the state exists