Interface MachineIdGuarder
- All Known Implementing Classes:
DefaultMachineIdGuarder,MachineIdGuarder.None
The MachineIdGuarder interface provides mechanisms to guard and manage machine IDs in a distributed system. It allows registering and unregistering instances within namespaces, and controlling the lifecycle of the guarder.
This interface is designed to prevent machine ID conflicts and ensure unique identification across distributed instances.
Example usage:
MachineIdGuarder guarder = new SomeMachineIdGuarder();
guarder.register("myNamespace", new InstanceId("instance1"));
guarder.start();
// ... use the guarder
guarder.stop();
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic classA no-operation implementation of MachineIdGuarder. -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionGets the guardian state for all registered instances.default booleanChecks if any registered instance has failed guarding.booleanChecks if the machine ID guarder is currently running.voidregister(String namespace, InstanceId instanceId) Registers an instance ID within a specific namespace.voidstart()Starts the machine ID guarder.voidstop()Stops the machine ID guarder.voidunregister(String namespace, InstanceId instanceId) Unregisters an instance ID from a specific namespace.
-
Field Details
-
NONE
-
-
Method Details
-
getGuardianStates
Map<NamespacedInstanceId,GuardianState> getGuardianStates()Gets the guardian state for all registered instances.This method returns a map of namespaced instance IDs to their current guardian state, including the timestamp of the last guarding operation and any errors that occurred.
- Returns:
- a map of namespaced instance IDs to their guardian state
-
hasFailure
default boolean hasFailure()Checks if any registered instance has failed guarding.This method returns true if at least one registered instance has a failed guardian state, indicating that the guarding operation encountered an error for that instance.
- Returns:
- true if any instance has failed guarding, false otherwise
-
register
Registers an instance ID within a specific namespace.This method associates the given instance ID with the provided namespace, allowing the guarder to track and manage machine IDs for conflict prevention.
- Parameters:
namespace- the namespace to register the instance in, must not be nullinstanceId- the instance ID to register, must not be null- Throws:
IllegalArgumentException- if namespace or instanceId is null
-
unregister
Unregisters an instance ID from a specific namespace.This method removes the association of the given instance ID with the provided namespace, releasing any resources or locks held for that instance.
- Parameters:
namespace- the namespace to unregister the instance from, must not be nullinstanceId- the instance ID to unregister, must not be null- Throws:
IllegalArgumentException- if namespace or instanceId is null
-
start
void start()Starts the machine ID guarder.This method initializes the guarder and begins monitoring or guarding machine IDs. After calling start(), the guarder is considered running.
- Throws:
IllegalStateException- if the guarder is already running
-
stop
void stop()Stops the machine ID guarder.This method shuts down the guarder and stops monitoring or guarding machine IDs. After calling stop(), the guarder is no longer running.
- Throws:
IllegalStateException- if the guarder is not running
-
isRunning
boolean isRunning()Checks if the machine ID guarder is currently running.- Returns:
- true if the guarder is running, false otherwise
-