Class MergedIdSegment
- All Implemented Interfaces:
Comparable<IdSegment>,Grouped,IdSegment
-
Field Summary
Fields inherited from interface me.ahoo.cosid.segment.IdSegment
SEQUENCE_OVERFLOW, TIME_TO_LIVE_FOREVER -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionlongID segment fetch time.longgetMaxId()Get the maximum ID in this segment.longGet the offset (starting ID) of this segment.intlongGet the current sequence number within this segment.longlonggetStep()Get the step size for ID allocation.longgetTtl()Get the time-to-live for this segment.group()longAtomically increment the sequence and return the new value.toString()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface me.ahoo.cosid.segment.IdSegment
compareTo, ensureNextIdSegment, isAvailable, isExpired, isOverflow, isOverflow
-
Constructor Details
-
MergedIdSegment
-
-
Method Details
-
group
-
getSegments
public int getSegments() -
getSingleStep
public long getSingleStep() -
getFetchTime
public long getFetchTime()ID segment fetch time. unitTimeUnit.MILLISECONDS- Specified by:
getFetchTimein interfaceIdSegment- Returns:
- Fetch Time
-
getMaxId
public long getMaxId()Description copied from interface:IdSegmentGet 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.
-
getOffset
public long getOffset()Description copied from interface:IdSegmentGet 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.
-
getSequence
public long getSequence()Description copied from interface:IdSegmentGet the current sequence number within this segment.This represents the next ID that will be allocated from this segment, or
IdSegment.SEQUENCE_OVERFLOWif the segment has been exhausted.- Specified by:
getSequencein interfaceIdSegment- Returns:
- The current sequence number
-
getStep
public long getStep()Description copied from interface:IdSegmentGet 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.
-
getTtl
public long getTtl()Description copied from interface:IdSegmentGet 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_FOREVERindicates the segment never expires.Unit:
TimeUnit.SECONDS -
incrementAndGet
public long incrementAndGet()Description copied from interface:IdSegmentAtomically 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:
incrementAndGetin interfaceIdSegment- Returns:
- The next allocated ID, or
IdSegment.SEQUENCE_OVERFLOWif exhausted
-
toString
-