Class LeasedSnowflakeId
- All Implemented Interfaces:
Decorator<IdGenerator>,IdGenerator,IdGeneratorDecorator,SnowflakeId,Statistical,StringIdGenerator
Fail fast: a duplicate id is worse than a failed request. See MachineIdLease.
-
Field Summary
Fields inherited from interface me.ahoo.cosid.snowflake.SnowflakeId
TOTAL_BIT -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionlonggenerate()Generate a distributed ID by delegating to the actual generator.@NonNull SnowflakeIdGet the actual (wrapped) ID generator that this decorator is enhancing.longGet the timestamp of the last ID that was generated.longGet the last generated timestamp in milliseconds for clock synchronization.getLease()intGet the machine ID assigned to this generator.layout()The bit layout of the ids.stat()Get statistical information about this decorated ID generator.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface me.ahoo.cosid.IdGenerator
generateAsString, idConverterMethods inherited from interface me.ahoo.cosid.snowflake.SnowflakeId
getEpoch, getMachineBit, getMaxMachineId, getMaxSequence, getMaxTimestamp, getSequenceBit, getTimestampBit, isSafeJavascript
-
Constructor Details
-
LeasedSnowflakeId
-
-
Method Details
-
getActual
Description copied from interface:IdGeneratorDecoratorGet the actual (wrapped) ID generator that this decorator is enhancing.This method returns the underlying ID generator that this decorator is wrapping. All ID generation requests are typically delegated to this actual generator, with the decorator adding its additional functionality.
- Specified by:
getActualin interfaceDecorator<IdGenerator>- Specified by:
getActualin interfaceIdGeneratorDecorator- Returns:
- The actual ID generator being decorated
-
getLease
-
generate
Description copied from interface:IdGeneratorDecoratorGenerate a distributed ID by delegating to the actual generator.This default implementation delegates the ID generation to the actual wrapped generator, ensuring that decorators can focus on adding functionality rather than reimplementing basic generation.
- Specified by:
generatein interfaceIdGenerator- Specified by:
generatein interfaceIdGeneratorDecorator- Returns:
- A unique distributed ID as a long value
- Throws:
MachineIdLostException
-
stat
Description copied from interface:IdGeneratorDecoratorGet statistical information about this decorated ID generator.This method provides combined statistical information from both the decorator itself and the actual generator it wraps, as well as the ID converter being used. This gives a complete picture of the generator's state.
- Specified by:
statin interfaceIdGenerator- Specified by:
statin interfaceIdGeneratorDecorator- Specified by:
statin interfaceSnowflakeId- Specified by:
statin interfaceStatistical- Specified by:
statin interfaceStringIdGenerator- Returns:
- Statistical information about this decorated ID generator
-
layout
Description copied from interface:SnowflakeIdThe bit layout of the ids.- Specified by:
layoutin interfaceSnowflakeId- Returns:
- the layout
-
getLastTimestamp
public long getLastTimestamp()Description copied from interface:SnowflakeIdGet the timestamp of the last ID that was generated.This is used for clock synchronization and to ensure proper ordering of generated IDs. It can also help detect clock drift.
- Specified by:
getLastTimestampin interfaceSnowflakeId- Returns:
- The timestamp of the last generated ID
-
getLastTimestampAsMilliseconds
public long getLastTimestampAsMilliseconds()Description copied from interface:SnowflakeIdGet the last generated timestamp in milliseconds for clock synchronization.- Specified by:
getLastTimestampAsMillisecondsin interfaceSnowflakeId- Returns:
- The last generated timestamp in milliseconds
-
getMachineId
public int getMachineId()Description copied from interface:SnowflakeIdGet the machine ID assigned to this generator.This is the unique identifier for the machine or instance that is generating IDs, which ensures global uniqueness across the distributed system.
- Specified by:
getMachineIdin interfaceSnowflakeId- Returns:
- The machine ID
-