pub struct Session {
id: SessionId,
is_mcp: bool,
last_activity: Mutex<Instant>,
sender: UnboundedSender<SessionMessage>,
connection_count: AtomicU32,
shutdown_requested: AtomicBool,
pack_names: RwLock<BTreeMap<String, String>>,
jobs: Arc<JobRegistry>,
settings: RwLock<Arc<Settings>>,
queued: AtomicUsize,
diagnostics_check: Mutex<Option<DiagnosticsCheck>>,
}Expand description
A session represents a single client’s connection state.
Each session has its own background thread for processing commands, ensuring complete isolation between clients.
Fields§
§id: SessionIdUnique identifier for this session.
is_mcp: boolWhether this is the session of the MCP clients, removed by inactivity instead of by connection count.
last_activity: Mutex<Instant>Instant of the last command sent to this session’s background thread.
Only updated by Session::call, so it reflects actual work, not
transport-level pings.
sender: UnboundedSender<SessionMessage>Sender to communicate with this session’s background thread.
connection_count: AtomicU32Number of active connections using this session.
shutdown_requested: AtomicBoolWhether this session has been marked for shutdown.
pack_names: RwLock<BTreeMap<String, String>>Names of the packs currently open in this session, by pack key.
jobs: Arc<JobRegistry>Jobs of this session.
settings: RwLock<Arc<Settings>>Settings the session runs with. Behind an Arc so requests can hold them without copying.
queued: AtomicUsizeAmount of requests sent to the background thread that it hasn’t started yet.
diagnostics_check: Mutex<Option<DiagnosticsCheck>>The last diagnostics check requested, so a new one can replace it.
Implementations§
Source§impl Session
impl Session
Sourcepub fn new(id: SessionId, is_mcp: bool) -> Arc<Self> ⓘ
pub fn new(id: SessionId, is_mcp: bool) -> Arc<Self> ⓘ
Create a new session with its own background thread.
is_mcp marks the session of the MCP clients, which is removed by
inactivity instead of by connection count (see Session::is_mcp).
Sourcefn start_autosave_timer(session: &Arc<Self>)
fn start_autosave_timer(session: &Arc<Self>)
Starts the timer asking the background thread to autosave the changed packs, every autosave_interval minutes of the settings.
An interval of 0 disables autosaves. The timer stops when the session shuts down or is dropped.
Sourcepub fn last_activity(&self) -> Instant
pub fn last_activity(&self) -> Instant
Get the instant of the last command sent to this session.
Sourcepub fn disconnect(&self)
pub fn disconnect(&self)
Decrement the connection count.
Sourcepub fn connection_count(&self) -> u32
pub fn connection_count(&self) -> u32
Get the current connection count.
Sourcepub fn is_shutdown_requested(&self) -> bool
pub fn is_shutdown_requested(&self) -> bool
Check if shutdown has been requested.
Sourcepub fn pack_names(&self) -> Vec<String>
pub fn pack_names(&self) -> Vec<String>
Get the names of the packs open in this session.
Sourcepub fn set_pack_name(&self, pack_key: &str, name: &str)
pub fn set_pack_name(&self, pack_key: &str, name: &str)
Set the name of an open pack of this session, adding it if it’s not there yet.
Sourcepub fn remove_pack(&self, pack_key: &str)
pub fn remove_pack(&self, pack_key: &str)
Remove a pack from the open ones of this session.
Sourcepub fn jobs(&self) -> &Arc<JobRegistry> ⓘ
pub fn jobs(&self) -> &Arc<JobRegistry> ⓘ
Returns the jobs of this session.
Sourcefn configure(&self, request: RpcRequest) -> RpcResponse
fn configure(&self, request: RpcRequest) -> RpcResponse
Replaces the settings of this session, applying their telemetry choices to the whole process.
Sourcepub fn call(&self, request: RpcRequest) -> UnboundedReceiver<RpcResponse>
pub fn call(&self, request: RpcRequest) -> UnboundedReceiver<RpcResponse>
Send a request to this session’s background thread.
Configuration and job control requests are answered without waiting for the background thread, and jobs are answered right away with their ID, before they run.
Returns a receiver to get the response.
Sourcefn enqueue(
&self,
message: SessionMessage,
) -> Result<(), SendError<SessionMessage>>
fn enqueue( &self, message: SessionMessage, ) -> Result<(), SendError<SessionMessage>>
Sends a request to the background thread, counting it as queued until the thread starts it.
Sourcepub fn has_queued_requests(&self) -> bool
pub fn has_queued_requests(&self) -> bool
Returns if there are requests waiting for the background thread.
Sourcefn replace_diagnostics_check(&self, job: u64, request: RpcRequest) -> RpcRequest
fn replace_diagnostics_check(&self, job: u64, request: RpcRequest) -> RpcRequest
Makes a new diagnostics check replace the last one, if it hasn’t ended yet.
The new check also checks the paths the replaced one would have checked. A queued replaced check is
cancelled, and a running one is cancelled once it stops for the new one (see Self::requeue_diagnostics_check).
§Arguments
job- Job of the new check.request- Request of the new check.
§Returns
The request of the new check, with the paths of the replaced one added.
Sourcepub fn requeue_diagnostics_check(&self, job: u64, request: RpcRequest)
pub fn requeue_diagnostics_check(&self, job: u64, request: RpcRequest)
Queues again a diagnostics check that stopped to let other requests run, or cancels it if a newer one replaced it.
§Arguments
job- Job of the check.request- Request of the check.
Auto Trait Implementations§
impl !Freeze for Session
impl !RefUnwindSafe for Session
impl !UnwindSafe for Session
impl Send for Session
impl Sync for Session
impl Unpin for Session
impl UnsafeUnpin for Session
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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> 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 moreimpl<T> MaybeSend for T
impl<T> MaybeSync for T
§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
§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.