java.lang.Object
me.ahoo.cosid.lease.StaticSlot
- All Implemented Interfaces:
AutoCloseable,SlotHandle
A slot the user keeps unique (manual or StatefulSet ordinal), with a time window from a local file
(05-machine-lease.md §4.4): the file holds the ceiling, written ahead and fsynced before use, so a crash followed by
a clock regression cannot repeat ids. Without a file there is no regression protection.
With a file, one long-lived task on the executor writes the ceiling ahead again whenever less than
ahead/2 of the window is left; the executor must run tasks asynchronously.
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
ConstructorsConstructorDescriptionStaticSlot(int slot, int bits, Optional<Path> stateFile, Duration ahead, Optional<Instant> notBefore, Executor executor, TimeSource time) A static slot;start()reads the window. -
Method Summary
Modifier and TypeMethodDescriptionintbits()voidclose()Stops extending the window; the ceiling written ahead stays in the file.voidclose(long lastIssued) Writes the exact last issued timestamp as the ceiling, so the next start begins right after it.current()The current binding: one volatile read.intslot()voidstart()Reads the floor from the file and writes the first ceiling ahead.
-
Constructor Details
-
StaticSlot
public StaticSlot(int slot, int bits, Optional<Path> stateFile, Duration ahead, Optional<Instant> notBefore, Executor executor, TimeSource time) A static slot;start()reads the window.- Parameters:
slot- the slot, in[0, 2^bits)bits- the slot bitsstateFile- the window file; none means no clock regression protectionahead- how far ahead the ceiling is written; default 10snotBefore- the floor when the file does not exist yet (given by the migration tool)executor- runs the asynchronous rewrites of the ceilingtime- the time source
-
-
Method Details
-
slot
public int slot() -
bits
public int bits() -
start
public void start()Reads the floor from the file and writes the first ceiling ahead. -
current
Description copied from interface:SlotHandleThe current binding: one volatile read. A generator reads it once per id.- Specified by:
currentin interfaceSlotHandle- Returns:
- the binding
-
close
public void close(long lastIssued) Writes the exact last issued timestamp as the ceiling, so the next start begins right after it.- Parameters:
lastIssued- the largest timestamp issued on the slot, in milliseconds
-
close
public void close()Stops extending the window; the ceiling written ahead stays in the file.- Specified by:
closein interfaceAutoCloseable
-