- All Implemented Interfaces:
AutoCloseable,IdGenerator
RangeStore (04-segment.md §2): one atomic increment on the hot
path, refills off the lock and single-flight, reservation size adapted to a time budget.
The hot path reads the current cursor once and takes a value from it. Only when the cursor is used up, expired or
closed does a caller take the switch lock (spinning briefly first, since another caller usually switches within
microseconds), move to the next ready range, and start a refill when the ready values fall below the lookahead
budget. The switch lock never covers I/O: reservations run on the refill executor, single-flight, and a caller with
no value left waits for the one in flight outside the lock, at most BatchPolicy.reserveTimeout(), or makes
it itself (still outside the lock) if the executor has not started it. A reservation that completes after its
waiters gave up still delivers its range. After a failed reservation no new one starts for a backoff that doubles
from 100ms up to 5s; meanwhile callers with no value left fail at once.
Its public constructors are the assembly entry CosIdRuntime uses (R2-core-03): they keep their signatures,
and a new parameter comes only through a builder or a static factory, never as one more positional overload
(api-freeze.md §4.2).
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe operationGeneratorListener.onStoreTimeout(java.lang.String, java.lang.String)reports when callers waited for a refill longer than the reserve timeout; a reserve call that hits the store's own timeout is reported asreserve. -
Constructor Summary
ConstructorsConstructorDescriptionSegmentGenerator(String name, String key, String storeName, RangeStore store, BatchPolicy policy, Executor refillExecutor, TimeSource time, GeneratorListener listener) A segment generator on a named store.SegmentGenerator(String name, String key, RangeStore store, BatchPolicy policy, Executor refillExecutor, TimeSource time, GeneratorListener listener) A segment generator. -
Method Summary
Modifier and TypeMethodDescriptionlongbatch()The size of the next reservation, fordescribe().voidclose()Stops issuing, cancels the refill in flight and drops the ready ranges (S4 allows the gap).longgenerate()Issues the next value.longheld()The values at hand, fordescribe().key()name()policy()
-
Field Details
-
RESERVE_WAIT
The operationGeneratorListener.onStoreTimeout(java.lang.String, java.lang.String)reports when callers waited for a refill longer than the reserve timeout; a reserve call that hits the store's own timeout is reported asreserve.- See Also:
-
-
Constructor Details
-
SegmentGenerator
public SegmentGenerator(String name, String key, RangeStore store, BatchPolicy policy, Executor refillExecutor, TimeSource time, GeneratorListener listener) A segment generator. It reserves nothing until the firstgenerate().- Parameters:
name- the generator name, for events and errorskey- the range keystore- the range storepolicy- the batch policyrefillExecutor- runs the reservations; the runtime's own executor by defaulttime- the time sourcelistener- the event listener
-
SegmentGenerator
public SegmentGenerator(String name, String key, String storeName, RangeStore store, BatchPolicy policy, Executor refillExecutor, TimeSource time, GeneratorListener listener) A segment generator on a named store. It reserves nothing until the firstgenerate().- Parameters:
name- the generator name, for events and errorskey- the range keystoreName- the store name, forGeneratorListener.onStoreTimeout(java.lang.String, java.lang.String)when a caller waits for a refill longer than the reserve timeoutstore- the range storepolicy- the batch policyrefillExecutor- runs the reservations; the runtime's own executor by defaulttime- the time sourcelistener- the event listener
-
-
Method Details
-
name
-
key
-
policy
-
generate
public long generate()Issues the next value.- Specified by:
generatein interfaceIdGenerator- Returns:
- the value
- Throws:
RangeUnavailableException- if no range arrives within the reserve timeout, or a refill is backing off after a failureRangeSealedException- if the key is sealedRangeExhaustedException- if the key has no values leftIllegalStateException- if the generator is closed
-
held
public long held()The values at hand, fordescribe().- Returns:
- the rest of the current range plus the ready ranges
-
batch
public long batch()The size of the next reservation, fordescribe().- Returns:
- the batch size the rate estimate gives now
-
close
public void close()Stops issuing, cancels the refill in flight and drops the ready ranges (S4 allows the gap). Closing again does nothing.- Specified by:
closein interfaceAutoCloseable
-