pub struct ServerRuntime { /* private fields */ }Expand description
Server-side runtime: owns the transport, tracks live sessions and worker threads, and records connection and message counters.
Implementations§
Source§impl ServerRuntime
impl ServerRuntime
Sourcepub fn new(
transport: Arc<dyn ServerTransport>,
cx: Cx,
thread_mode: ThreadMode,
max_inflight: usize,
) -> Self
pub fn new( transport: Arc<dyn ServerTransport>, cx: Cx, thread_mode: ThreadMode, max_inflight: usize, ) -> Self
Creates a runtime with the default session isolation policy.
Sourcepub fn new_with_isolation(
transport: Arc<dyn ServerTransport>,
cx: Cx,
thread_mode: ThreadMode,
max_inflight: usize,
session_isolation: IsolationPolicy,
) -> Self
pub fn new_with_isolation( transport: Arc<dyn ServerTransport>, cx: Cx, thread_mode: ThreadMode, max_inflight: usize, session_isolation: IsolationPolicy, ) -> Self
Creates a runtime with an explicit session isolation policy applied to new sessions.
Sourcepub fn transport(&self) -> &Arc<dyn ServerTransport>
pub fn transport(&self) -> &Arc<dyn ServerTransport>
Returns the transport this runtime accepts connections on.
Sourcepub fn thread_mode(&self) -> &ThreadMode
pub fn thread_mode(&self) -> &ThreadMode
Returns the threading mode used to service connections.
Sourcepub fn session_count(&self) -> usize
pub fn session_count(&self) -> usize
Returns the number of currently open sessions.
Sourcepub fn begin_stop(&self)
pub fn begin_stop(&self)
Signals that the runtime should stop accepting and servicing connections.
Sourcepub fn is_stopping(&self) -> bool
pub fn is_stopping(&self) -> bool
Returns whether a stop has been requested.
Sourcepub fn open_session(
&self,
negotiated_codec: Symbol,
isolation: IsolationPolicy,
) -> Result<u64>
pub fn open_session( &self, negotiated_codec: Symbol, isolation: IsolationPolicy, ) -> Result<u64>
Opens a new session with the given codec and isolation policy, returning its id.
Sourcepub fn update_session_codec(
&self,
session_id: u64,
negotiated_codec: Symbol,
) -> Result<()>
pub fn update_session_codec( &self, session_id: u64, negotiated_codec: Symbol, ) -> Result<()>
Updates the negotiated codec for an existing session; a no-op if the session is gone.
Sourcepub fn close_session(&self, session_id: u64) -> Result<()>
pub fn close_session(&self, session_id: u64) -> Result<()>
Removes the session with session_id from the runtime.
Sourcepub fn clear_sessions(&self) -> Result<()>
pub fn clear_sessions(&self) -> Result<()>
Removes all sessions from the runtime.
Sourcepub fn connection_count(&self) -> u64
pub fn connection_count(&self) -> u64
Returns the total number of connections opened over the runtime’s lifetime.
Sourcepub fn messages_sent(&self) -> u64
pub fn messages_sent(&self) -> u64
Returns the total number of messages sent.
Sourcepub fn messages_received(&self) -> u64
pub fn messages_received(&self) -> u64
Returns the total number of messages received.
Sourcepub fn max_inflight(&self) -> usize
pub fn max_inflight(&self) -> usize
Returns the maximum number of in-flight requests permitted.
Sourcepub fn session_isolation(&self) -> &IsolationPolicy
pub fn session_isolation(&self) -> &IsolationPolicy
Returns the isolation policy applied to new sessions.
Sourcepub fn note_message_sent(&self)
pub fn note_message_sent(&self)
Increments the sent-message counter.
Sourcepub fn note_message_received(&self)
pub fn note_message_received(&self)
Increments the received-message counter.
Sourcepub fn with_cx<T>(&self, f: impl FnOnce(&mut Cx) -> Result<T>) -> Result<T>
pub fn with_cx<T>(&self, f: impl FnOnce(&mut Cx) -> Result<T>) -> Result<T>
Runs f with exclusive access to the runtime’s shared evaluation context.
Sourcepub fn set_accept_thread(&self, handle: JoinHandle<()>) -> Result<()>
pub fn set_accept_thread(&self, handle: JoinHandle<()>) -> Result<()>
Stores the join handle for the connection-accept thread.
Sourcepub fn join_accept_thread(&self) -> Result<()>
pub fn join_accept_thread(&self) -> Result<()>
Joins the accept thread if one is registered.
Sourcepub fn register_worker_thread(&self, handle: JoinHandle<()>) -> Result<()>
pub fn register_worker_thread(&self, handle: JoinHandle<()>) -> Result<()>
Records a worker thread’s join handle for later cleanup.
Sourcepub fn join_worker_threads(&self) -> Result<()>
pub fn join_worker_threads(&self) -> Result<()>
Joins and drains all registered worker threads.
Sourcepub fn accept_timeout(
&self,
timeout: Duration,
) -> Result<Option<Box<dyn ConnectionTransport>>>
pub fn accept_timeout( &self, timeout: Duration, ) -> Result<Option<Box<dyn ConnectionTransport>>>
Waits up to timeout for an incoming connection, returning its transport if one arrives.