Package me.ahoo.cosid.segment
Class DefaultSegmentId
java.lang.Object
me.ahoo.cosid.segment.DefaultSegmentId
- All Implemented Interfaces:
IdGenerator,SegmentId,Statistical,StringIdGenerator
Default segment algorithm ID generator.
Provides thread-safe ID generation using a segment-based approach. Allocates ID segments from a central distributor and generates IDs locally within each segment for high throughput.
-
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultSegmentId(long idSegmentTtl, IdSegmentDistributor maxIdDistributor) Creates a generator with specified segment TTL.DefaultSegmentId(IdSegmentDistributor maxIdDistributor) Creates a generator with infinite segment TTL. -
Method Summary
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, idConverter
-
Constructor Details
-
DefaultSegmentId
Creates a generator with infinite segment TTL.- Parameters:
maxIdDistributor- the segment distributor
-
DefaultSegmentId
Creates a generator with specified segment TTL.- Parameters:
idSegmentTtl- segment time-to-live in secondsmaxIdDistributor- the segment distributor
-
-
Method Details
-
current
Description copied from interface:SegmentIdGet the current ID segment being used for generation.This method returns the segment from which IDs are currently being allocated. The segment contains the range of available IDs and tracks the current position within that range.
-
generate
public long generate()Description copied from interface:IdGeneratorGenerate 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).
- Specified by:
generatein interfaceIdGenerator- Returns:
- A unique distributed ID as a long value
-