java.lang.Object
me.ahoo.cosid.lease.LeaseKeeper
- All Implemented Interfaces:
AutoCloseable,SlotHandle
Holds the slot lease of a runtime (05-machine-lease.md §4.2): acquires it at
start(), renews it every
ttl/3 with backoff, re-acquires a lost slot and publishes each holding as a SlotBinding.
The renewals run in one long-lived task on the executor, which must run tasks asynchronously (the runtime's default runs each on a virtual thread). Their schedule follows elapsed time, not the wall clock, so a clock step does not delay a renewal.
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
ConstructorsConstructorDescriptionLeaseKeeper(SlotLeaseStore store, String namespace, Owner owner, int bits, Duration ttl, Duration tolerance, int slotOffset, OptionalInt preferredSlot, Duration acquireTimeout, Executor executor, TimeSource time, GeneratorListener listener) A lease keeper of a namespace with a slot offset (api-freeze.md §2.1.1);start()acquires the slot.LeaseKeeper(SlotLeaseStore store, String namespace, Owner owner, int bits, Duration ttl, Duration tolerance, OptionalInt preferredSlot, Duration acquireTimeout, Executor executor, TimeSource time, GeneratorListener listener) A lease keeper;start()acquires the slot. -
Method Summary
Modifier and TypeMethodDescriptionintbits()The slot bits: the namespace holds2^bitsslots.voidclose()Stops renewing and releases the lease as if issued up to its ceiling, for a slot no generator used.voidclose(long lastIssued) Stops renewing and releases the lease with the exact last issued timestamp (§4.3).current()The current binding: one volatile read.lease()The lease as last returned by the store.The namespace the slot is leased in.owner()The owner the slot is leased for.voidstart()Acquires the slot and starts renewing it.
-
Constructor Details
-
LeaseKeeper
public LeaseKeeper(SlotLeaseStore store, String namespace, Owner owner, int bits, Duration ttl, Duration tolerance, OptionalInt preferredSlot, Duration acquireTimeout, Executor executor, TimeSource time, GeneratorListener listener) A lease keeper;start()acquires the slot.- Parameters:
store- the lease storenamespace- the namespaceowner- the owner, with this runtime's incarnationbits- the slots are[0, 2^bits)ttl- the lease time to live; default 30stolerance- the ceiling lies this far beyond the expiry (D20); default 1spreferredSlot- the slot to try firstacquireTimeout- how longstart()retries an exhausted namespace; defaultttlexecutor- runs the renewals; the runtime's own executor by defaulttime- the time sourcelistener- the event listener
-
LeaseKeeper
public LeaseKeeper(SlotLeaseStore store, String namespace, Owner owner, int bits, Duration ttl, Duration tolerance, int slotOffset, OptionalInt preferredSlot, Duration acquireTimeout, Executor executor, TimeSource time, GeneratorListener listener) A lease keeper of a namespace with a slot offset (api-freeze.md §2.1.1);start()acquires the slot.- Parameters:
store- the lease storenamespace- the namespaceowner- the owner, with this runtime's incarnationbits- the slots are[0, 2^bits)ttl- the lease time to livetolerance- the ceiling lies this far beyond the expiry (D20)slotOffset- recorded in the namespace metadata; the generators add it to the slotpreferredSlot- the slot to try firstacquireTimeout- how longstart()retries an exhausted namespaceexecutor- runs the renewalstime- the time sourcelistener- the event listener
-
-
Method Details
-
namespace
The namespace the slot is leased in.- Returns:
- the namespace
-
owner
The owner the slot is leased for.- Returns:
- the owner
-
bits
public int bits()The slot bits: the namespace holds2^bitsslots.- Returns:
- the bits
-
start
public void start()Acquires the slot and starts renewing it.- Throws:
CosIdException- if no slot is acquired within the acquire timeout
-
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
-
lease
The lease as last returned by the store.- Returns:
- the lease, or empty before the first acquisition and after release
-
close
public void close(long lastIssued) Stops renewing and releases the lease with the exact last issued timestamp (§4.3). Call it once every generator on the slot is closed.- Parameters:
lastIssued- the largest timestamp issued on the slot, in milliseconds
-
close
public void close()Stops renewing and releases the lease as if issued up to its ceiling, for a slot no generator used.- Specified by:
closein interfaceAutoCloseable
-