Package me.ahoo.cosid.machine
Interface MachineIdDistributor
- All Known Implementing Classes:
AbstractMachineIdDistributor
,JdbcMachineIdDistributor
,ManualMachineIdDistributor
,MongoMachineIdDistributor
,ProxyMachineIdDistributor
,SpringRedisMachineIdDistributor
,StatefulSetMachineIdDistributor
,ZookeeperMachineIdDistributor
@ThreadSafe
public interface MachineIdDistributor
MachineId Distributor.
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptiondistribute
(String namespace, int machineBit, InstanceId instanceId, Duration safeGuardDuration) distribute machine id.static long
getSafeGuardAt
(Duration safeGuardDuration, boolean stable) void
guard
(String namespace, InstanceId instanceId, Duration safeGuardDuration) Guard the machine id by heartbeat.static int
maxMachineId
(int machineBit) static String
namespacedMachineId
(String namespace, int machineId) void
revert
(String namespace, InstanceId instanceId) revert machine id.static int
totalMachineIds
(int machineBit)
-
Field Details
-
FOREVER_SAFE_GUARD_DURATION
-
-
Method Details
-
maxMachineId
static int maxMachineId(int machineBit) -
totalMachineIds
static int totalMachineIds(int machineBit) -
namespacedMachineId
-
getSafeGuardAt
-
distribute
@Nonnull MachineState distribute(String namespace, int machineBit, InstanceId instanceId, Duration safeGuardDuration) throws MachineIdOverflowException distribute machine id.- Parameters:
namespace
- namespacemachineBit
- machineBitinstanceId
- instanceIdsafeGuardDuration
- safe Guard Duration- Returns:
- machine state
- Throws:
MachineIdOverflowException
- This exception is thrown when the machine number allocation exceeds the threshold
-
revert
revert machine id.- Parameters:
namespace
- namespaceinstanceId
- instanceId- Throws:
NotFoundMachineStateException
-
guard
void guard(String namespace, InstanceId instanceId, Duration safeGuardDuration) throws NotFoundMachineStateException, MachineIdLostException Guard the machine id by heartbeat.- Parameters:
namespace
- namespaceinstanceId
- instanceIdsafeGuardDuration
- safe Guard Duration- Throws:
NotFoundMachineStateException
MachineIdLostException
-