pub struct SessionRegistry { /* private fields */ }Expand description
Session registry:
session_key -> Connectionuser_key -> {session_key...}tenant_id -> count(Atomic)
Implementations§
Source§impl SessionRegistry
impl SessionRegistry
pub fn new() -> SessionRegistry
Sourcepub fn try_insert(
&self,
tenant_id: String,
user_key: String,
session_key: String,
conn: Connection,
max_total: u64,
) -> Result<(), WsPrismError>
pub fn try_insert( &self, tenant_id: String, user_key: String, session_key: String, conn: Connection, max_total: u64, ) -> Result<(), WsPrismError>
Insert a session while enforcing a tenant-wide cap (best-effort).
Concurrency note: For throughput, this uses lock-free atomics plus an
optimistic increment/check pattern. Under extreme contention, a small
temporary overshoot of max_total is possible before the counter is
corrected. This is an intentional trade-off to avoid global locks.
pub fn remove_session( &self, user_key: &str, session_key: &str, ) -> Option<Connection>
pub fn get_session(&self, session_key: &str) -> Option<Connection>
pub fn get_user_sessions(&self, user_key: &str) -> Vec<Connection>
pub fn count_user_sessions(&self, user_key: &str) -> usize
pub fn count_tenant_sessions(&self, tenant_id: &str) -> u64
Sourcepub fn all_sessions(&self) -> Vec<(String, Connection)>
pub fn all_sessions(&self) -> Vec<(String, Connection)>
Snapshot of all active sessions.
Returns a vector of (session_key, Connection). Intended for best-effort shutdown/draining logic.
pub fn len_sessions(&self) -> usize
Sourcepub fn evict_oldest(&self, user_key: &str) -> Option<(String, Connection)>
pub fn evict_oldest(&self, user_key: &str) -> Option<(String, Connection)>
Evict the oldest session for this user. Returns (victim_session_key, victim_connection).
Trait Implementations§
Source§impl Default for SessionRegistry
impl Default for SessionRegistry
Source§fn default() -> SessionRegistry
fn default() -> SessionRegistry
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl !Freeze for SessionRegistry
impl !RefUnwindSafe for SessionRegistry
impl Send for SessionRegistry
impl Sync for SessionRegistry
impl Unpin for SessionRegistry
impl UnwindSafe for SessionRegistry
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