Package me.ahoo.cosid.machine
Class AbstractMachineIdDistributor
java.lang.Object
me.ahoo.cosid.machine.AbstractMachineIdDistributor
- All Implemented Interfaces:
MachineIdDistributor
- Direct Known Subclasses:
JdbcMachineIdDistributor
,ManualMachineIdDistributor
,MongoMachineIdDistributor
,ProxyMachineIdDistributor
,SpringRedisMachineIdDistributor
,StatefulSetMachineIdDistributor
,ZookeeperMachineIdDistributor
Abstract MachineIdDistributor.
-
Field Summary
Fields inherited from interface me.ahoo.cosid.machine.MachineIdDistributor
FOREVER_SAFE_GUARD_DURATION
-
Constructor Summary
ConstructorDescriptionAbstractMachineIdDistributor
(MachineStateStorage machineStateStorage, ClockBackwardsSynchronizer clockBackwardsSynchronizer) -
Method Summary
Modifier and TypeMethodDescriptiondistribute
(String namespace, int machineBit, InstanceId instanceId, Duration safeGuardDuration) 1.protected abstract MachineState
distributeRemote
(String namespace, int machineBit, InstanceId instanceId, Duration safeGuardDuration) void
guard
(String namespace, InstanceId instanceId, Duration safeGuardDuration) Guard the machine id by heartbeat.protected abstract void
guardRemote
(String namespace, InstanceId instanceId, MachineState machineState, Duration safeGuardDuration) void
revert
(String namespace, InstanceId instanceId) 1.protected abstract void
revertRemote
(String namespace, InstanceId instanceId, MachineState machineState)
-
Field Details
-
NOT_FOUND_LAST_STAMP
public static final int NOT_FOUND_LAST_STAMP- See Also:
-
-
Constructor Details
-
AbstractMachineIdDistributor
public AbstractMachineIdDistributor(MachineStateStorage machineStateStorage, ClockBackwardsSynchronizer clockBackwardsSynchronizer)
-
-
Method Details
-
distribute
@Nonnull public MachineState distribute(String namespace, int machineBit, InstanceId instanceId, Duration safeGuardDuration) throws MachineIdOverflowException 1. get fromMachineStateStorage
2. when not found:distributeRemote(java.lang.String, int, me.ahoo.cosid.machine.InstanceId, java.time.Duration)
3. setMachineState
toMachineStateStorage
- Specified by:
distribute
in interfaceMachineIdDistributor
- 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
-
distributeRemote
protected abstract MachineState distributeRemote(String namespace, int machineBit, InstanceId instanceId, Duration safeGuardDuration) -
revert
1. get fromMachineStateStorage
2. when not found:distributeRemote(java.lang.String, int, me.ahoo.cosid.machine.InstanceId, java.time.Duration)
, no need to revert 3. revert- Specified by:
revert
in interfaceMachineIdDistributor
- Parameters:
namespace
- namespaceinstanceId
- instanceId
-
revertRemote
protected abstract void revertRemote(String namespace, InstanceId instanceId, MachineState machineState) -
guard
public void guard(String namespace, InstanceId instanceId, Duration safeGuardDuration) throws NotFoundMachineStateException, MachineIdLostException Description copied from interface:MachineIdDistributor
Guard the machine id by heartbeat.- Specified by:
guard
in interfaceMachineIdDistributor
- Parameters:
namespace
- namespaceinstanceId
- instanceIdsafeGuardDuration
- safe Guard Duration- Throws:
NotFoundMachineStateException
MachineIdLostException
-
guardRemote
protected abstract void guardRemote(String namespace, InstanceId instanceId, MachineState machineState, Duration safeGuardDuration)
-