Interface IdGenerator
- All Superinterfaces:
Statistical,StringIdGenerator
- All Known Subinterfaces:
CosIdGenerator,IdGeneratorDecorator,SegmentId,SnowflakeFriendlyId,SnowflakeId
- All Known Implementing Classes:
AbstractSnowflakeId,AtomicLongGenerator,ClockSyncCosIdGenerator,ClockSyncSnowflakeId,DefaultSegmentId,DefaultSnowflakeFriendlyId,FriendlyCosIdGenerator,LazyIdGenerator,MillisecondSnowflakeId,MockIdGenerator,Radix36CosIdGenerator,Radix62CosIdGenerator,RadixCosIdGenerator,SecondSnowflakeId,SegmentChainId,StringIdGeneratorDecorator,StringSegmentId,StringSnowflakeId,UncertaintyIdGenerator,UuidGenerator
This is the core interface for generating distributed IDs in the CosId library. It provides two primary methods for ID generation:
generate()- Generates a numeric ID as a long valuegenerateAsString()- Generates a string representation of the ID
The interface extends StringIdGenerator to provide string ID generation
capabilities and Statistical to provide statistical information about
the generator's state.
Implementations of this interface are expected to be thread-safe and can be used concurrently across multiple threads.
-
Method Summary
Modifier and TypeMethodDescriptionlonggenerate()Generate a distributed ID as a long value.default StringGenerate a distributed ID as a string value.default IdConverterGet the ID converter used to convertlongtype IDs toString.default IdGeneratorStatstat()Get statistical information about this ID generator.
-
Method Details
-
idConverter
Get the ID converter used to convertlongtype IDs toString.By default, this returns
Radix62IdConverter.PAD_STARTwhich converts long IDs to radix-62 string representations with padding to ensure consistent string lengths.- Returns:
- ID converter for transforming numeric IDs to string format
-
generate
long generate()Generate a distributed ID as a long value.This method generates a unique numeric identifier that is guaranteed to be unique within the distributed system. The exact algorithm used depends on the implementation (e.g., Snowflake, Segment, CosId).
- Returns:
- A unique distributed ID as a long value
-
generateAsString
Generate a distributed ID as a string value.This method generates a unique string identifier by first generating a numeric ID via
generate()and then converting it to a string using the configuredidConverter().- Specified by:
generateAsStringin interfaceStringIdGenerator- Returns:
- A unique distributed ID as a string value
-
stat
Get statistical information about this ID generator.This method provides insights into the generator's current state, including implementation details and converter statistics. This is useful for monitoring and debugging purposes.
- Specified by:
statin interfaceStatistical- Returns:
- Statistical information about this ID generator
-