pub struct ConnectionManager { /* private fields */ }Expand description
Thread-safe manager for active WebSocket connections.
Uses DashMap for lock-free concurrent reads and writes.
Each connection has an event sender for delivering change events and a
oneshot close-signal channel for graceful server-initiated disconnection
(e.g., slow consumer policy).
Implementations§
Source§impl ConnectionManager
impl ConnectionManager
Sourcepub fn new(
max_consecutive_drops: usize,
connection_event_capacity: usize,
) -> Self
pub fn new( max_consecutive_drops: usize, connection_event_capacity: usize, ) -> Self
Create a new empty connection manager.
Sourcepub fn insert(
&self,
state: ConnectionState,
) -> (Receiver<String>, Receiver<CloseSignal>)
pub fn insert( &self, state: ConnectionState, ) -> (Receiver<String>, Receiver<CloseSignal>)
Register a new connection and return a receiver for events and a close-signal receiver.
The event receiver should be polled by the connection handler to forward
change events to the WebSocket. The close-signal receiver fires when the
delivery pipeline detects a slow consumer.
Sourcepub fn remove(&self, connection_id: &str)
pub fn remove(&self, connection_id: &str)
Remove a connection by ID, cleaning up all associated state.
Sourcepub fn count_by_context(&self, context_hash: u64) -> usize
pub fn count_by_context(&self, context_hash: u64) -> usize
Number of connections for a specific security context hash.
Sourcepub fn send_event(&self, connection_id: &str, json: String) -> bool
pub fn send_event(&self, connection_id: &str, json: String) -> bool
Send a serialized event to a connection’s event channel.
On success, resets the per-connection drop counter.
On failure (channel full), increments the drop counter. If the counter
reaches max_consecutive_drops, a close signal with code 4002 (“slow
consumer”) is sent to the connection handler.
Returns true if the event was sent, false otherwise.
Sourcepub fn drop_count(&self, connection_id: &str) -> usize
pub fn drop_count(&self, connection_id: &str) -> usize
Return the current consecutive drop count for a connection (for testing).
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for ConnectionManager
impl !UnwindSafe for ConnectionManager
impl Freeze for ConnectionManager
impl Send for ConnectionManager
impl Sync for ConnectionManager
impl Unpin for ConnectionManager
impl UnsafeUnpin for ConnectionManager
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<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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