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
impl Router
Sourcepub fn new(backends: Vec<Arc<dyn Backend>>) -> Self
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.
Sourcepub fn with_policy(
backends: Vec<Arc<dyn Backend>>,
policy: BreakerPolicy,
) -> Self
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.
Sourcepub fn dispatch(&self) -> Result<Dispatch, RouterError>
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).
Sourcepub fn all_ready(&self) -> bool
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.
Sourcepub fn record_success(&self, name: &str)
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.
Sourcepub fn record_failure(&self, name: &str)
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.
Sourcepub fn breaker_open(&self, name: &str) -> bool
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.