Interface SegmentId

All Superinterfaces:
IdGenerator, Statistical, StringIdGenerator
All Known Implementing Classes:
DefaultSegmentId, SegmentChainId, StringSegmentId

public interface SegmentId extends IdGenerator
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:

  1. Request a segment (block of IDs) from a central distributor
  2. Generate IDs locally within that segment
  3. 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)

SegmentId

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    The default step size for segment allocation (1 ID at a time).
  • Method Summary

    Modifier and Type
    Method
    Description
    Get the current ID segment being used for generation.
    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_STEP
      The 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

      default IdGeneratorStat 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 interface IdGenerator
      Specified by:
      stat in interface Statistical
      Returns:
      Statistical information about this Segment ID generator