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
64
65
66
67
68
69
70
71
72
73
74
use crate::core::msg::Request;
use crate::core::{CoreContext, ServiceType};
use crate::core::endpoint::{Endpoint, QueryEndpoint};
use std::collections::HashMap;
use std::sync::atomic::AtomicU64;
use std::sync::Arc;
/// Represents a Node in a couchbase cluster
pub struct Node {
_hostname: String,
_context: Arc<CoreContext>,
endpoints: HashMap<ServiceType, Box<dyn Endpoint>>,
}
impl Node {
pub fn new(hostname: String, context: Arc<CoreContext>) -> Self {
let mut endpoints: HashMap<ServiceType, Box<dyn Endpoint>> = HashMap::new();
endpoints.insert(
ServiceType::Query,
Box::new(QueryEndpoint::new(hostname.clone(), 8093, context.clone())),
);
Self {
_hostname: hostname,
_context: context,
endpoints,
}
}
pub fn send(&self, request: Request) {
self.endpoints
.get(&request.service_type())
.expect("endpoint not found")
.send(request);
}
}
pub struct RoundRobinLocator {
_counter: AtomicU64,
}
impl RoundRobinLocator {
pub fn dispatch(&self, request: Request, nodes: &[Node]) {
// perform the real checks and use the counter offset
for n in nodes {
n.send(request);
break;
}
}
}
impl Default for RoundRobinLocator {
fn default() -> Self {
// todo: should be initalized with a random from 0..1024
Self {
_counter: AtomicU64::new(0),
}
}
}
pub struct KeyValueLocator {}
impl KeyValueLocator {
pub fn dispatch(&self, _request: Request, _nodes: &[Node]) {
unimplemented!()
}
}
impl Default for KeyValueLocator {
fn default() -> Self {
Self {}
}
}