Skip to main content

Supervisor

Struct Supervisor 

Source
pub struct Supervisor<P: Protocol> { /* private fields */ }
Expand description

Starts a supervised connection for a Protocol.

The task it spawns holds one connection at a time and keeps these rules (AD-11):

  • Pings on the wall clock. A ping goes out every Timing::ping_interval whatever the traffic, and also while the consumer’s queue is full: the task then races the queue’s space against the ping timer and reads nothing more, and the time it waits does not count as silence. None goes out while a membership change is in flight, which Timing::stale_after bounds.
  • Staleness. Silence for Timing::stale_after, by the protocol’s liveness rule, replaces the connection.
  • Follow-ups. After each decoded frame that leaves the connection up, the frame Protocol::follow_up returns is sent within Timing::stale_after; a send that fails or outlives it replaces the connection, as a failed ping does.
  • No drops. No decoded event is dropped; a bounded queue holds the task back instead.
  • Outage markers. At most one Protocol::disconnected per outage, and exactly one Protocol::reconnected, even when the membership stops being wanted during the outage.
  • Not wanted. A membership that stops being wanted on a healthy connection closes it politely, with no marker, and ends the stream.
  • Rotation. A connection older than Timing::max_connection_age is closed politely and replaced at once.
  • Membership during an outage. A change made during an outage goes to Protocol::record, and a held one is applied after the reconnect.
  • The consumer gone. Dropping Supervised ends the task promptly, and Supervised::close does not wait on a consumer that never read.

Reconnects wait out Timing::backoff’s schedule, with no cap on attempts, or the Protocol::retry_after of the failure before them when that is longer, up to Timing::max_backoff (DRIFT R11); each attempt is bounded by Timing::connect_timeout. The task logs under the polyoxide_ws target.

The task runs on the injected runtime and dials through the injected socket_transport, each the target’s default when none is given.

The basis is one socket crate’s former supervised tier (ws/supervised.rs, deleted in Story 4.6), with another socket crate’s former loop (replaced in Story 4.7 by a router over one supervisor per path) for rotation, outage markers, changes recorded during an outage, the start in an outage and the consumer’s departure. Neither kept pinging behind a full queue.

Implementations§

Source§

impl<P: Protocol> Supervisor<P>

Source

pub fn new(protocol: P, timing: Timing) -> Self

A supervisor for protocol on timing, on the target’s default runtime and socket transport until runtime and socket_transport say otherwise.

Source

pub fn runtime(self, runtime: Arc<dyn Runtime>) -> Self

Run the task’s timers, clock reads and spawn on runtime.

Source

pub fn socket_transport(self, transport: Arc<dyn SocketTransport>) -> Self

Dial every attempt through transport.

Source

pub async fn connect( self, membership: P::Membership, ) -> Result<Supervised<P>, P::Error>

Connect, replay membership, and start supervising. Any failure of that first attempt is returned, so a setup that is wrong is reported rather than retried.

Source

pub async fn start( self, membership: P::Membership, ) -> Result<Supervised<P>, P::Error>

As connect, except that a first failure Protocol::recover would retry starts the stream in an outage: the protocol’s disconnected for it, then the backoff and the attempts that follow. Only a failure it would Stop on is returned.

Trait Implementations§

Source§

impl<P: Debug + Protocol> Debug for Supervisor<P>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<P> !RefUnwindSafe for Supervisor<P>

§

impl<P> !UnwindSafe for Supervisor<P>

§

impl<P> Freeze for Supervisor<P>
where P: Freeze,

§

impl<P> Send for Supervisor<P>

§

impl<P> Sync for Supervisor<P>
where P: Sync,

§

impl<P> Unpin for Supervisor<P>
where P: Unpin,

§

impl<P> UnsafeUnpin for Supervisor<P>
where P: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more