pub struct SessionLock { /* private fields */ }Expand description
Represents a lock on a session for exclusive message processing.
A session lock ensures that only one consumer can process messages from a session at a time, maintaining FIFO ordering guarantees. Locks have an expiration time and can be renewed to extend processing time.
§Design
- Expiration: Locks automatically expire after a timeout period
- Renewal: Locks can be renewed before expiration to extend processing
- Owner Tracking: Each lock tracks which consumer owns it
- Timeout Handling: Expired locks can be acquired by other consumers
§Example
use queue_runtime::sessions::SessionLock;
use queue_runtime::message::SessionId;
use std::time::Duration;
let session_id = SessionId::new("user-123".to_string()).unwrap();
let lock = SessionLock::new(session_id.clone(), "consumer-1".to_string(), Duration::from_secs(30));
assert!(!lock.is_expired());
assert_eq!(lock.owner(), "consumer-1");Implementations§
Source§impl SessionLock
impl SessionLock
Sourcepub fn session_id(&self) -> &SessionId
pub fn session_id(&self) -> &SessionId
Get the session ID this lock is for.
Sourcepub fn acquired_at(&self) -> Instant
pub fn acquired_at(&self) -> Instant
Get when this lock was acquired.
Sourcepub fn expires_at(&self) -> Instant
pub fn expires_at(&self) -> Instant
Get when this lock expires.
Sourcepub fn lock_duration(&self) -> Duration
pub fn lock_duration(&self) -> Duration
Get the configured lock duration.
Sourcepub fn is_expired(&self) -> bool
pub fn is_expired(&self) -> bool
Sourcepub fn time_remaining(&self) -> Duration
pub fn time_remaining(&self) -> Duration
Get the remaining time before this lock expires.
§Returns
Duration until expiration, or zero if already expired
Trait Implementations§
Source§impl Clone for SessionLock
impl Clone for SessionLock
Source§fn clone(&self) -> SessionLock
fn clone(&self) -> SessionLock
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for SessionLock
impl RefUnwindSafe for SessionLock
impl Send for SessionLock
impl Sync for SessionLock
impl Unpin for SessionLock
impl UnsafeUnpin for SessionLock
impl UnwindSafe for SessionLock
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more