pub trait Session: Send {
// Required methods
fn call<'a>(
&'a mut self,
method: &'a str,
params: Payload,
) -> BoxFut<'a, Result<Payload, RpcError>>;
fn write<'a>(
&'a mut self,
topic: &'a str,
payload: Payload,
) -> BoxFut<'a, Result<(), RpcError>>;
// Provided methods
fn subscribe<'a>(
&'a mut self,
topic: &'a str,
) -> BoxFut<'a, Result<BoxStream<'static, SubUpdate>, RpcError>> { ... }
fn snapshots(&mut self, topic: &str) -> Vec<(String, Payload, Stamp)> { ... }
fn starts_session(&self, method: &str) -> bool { ... }
}Expand description
The per-connection session: serves calls, subscriptions, and writes for one
accepted Connection. The engine owns the Box<dyn Session> and threads
&mut self into each method, so it can hold per-connection state without a
lock; the shared, immutable role stays on Dispatch.
Required Methods§
Provided Methods§
Sourcefn subscribe<'a>(
&'a mut self,
topic: &'a str,
) -> BoxFut<'a, Result<BoxStream<'static, SubUpdate>, RpcError>>
fn subscribe<'a>( &'a mut self, topic: &'a str, ) -> BoxFut<'a, Result<BoxStream<'static, SubUpdate>, RpcError>>
Open a subscription yielding many SubUpdates. The stream is 'static
(it captures cloned handles) so it outlives the &mut borrow and lives in
the engine. Async so a connector can await per-operation authorization.
Defaulted to RpcError::NotFound for dispatches with no streaming.
Sourcefn snapshots(&mut self, topic: &str) -> Vec<(String, Payload, Stamp)>
fn snapshots(&mut self, topic: &str) -> Vec<(String, Payload, Stamp)>
Late-join snapshots: one (topic, value) per record covered by topic
(several for a wildcard subscription), each emitted as an
Outbound::Snapshot right after a successful
subscribe and before the first event. Defaulted
to empty (no snapshots).
The engine numbers the burst 1..=N and starts the event stream at
N + 1, so a snapshot dropped in transit shows up as
SubUpdate::skipped on the next delivered update.
The burst’s last snapshot is flagged and reaches the subscriber as the
one update with SubUpdate::snapshot_end set, carrying the burst’s
whole loss; the client engine reserves a sink slot so it survives a slow
consumer.
Do not block on that flag. It is absent when topic matches no
records, and when the final snapshot fails to encode or its frame is
rejected — the flag rides that frame. Loss accounting survives all of
these; only the end-of-burst signal is lost.
Each entry is the record’s topic, its payload, and the stamp of the write that payload was read from (one read, design 058 §4.4).
Sourcefn starts_session(&self, method: &str) -> bool
fn starts_session(&self, method: &str) -> bool
Whether a request for method is a client’s handshake, which starts a
new session. Defaulted to false.
When a handshake arrives on a connection that already had one,
run_session treats it as a new client: it
cancels every subscription, discards their queued events and opens a
fresh session before answering. A transport that carries one peer for
its whole life (a serial line) has no other way to tell that the client
behind it changed.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".