pub use random::*;
mod random;
use crate::client::channel::RpcChannel;
use crate::net::Address;
use crate::server::Serve;
use std::fmt::Debug;
pub trait LoadBalance<S>: Send + Sync + 'static
where
S: Serve + 'static,
S::Req: Send,
S::Resp: Send,
{
type ChannelIter: Iterator<Item = RpcChannel<S>> + Send;
fn start_balance(&self, channels: Vec<RpcChannel<S>>);
fn get_picker(&self) -> Self::ChannelIter;
fn rebalance(&self, changes: Option<RpcChange<S>>);
}
#[derive(Clone)]
pub struct RpcChange<S: Serve> {
pub all: Vec<RpcChannel<S>>,
pub added: Vec<RpcChannel<S>>,
pub updated: Vec<RpcChannel<S>>,
pub removed: Vec<Address>,
}
impl<S> Debug for RpcChange<S>
where
S: Serve,
S::Req: Debug,
S::Resp: Debug,
{
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("RpcChange")
.field("all", &self.all)
.field("added", &self.added)
.field("updated", &self.updated)
.field("removed", &self.removed)
.finish()
}
}