The state of a binding is one long, time << seqBits | seq of the last issued id, next to that
binding (TimeSequencer.Bound). A new binding of the slot swaps in a new Bound, which resets the sequence; the
replaced state is retired to CLOSED. close() swaps in a terminal Bound and retires the
last state, which gives the exact last issued time.
Issuing is a short critical section: read the binding and the time, check the window, compute and publish the state. Nothing waits inside it (01 §2.1): an attempt that has to wait (sequence exhausted, clock regression, slot floor, renewal at the ceiling) returns, the lock is released, the thread waits, then retries. Listener calls happen outside the lock too. A lock beats a CAS loop here: under contention the lock keeps the state in one core's cache while it issues, where every lost CAS moves it (benchmark P1, 16 threads).
-
Constructor Summary
ConstructorsConstructorDescriptionTimeSequencer(String name, Layout layout, SlotHandle slot, int nodeOffset, TimeSource time, ClockRegressionPolicy regression, GeneratorListener listener) A sequencer whose node is the slot plus an offset (api-freeze.md §2.1.1).TimeSequencer(String name, Layout layout, SlotHandle slot, TimeSource time, ClockRegressionPolicy regression, GeneratorListener listener) A sequencer. -
Method Summary
-
Constructor Details
-
TimeSequencer
public TimeSequencer(String name, Layout layout, SlotHandle slot, TimeSource time, ClockRegressionPolicy regression, GeneratorListener listener) A sequencer.- Parameters:
name- the generator namelayout- the id layoutslot- the machine slottime- the time sourceregression- the clock regression policylistener- the event listener
-
TimeSequencer
public TimeSequencer(String name, Layout layout, SlotHandle slot, int nodeOffset, TimeSource time, ClockRegressionPolicy regression, GeneratorListener listener) A sequencer whose node is the slot plus an offset (api-freeze.md §2.1.1).- Parameters:
name- the generator namelayout- the id layoutslot- the machine slotnodeOffset- added to the slot to give the node of the ids, not negativetime- the time sourceregression- the clock regression policylistener- the event listener
-
-
Method Details
-
nextId
public long nextId()Issues the next id; the layout must fit along.- Returns:
- the id
-
nextParts
Issues the next id as parts.- Returns:
- the parts
-
slot
public int slot()The slot of the current binding.- Returns:
- the slot
-
lastIssuedMillis
public long lastIssuedMillis()The time of the last issued id.- Returns:
- milliseconds since the Unix epoch, 0 when none was issued; exact once
close()returned
-
close
public void close()Moves the sequencer to its terminal state: no id is issued once this returns.
-