Interface MachineIdGuarder

All Known Implementing Classes:
DefaultMachineIdGuarder, MachineIdGuarder.None

@Beta public interface MachineIdGuarder
MachineId Guarder.

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 Classes
    Modifier and Type
    Interface
    Description
    static class 
    A no-operation implementation of MachineIdGuarder.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final MachineIdGuarder
     
  • Method Summary

    Modifier and Type
    Method
    Description
    Gets the guardian state for all registered instances.
    default boolean
    Checks if any registered instance has failed guarding.
    boolean
    Checks if the machine ID guarder is currently running.
    void
    register(String namespace, InstanceId instanceId)
    Registers an instance ID within a specific namespace.
    void
    Starts the machine ID guarder.
    void
    Stops the machine ID guarder.
    void
    unregister(String namespace, InstanceId instanceId)
    Unregisters an instance ID from a specific namespace.
  • Field Details

  • 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

      void register(String namespace, InstanceId instanceId)
      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 null
      instanceId - the instance ID to register, must not be null
      Throws:
      IllegalArgumentException - if namespace or instanceId is null
    • unregister

      void unregister(String namespace, InstanceId instanceId)
      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 null
      instanceId - 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