pub struct Balancer { /* private fields */ }Expand description
A set of routes, each a listening address spread over backends. Cheap to
clone; all clones share the routes. Dropping the last clone does not stop
the listeners: call Balancer::remove_route (or Balancer::clear).
Implementations§
Source§impl Balancer
impl Balancer
pub fn new() -> Balancer
Sourcepub fn set_route(
&self,
key: &str,
listen: SocketAddr,
backends: Vec<SocketAddr>,
) -> Result<SocketAddr>
pub fn set_route( &self, key: &str, listen: SocketAddr, backends: Vec<SocketAddr>, ) -> Result<SocketAddr>
Create or update the route key, returning the bound address.
A new route (or a changed listen) binds here, and a bind failure (the
port is taken) is the error. A changed listen binds the new address
first and only then closes the old one, so a failure leaves the old route
serving. The same listen never rebinds: only the backend list changes,
and backends that left keep their connections until those end.
Sourcepub fn remove_route(&self, key: &str)
pub fn remove_route(&self, key: &str)
Stop listening for key. Its open connections drain on their own. The
listening socket is closed when this returns.
pub fn routes(&self) -> Vec<RouteStatus>
Sourcepub fn active(&self, key: &str, backend: SocketAddr) -> usize
pub fn active(&self, key: &str, backend: SocketAddr) -> usize
Open connections to backend under route key, whether it is still in
the route or draining.
Sourcepub fn wait_drained(
&self,
key: &str,
backend: SocketAddr,
timeout: Duration,
) -> bool
pub fn wait_drained( &self, key: &str, backend: SocketAddr, timeout: Duration, ) -> bool
Wait until backend has no open connections under route key, up to
timeout. True when it drained (or never had any), false on timeout.
Only meaningful once the backend is out of the route; otherwise new
connections can keep arriving.