java.lang.Object
me.ahoo.cosid.internal.RangeCursor
- Direct Known Subclasses:
ExpiringRangeCursor
The range a segment generator issues from (04-segment.md ยง2.1): one atomic increment and one comparison per value.
The counter keeps counting past end: a value at or past the end is never issued. A cursor is only ever
incremented by the threads that read it while it was the generator's current cursor, so it passes its end by at most
the number of such threads; of(long, long) keeps every end HEADROOM below Long.MAX_VALUE so the
counter never wraps around into issuable values.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final longValues within this distance ofLong.MAX_VALUEare never issued (a gap, which D19 allows). -
Constructor Summary
ConstructorsConstructorDescriptionRangeCursor(long next, long end) A cursor on[next, end), unchecked: also the empty and closed sentinels. -
Method Summary
Modifier and TypeMethodDescriptionstatic longcap(long end) longend()static RangeCursorof(long start, long end) longremaining(long nowMillis) The values not taken yet.longtake()Takes the next value.longuntaken()The values not taken yet, ignoring expiry.booleanusable(long nowMillis) Whether a value is left atnowMillis.
-
Field Details
-
HEADROOM
public static final long HEADROOMValues within this distance ofLong.MAX_VALUEare never issued (a gap, which D19 allows).- See Also:
-
-
Constructor Details
-
RangeCursor
public RangeCursor(long next, long end) A cursor on[next, end), unchecked: also the empty and closed sentinels.- Parameters:
next- the first valueend- the end, exclusive
-
-
Method Details
-
of
- Parameters:
start- the first valueend- the end, exclusive- Returns:
- the cursor, or null if nothing of the range is left after the cap
-
cap
public static long cap(long end) - Parameters:
end- the end of a range- Returns:
- the end a cursor may issue up to
-
take
public long take()Takes the next value.- Returns:
- the value, or
-1if the cursor is used up (or expired)
-
untaken
public long untaken()The values not taken yet, ignoring expiry.- Returns:
end - next, at least 0
-
end
public long end() -
remaining
public long remaining(long nowMillis) The values not taken yet.- Parameters:
nowMillis- the current time- Returns:
- the values left, 0 if none or expired
-
usable
public boolean usable(long nowMillis) Whether a value is left atnowMillis.- Parameters:
nowMillis- the current time- Returns:
- true if
take()may still return a value
-