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
impl RenewalManager
Sourcepub fn register(
&mut self,
lease_id: u128,
expires_at: u64,
policy: RenewalPolicy,
)
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.
Sourcepub fn register_with_created_at(
&mut self,
lease_id: u128,
created_at: u64,
expires_at: u64,
policy: RenewalPolicy,
)
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.
Sourcepub fn unregister(&mut self, lease_id: u128)
pub fn unregister(&mut self, lease_id: u128)
Unregister a lease.
Sourcepub fn tick(&mut self, now_unix_secs: u64) -> RenewalSummary
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).
Sourcepub fn tick_with<F>(
&mut self,
now_unix_secs: u64,
renew_fn: F,
) -> RenewalSummary
pub fn tick_with<F>( &mut self, now_unix_secs: u64, renew_fn: F, ) -> RenewalSummary
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.
Sourcepub fn is_near_expiry(&self, lease_id: u128, now: u64) -> bool
pub fn is_near_expiry(&self, lease_id: u128, now: u64) -> bool
Returns true if the given lease is near expiry (< 10% TTL remaining).
Sourcepub fn on_revoked<F: Fn(u128, u8) + 'static>(&mut self, callback: F)
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).
Sourcepub fn notify_revoked(&self, lease_id: u128, reason: u8)
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).
Sourcepub fn expires_at(&self, lease_id: u128) -> Option<u64>
pub fn expires_at(&self, lease_id: u128) -> Option<u64>
Returns the current expires_at for a managed lease, if registered.