1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
use tokio_core::net::TcpStream;
use tokio_proto::multiplex::ClientService;
use tokio_service::Service;
use channel::MetaClientProtocol;
use service::MethodError;
pub mod single_server;
type InnerService = ClientService<TcpStream, MetaClientProtocol>;
pub type ServerId = u64;
#[derive(Debug)]
pub struct ServerEndPort(InnerService);
impl ServerEndPort {
pub(crate) fn new(service: InnerService) -> Self {
ServerEndPort(service)
}
}
impl Service for ServerEndPort {
type Request = <InnerService as Service>::Request;
type Response = <InnerService as Service>::Response;
type Error = <InnerService as Service>::Error;
type Future = <InnerService as Service>::Future;
fn call(&self, req: Self::Request) -> Self::Future {
self.0.call(req)
}
}
#[derive(Clone, Debug, Default)]
pub struct CallInfo {
pub error: Option<MethodError>,
pub start_usec: u64,
}
impl CallInfo {
pub fn new(start_usec: u64, error: Option<MethodError>) -> Self {
CallInfo { start_usec, error }
}
}
pub trait LoadBalance {
fn select_server(&mut self) -> (ServerId, &ServerEndPort);
fn feed_back(&mut self, id: ServerId, call_info: CallInfo);
}