RenewalManager

Struct RenewalManager 

Source
pub struct RenewalManager { /* private fields */ }
Expand description

Callback invoked by the manager to actually perform a renewal.

The manager itself does not hold lease objects; callers provide a renew_fn closure to tick_with that performs the renewal and returns the new expires_at timestamp on success.

Alternatively, use tick for a simpler API that auto-renews by extending expires_at by policy.min_renew_secs.

Implementations§

Source§

impl RenewalManager

Source

pub fn new() -> Self

Create an empty manager with no registered leases.

Source

pub fn register( &mut self, lease_id: u128, expires_at: u64, policy: RenewalPolicy, )

Register a lease for managed renewal.

created_at is inferred as expires_at - policy.min_renew_secs (clamped to 0). For precise control, use register_with_created_at.

Source

pub fn register_with_created_at( &mut self, lease_id: u128, created_at: u64, expires_at: u64, policy: RenewalPolicy, )

Register a lease with an explicit creation timestamp.

Source

pub fn unregister(&mut self, lease_id: u128)

Unregister a lease.

Source

pub fn len(&self) -> usize

Number of leases currently managed.

Source

pub fn is_empty(&self) -> bool

Returns true if no leases are managed.

Source

pub fn tick(&mut self, now_unix_secs: u64) -> RenewalSummary

Drive renewals using a simple model: if a lease is due, extend expires_at by policy.min_renew_secs. This is suitable when the manager owns the lease state (e.g. testing or self-contained use).

Source

pub fn tick_with<F>( &mut self, now_unix_secs: u64, renew_fn: F, ) -> RenewalSummary
where F: FnMut(u128, u64) -> Result<u64, ()>,

Drive renewals with a caller-provided renewal function.

renew_fn(lease_id, duration_secs) should attempt the actual renewal and return the new expires_at on success, or an error.

Source

pub fn is_near_expiry(&self, lease_id: u128, now: u64) -> bool

Returns true if the given lease is near expiry (< 10% TTL remaining).

Source

pub fn on_revoked<F: Fn(u128, u8) + 'static>(&mut self, callback: F)

Register a callback invoked when a lease is revoked (e.g. via WITHDRAW cleanup or REVOKE_BROADCAST).

The callback receives the lease ID and a reason code (0 = unknown/timeout).

Source

pub fn notify_revoked(&self, lease_id: u128, reason: u8)

Notify all registered revocation callbacks for the given lease.

reason is the WITHDRAW reason code (0 = timeout/unknown).

Source

pub fn expires_at(&self, lease_id: u128) -> Option<u64>

Returns the current expires_at for a managed lease, if registered.

Trait Implementations§

Source§

impl Default for RenewalManager

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.