Package me.ahoo.cosid.snowflake
Class StringSnowflakeId
java.lang.Object
me.ahoo.cosid.StringIdGeneratorDecorator
me.ahoo.cosid.snowflake.StringSnowflakeId
- All Implemented Interfaces:
Decorator<IdGenerator>,IdGenerator,IdGeneratorDecorator,SnowflakeId,Statistical,StringIdGenerator
- Direct Known Subclasses:
DefaultSnowflakeFriendlyId
String-based SnowflakeId wrapper.
Wraps a SnowflakeId with a string converter for generating string-based IDs while maintaining SnowflakeId properties.
-
Field Summary
Fields inherited from class me.ahoo.cosid.StringIdGeneratorDecorator
actual, idConverterFields inherited from interface me.ahoo.cosid.snowflake.SnowflakeId
TOTAL_BIT -
Constructor Summary
ConstructorsConstructorDescriptionStringSnowflakeId(SnowflakeId actual, IdConverter idConverter) Creates a new StringSnowflakeId. -
Method Summary
Modifier and TypeMethodDescriptionlongGet the timestamp of the last ID that was generated.longGet the last generated timestamp in milliseconds for clock synchronization.intGet the machine ID assigned to this generator.layout()The bit layout of the ids.stat()Get statistical information about this Snowflake ID generator.Methods inherited from class me.ahoo.cosid.StringIdGeneratorDecorator
getActual, idConverterMethods 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.IdGeneratorDecorator
generateMethods inherited from interface me.ahoo.cosid.snowflake.SnowflakeId
getEpoch, getMachineBit, getMaxMachineId, getMaxSequence, getMaxTimestamp, getSequenceBit, getTimestampBit, isSafeJavascript
-
Constructor Details
-
StringSnowflakeId
Creates a new StringSnowflakeId.- Parameters:
actual- the underlying SnowflakeIdidConverter- the converter for string generation
-
-
Method Details
-
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
-
stat
Description copied from interface:SnowflakeIdGet statistical information about this Snowflake ID generator.This method provides detailed information about the generator's configuration and current state, including all the key parameters that define its behavior.
- 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 Snowflake ID generator
-