Class StaticSlot

java.lang.Object
me.ahoo.cosid.lease.StaticSlot
All Implemented Interfaces:
AutoCloseable, SlotHandle

public final class StaticSlot extends Object implements SlotHandle, AutoCloseable
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 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 bits
      stateFile - the window file; none means no clock regression protection
      ahead - how far ahead the ceiling is written; default 10s
      notBefore - the floor when the file does not exist yet (given by the migration tool)
      executor - runs the asynchronous rewrites of the ceiling
      time - 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

      public SlotBinding current()
      Description copied from interface: SlotHandle
      The current binding: one volatile read. A generator reads it once per id.
      Specified by:
      current in interface SlotHandle
      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:
      close in interface AutoCloseable