- All Implemented Interfaces:
AutoCloseable,GroupedIdGenerator
SegmentGenerators, the current period's and
the next one's, at the store keys {key}/{period}.
The hot path reads the time once and compares it with a precomputed instant; before it, the id comes from the
current period's generator. From PeriodicPolicy.prewarm() before the period ends the next period's generator
is created and starts its first reservation, so that crossing the boundary needs no synchronous store call. At the
boundary the old period's generator is closed; its key is sealed only PeriodicPolicy.sealAfter() after the
period ended, on the refill executor. Periods only move forward: a generator never returns to a period it left, and a
sealed key fails with RangeSealedException rather than being recreated (S6).
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).
-
Constructor Summary
ConstructorsConstructorDescriptionPeriodicSegmentGenerator(String name, String key, String storeName, Period period, ZoneId zone, RangeStore store, BatchPolicy policy, PeriodicPolicy periodic, Executor refillExecutor, TimeSource time, GeneratorListener listener) A periodic segment generator on a named store.PeriodicSegmentGenerator(String name, String key, Period period, ZoneId zone, RangeStore store, BatchPolicy policy, PeriodicPolicy periodic, Executor refillExecutor, TimeSource time, GeneratorListener listener) A periodic segment generator. -
Method Summary
Modifier and TypeMethodDescriptionlongbatch()The size of the next reservation in the period being issued, fordescribe().voidclose()Closes the generators of the current and the next period.The period being issued, fordescribe().generate()Issues the next id of the current period.longheld()The values at hand in the period being issued, fordescribe().name()The generator name.
-
Constructor Details
-
PeriodicSegmentGenerator
public PeriodicSegmentGenerator(String name, String key, Period period, ZoneId zone, RangeStore store, BatchPolicy policy, PeriodicPolicy periodic, Executor refillExecutor, TimeSource time, GeneratorListener listener) A periodic segment generator. It reserves nothing until the firstgenerate().- Parameters:
name- the generator name, for events and errorskey- the range key the period keys are appended toperiod- the periodzone- the time zone the periods followstore- the range storepolicy- the batch policy of each periodperiodic- the periodic policyrefillExecutor- runs the reservationstime- the time sourcelistener- the event listener
-
PeriodicSegmentGenerator
public PeriodicSegmentGenerator(String name, String key, String storeName, Period period, ZoneId zone, RangeStore store, BatchPolicy policy, PeriodicPolicy periodic, Executor refillExecutor, TimeSource time, GeneratorListener listener) A periodic segment generator on a named store. It reserves nothing until the firstgenerate().- Parameters:
name- the generator name, for events and errorskey- the range key the period keys are appended tostoreName- the store name, forGeneratorListener.onStoreTimeout(java.lang.String, java.lang.String)when a caller waits for a refill longer than the reserve timeoutperiod- the periodzone- the time zone the periods followstore- the range storepolicy- the batch policy of each periodperiodic- the periodic policyrefillExecutor- runs the reservationstime- the time sourcelistener- the event listener
-
-
Method Details
-
name
The generator name.- Returns:
- the name
-
generate
Issues the next id of the current period.- Specified by:
generatein interfaceGroupedIdGenerator- Returns:
- the id with its period
- Throws:
RangeSealedException- if the period's key is already sealed (a lagging clock)RangeUnavailableException- if the period's generator has no range in timeIllegalStateException- if the generator is closed
-
currentPeriod
The period being issued, fordescribe().- Returns:
- the period key, empty before the first id
-
held
public long held()The values at hand in the period being issued, fordescribe().- Returns:
- the rest of its current range plus its ready ranges; 0 before the first id
-
batch
public long batch()The size of the next reservation in the period being issued, fordescribe().- Returns:
- the batch size the rate estimate gives now; the step before the first id
-
close
public void close()Closes the generators of the current and the next period. Keys not sealed yet stay unsealed. Closing again does nothing.- Specified by:
closein interfaceAutoCloseable
-