Class LocalMachineStateStorage

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

public class LocalMachineStateStorage extends Object implements MachineStateStorage
File-based machine state storage.

Stores machine state in local files, using base64-encoded filenames for namespace/instance encoding.

  • Field Details

    • DEFAULT_STATE_LOCATION_PATH

      public static final String DEFAULT_STATE_LOCATION_PATH
      Default state location in user home directory.
    • stateLocation

      public final String stateLocation
      The state location path.
  • Constructor Details

    • LocalMachineStateStorage

      public LocalMachineStateStorage(String stateLocation)
      Creates storage with specified location.
      Parameters:
      stateLocation - the directory path for state files
    • LocalMachineStateStorage

      public LocalMachineStateStorage()
      Creates storage with default location.
  • 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