Package me.ahoo.cosid.segment
Interface SegmentId
- All Superinterfaces:
IdGenerator
,Statistical
,StringIdGenerator
- All Known Implementing Classes:
DefaultSegmentId
,SegmentChainId
,StringSegmentId
Segment algorithm ID generator.
This interface implements a segment-based ID generation algorithm that works by allocating contiguous blocks (segments) of IDs from a central authority. Each segment contains:
- A range of IDs (offset to max ID)
- A sequence counter to track usage within the segment
- Metadata for expiration and availability
The segment algorithm works as follows:
- Request a segment (block of IDs) from a central distributor
- Generate IDs locally within that segment
- When the segment is exhausted, request a new segment
This approach provides:
- High throughput (local generation within segments)
- Global uniqueness (central coordination for segments)
- Resilience (continues working if distributor is temporarily unavailable)
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
The default step size for segment allocation (1 ID at a time). -
Method Summary
Modifier and TypeMethodDescriptioncurrent()
Get the current ID segment being used for generation.default IdGeneratorStat
stat()
Get statistical information about this Segment ID generator.Methods inherited from interface me.ahoo.cosid.IdGenerator
generate, generateAsString, idConverter
-
Field Details
-
ONE_STEP
static final int ONE_STEPThe default step size for segment allocation (1 ID at a time).This constant represents the minimum allocation unit for IDs, typically used when requesting individual IDs rather than segments.
- See Also:
-
-
Method Details
-
current
IdSegment current()Get 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.
- Returns:
- The current ID segment
-
stat
Get statistical information about this Segment ID generator.This method provides detailed information about the generator's current state, including segment metadata and availability status.
- Specified by:
stat
in interfaceIdGenerator
- Specified by:
stat
in interfaceStatistical
- Returns:
- Statistical information about this Segment ID generator
-