Class MergedIdSegment

java.lang.Object
me.ahoo.cosid.segment.MergedIdSegment
All Implemented Interfaces:
Comparable<IdSegment>, Grouped, IdSegment

public class MergedIdSegment extends Object implements IdSegment
Merged IdSegment.
  • Constructor Details

    • MergedIdSegment

      public MergedIdSegment(int segments, IdSegment idSegment)
  • Method Details

    • group

      public GroupedKey group()
      Specified by:
      group in interface Grouped
    • getSegments

      public int getSegments()
    • getSingleStep

      public long getSingleStep()
    • getFetchTime

      public long getFetchTime()
      ID segment fetch time. unit TimeUnit.MILLISECONDS
      Specified by:
      getFetchTime in interface IdSegment
      Returns:
      Fetch Time
    • getMaxId

      public long getMaxId()
      Description copied from interface: IdSegment
      Get the maximum ID in this segment.

      This is the upper bound of the ID range allocated to this segment. IDs generated from this segment will not exceed this value.

      Specified by:
      getMaxId in interface IdSegment
      Returns:
      The maximum ID in this segment
    • getOffset

      public long getOffset()
      Description copied from interface: IdSegment
      Get the offset (starting ID) of this segment.

      This is the lower bound of the ID range allocated to this segment. The first ID generated from this segment will typically be this value or slightly higher depending on the step size.

      Specified by:
      getOffset in interface IdSegment
      Returns:
      The offset of this segment
    • getSequence

      public long getSequence()
      Description copied from interface: IdSegment
      Get the current sequence number within this segment.

      This represents the next ID that will be allocated from this segment, or IdSegment.SEQUENCE_OVERFLOW if the segment has been exhausted.

      Specified by:
      getSequence in interface IdSegment
      Returns:
      The current sequence number
    • getStep

      public long getStep()
      Description copied from interface: IdSegment
      Get the step size for ID allocation.

      This determines how much the sequence number is incremented each time an ID is allocated. A step size of 1 allocates consecutive IDs, while larger step sizes can be used for sharding or other purposes.

      Specified by:
      getStep in interface IdSegment
      Returns:
      The step size for ID allocation
    • getTtl

      public long getTtl()
      Description copied from interface: IdSegment
      Get the time-to-live for this segment.

      This determines how long the segment remains valid before it should be refreshed or replaced. A value of IdSegment.TIME_TO_LIVE_FOREVER indicates the segment never expires.

      Unit: TimeUnit.SECONDS

      Specified by:
      getTtl in interface IdSegment
      Returns:
      The time-to-live in seconds
    • incrementAndGet

      public long incrementAndGet()
      Description copied from interface: IdSegment
      Atomically increment the sequence and return the new value.

      This method provides thread-safe allocation of the next ID from this segment. If the segment has been exhausted, it returns IdSegment.SEQUENCE_OVERFLOW.

      Specified by:
      incrementAndGet in interface IdSegment
      Returns:
      The next allocated ID, or IdSegment.SEQUENCE_OVERFLOW if exhausted
    • toString

      public String toString()
      Overrides:
      toString in class Object