Skip to main content

Router

Struct Router 

Source
pub struct Router { /* private fields */ }
Expand description

Backend router. Holds the priority-ordered backend list and per-backend breaker state. Cheap to clone via Arc.

Implementations§

Source§

impl Router

Source

pub fn new(backends: Vec<Arc<dyn Backend>>) -> Self

Build a router from a priority-ordered list of backends. First entry is highest priority. Uses the default breaker policy.

Source

pub fn with_policy( backends: Vec<Arc<dyn Backend>>, policy: BreakerPolicy, ) -> Self

Build a router with explicit breaker tuning. Used by tests (short windows + cooldowns) and operator-tuned configs.

Source

pub fn len(&self) -> usize

Number of registered backends. For diagnostics and tests.

Source

pub fn is_empty(&self) -> bool

true if no backends are registered.

Source

pub fn dispatch(&self) -> Result<Dispatch, RouterError>

Pick a backend for the next request.

Walks the slot list in priority order and returns the first slot whose backend is ready() and whose breaker is not currently open. Slots whose breaker has timed out into the half-open state count as eligible — the next outcome reported for them either closes the breaker (record_success) or re-opens it (record_failure).

Source

pub fn all_ready(&self) -> bool

true once every registered backend reports ready. The lifecycle uses this to gate listener creation (THREAT_MODEL F-13). Breaker state is not consulted — readiness here is the boot-time engine-loaded check, not the per-request availability check.

Source

pub fn record_success(&self, name: &str)

Record a successful generation against the given backend. Closes the circuit breaker (clears the open mark and the failure window). Called by the lifecycle layer after a terminal Done frame for a request served by this backend.

Source

pub fn record_failure(&self, name: &str)

Record a failure against the given backend. Counts toward the failure window; opens the breaker once the threshold is reached. Called from both the pre-stream error path (generate* returned GenerateError) and the mid-stream error path (stream terminated without a Done frame). Both kinds of failure count equally per ADR 0007.

Source

pub fn breaker_open(&self, name: &str) -> bool

true if the named backend’s circuit breaker is currently open. Diagnostic surface; the dispatch path checks this internally and returns NoneAvailable if every backend is open.

Auto Trait Implementations§

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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<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