pub struct SessionHandle { /* private fields */ }Expand description
A handle for managing HTTP transport sessions and final subscription streams.
Obtained from HttpTransport::into_router_with_handle() or
HttpTransport::into_router_at_with_handle(). The handle is cheap to
clone and can be shared across threads.
§Example
ⓘ
use tower_mcp::transport::http::HttpTransport;
let transport = HttpTransport::new(router);
let (router, handle) = transport.into_router_with_handle();
// Later, in an admin endpoint:
let count = handle.session_count().await;
for info in handle.list_sessions().await {
println!("{}: created {:?} ago", info.id, info.created_at);
}
handle.terminate_session("session-id").await;
// During graceful server shutdown (with the `stateless` feature):
handle.close_subscriptions();Implementations§
Source§impl SessionHandle
impl SessionHandle
Sourcepub async fn session_count(&self) -> usize
pub async fn session_count(&self) -> usize
Returns the number of currently active sessions.
Sourcepub async fn list_sessions(&self) -> Vec<SessionInfo>
pub async fn list_sessions(&self) -> Vec<SessionInfo>
Returns metadata for all active sessions.
Sourcepub async fn terminate_session(&self, id: &str) -> bool
pub async fn terminate_session(&self, id: &str) -> bool
Terminates a session by ID, returning true if the session existed.
Sourcepub fn subscription_count(&self) -> usize
pub fn subscription_count(&self) -> usize
Returns the number of active final-protocol subscription streams.
Sourcepub fn close_subscriptions(&self) -> usize
pub fn close_subscriptions(&self) -> usize
Gracefully finish every active final-protocol subscription stream.
Each stream receives its terminal SubscriptionsListenResult before
closing. Returns the number of streams that were drained.
Trait Implementations§
Source§impl Clone for SessionHandle
impl Clone for SessionHandle
Source§fn clone(&self) -> SessionHandle
fn clone(&self) -> SessionHandle
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · 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 !RefUnwindSafe for SessionHandle
impl !UnwindSafe for SessionHandle
impl Freeze for SessionHandle
impl Send for SessionHandle
impl Sync for SessionHandle
impl Unpin for SessionHandle
impl UnsafeUnpin for SessionHandle
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