Package me.ahoo.cosid.machine
Interface MachineStateStorage
- All Known Implementing Classes:
InMemoryMachineStateStorage,LocalMachineStateStorage
@ThreadSafe
public interface MachineStateStorage
Machine state storage for persisting machine state across restarts.
Provides an interface for storing and retrieving machine state information, which is essential for maintaining machine ID allocations in distributed ID generation systems.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final MachineStateStorageIn-memory machine state storage instance.static final MachineStateStorageLocal machine state storage instance. -
Method Summary
Modifier and TypeMethodDescriptionvoidClears all machine states for a given namespace.booleanexists(String namespace, InstanceId instanceId) Checks if a machine state exists for a given namespace and instance.@NonNull MachineStateget(String namespace, InstanceId instanceId) Gets the machine state for a given namespace and instance.voidremove(String namespace, InstanceId instanceId) Removes the machine state for a given namespace and instance.voidset(String namespace, int machineId, InstanceId instanceId) Sets the machine state for a given namespace and instance.intGets the number of machine states in a namespace.
-
Field Details
-
LOCAL
Local machine state storage instance. -
IN_MEMORY
In-memory machine state storage instance.
-
-
Method Details
-
get
Gets the machine state for a given namespace and instance.- Parameters:
namespace- the namespaceinstanceId- the instance ID- Returns:
- the machine state, or NOT_FOUND if not found
-
set
Sets the machine state for a given namespace and instance.- Parameters:
namespace- the namespacemachineId- the machine IDinstanceId- the instance ID
-
remove
Removes the machine state for a given namespace and instance.- Parameters:
namespace- the namespaceinstanceId- the instance ID
-
clear
Clears all machine states for a given namespace.- Parameters:
namespace- the namespace
-
size
Gets the number of machine states in a namespace.- Parameters:
namespace- the namespace- Returns:
- the number of machine states
-
exists
Checks if a machine state exists for a given namespace and instance.- Parameters:
namespace- the namespaceinstanceId- the instance ID- Returns:
- true if the state exists
-