Package me.ahoo.cosid.machine
Class GuardDistribute
java.lang.Object
me.ahoo.cosid.machine.GuardDistribute
- All Implemented Interfaces:
MachineIdDistribute
- Direct Known Subclasses:
CosIdGuardDistribute
-
Constructor Summary
ConstructorsConstructorDescriptionGuardDistribute(MachineIdDistributor machineIdDistributor, MachineIdGuarder machineIdGuarder) -
Method Summary
Modifier and TypeMethodDescription@NonNull MachineStatedistribute(String namespace, int machineBit, InstanceId instanceId, Duration safeGuardDuration) Distribute (allocate) a machine ID within the specified namespace.@NonNull Set<NamespacedInstanceId>Every machine id distributed through this instance, whether or not a guarder is running, so that they can all be reverted on shutdown.@NonNull MachineIdLeasegetLease(String namespace, InstanceId instanceId) The lease that keeps the distributed machine id usable, seeMachineIdLease.
-
Constructor Details
-
GuardDistribute
public GuardDistribute(MachineIdDistributor machineIdDistributor, MachineIdGuarder machineIdGuarder)
-
-
Method Details
-
distribute
public @NonNull MachineState distribute(String namespace, int machineBit, InstanceId instanceId, Duration safeGuardDuration) throws MachineIdOverflowException Description copied from interface:MachineIdDistributeDistribute (allocate) a machine ID within the specified namespace.This method allocates a unique machine ID for the given instance within the specified namespace. The allocated ID is guaranteed to be unique within that namespace for the duration of its lease.
The method returns a
MachineStateobject containing the allocated machine ID and associated metadata.- Specified by:
distributein interfaceMachineIdDistribute- Parameters:
namespace- The namespace for machine ID allocationmachineBit- The number of bits to use for machine IDsinstanceId- The instance identifier requesting the machine IDsafeGuardDuration- The duration for safe guarding the allocation- Returns:
- The machine state containing the allocated machine ID
- Throws:
MachineIdOverflowException- if no more machine IDs are available
-
getLease
The lease that keeps the distributed machine id usable, seeMachineIdLease.- Parameters:
namespace- namespaceinstanceId- instance id- Returns:
- the lease of the instance
-
getDistributed
Every machine id distributed through this instance, whether or not a guarder is running, so that they can all be reverted on shutdown.- Returns:
- a snapshot of the distributed instances
-