pub struct SessionManager {
sessions: Mutex<HashMap<SessionId, ManagedSession>>,
next_id: Mutex<SessionId>,
timeout: Duration,
}Expand description
Manages all active sessions.
Provides thread-safe access to create, retrieve, and remove sessions. Sessions persist for a configurable timeout after all clients disconnect.
Fields§
§sessions: Mutex<HashMap<SessionId, ManagedSession>>Map of session IDs to managed sessions.
next_id: Mutex<SessionId>Counter for generating unique session IDs.
timeout: DurationSession timeout duration.
Implementations§
Source§impl SessionManager
impl SessionManager
Sourcepub fn create_session(&self) -> Arc<Session>
pub fn create_session(&self) -> Arc<Session>
Create a new session and return a reference to it.
Sourcepub fn get_or_create_session(
&self,
session_id: Option<SessionId>,
) -> (Arc<Session>, bool)
pub fn get_or_create_session( &self, session_id: Option<SessionId>, ) -> (Arc<Session>, bool)
Get an existing session by ID, or create a new one if the ID doesn’t exist.
If session_id is Some, attempts to retrieve that session.
If the session doesn’t exist or session_id is None, creates a new session.
Returns the session and whether it was newly created.
Sourcepub fn get_session(&self, id: SessionId) -> Option<Arc<Session>>
pub fn get_session(&self, id: SessionId) -> Option<Arc<Session>>
Get a session by ID without incrementing the connection count.
Sourcepub fn client_disconnected(manager: Arc<Self>, id: SessionId)
pub fn client_disconnected(manager: Arc<Self>, id: SessionId)
Mark a session as disconnected by a client.
If no more clients are connected, starts the timeout countdown. The session will be removed after the timeout unless a client reconnects.
Sourcefn schedule_cleanup(manager: Arc<Self>, id: SessionId)
fn schedule_cleanup(manager: Arc<Self>, id: SessionId)
Schedule a cleanup check for a session after the timeout period.
Sourcepub fn cleanup_expired_sessions(&self)
pub fn cleanup_expired_sessions(&self)
Perform cleanup of expired sessions.
This should be called periodically or after timeout events.
Sourcepub fn remove_session(&self, id: SessionId) -> Option<Arc<Session>>
pub fn remove_session(&self, id: SessionId) -> Option<Arc<Session>>
Remove a session immediately.
Sourcepub fn session_count(&self) -> usize
pub fn session_count(&self) -> usize
Get the number of active sessions.
Sourcepub fn session_ids(&self) -> Vec<SessionId> ⓘ
pub fn session_ids(&self) -> Vec<SessionId> ⓘ
Get all active session IDs.
Sourcepub fn get_sessions_info(&self) -> Vec<SessionInfo>
pub fn get_sessions_info(&self) -> Vec<SessionInfo>
Get information about all active sessions.
Returns a vector of SessionInfo structs containing session state snapshots
for use by session management tools.
Sourcepub fn start_cleanup_task(manager: Arc<Self>)
pub fn start_cleanup_task(manager: Arc<Self>)
Start a background task that periodically cleans up expired sessions.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for SessionManager
impl RefUnwindSafe for SessionManager
impl Send for SessionManager
impl Sync for SessionManager
impl Unpin for SessionManager
impl UnsafeUnpin for SessionManager
impl UnwindSafe for SessionManager
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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.