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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#![allow(unused_variables, dead_code, missing_docs)]
use std::collections::HashMap;
use std::sync::RwLock;
use super::{NotifyListener, Registry};
pub const REGISTRY_GROUP_KEY: &str = "registry.group";
#[derive(Debug, Default)]
pub struct MemoryRegistry {
registries: RwLock<HashMap<String, String>>,
}
impl MemoryRegistry {
pub fn new() -> MemoryRegistry {
MemoryRegistry {
registries: RwLock::new(HashMap::new()),
}
}
}
impl Registry for MemoryRegistry {
type NotifyListener = MemoryNotifyListener;
fn register(&mut self, mut url: crate::common::url::Url) -> Result<(), crate::StdError> {
let registry_group = match url.get_param(REGISTRY_GROUP_KEY.to_string()) {
Some(key) => key,
None => "dubbo".to_string(),
};
let dubbo_path = format!(
"/{}/{}/{}",
registry_group,
url.get_service_name().join(","),
"provider",
);
url.params.insert("anyhost".to_string(), "true".to_string());
let raw_url = format!("{}?{}", url.to_url(), url.encode_param(),);
self.registries.write().unwrap().insert(dubbo_path, raw_url);
Ok(())
}
fn unregister(&mut self, url: crate::common::url::Url) -> Result<(), crate::StdError> {
let registry_group = match url.get_param(REGISTRY_GROUP_KEY.to_string()) {
Some(key) => key,
None => "dubbo".to_string(),
};
let dubbo_path = format!(
"/{}/{}/{}",
registry_group,
url.get_service_name().join(","),
"provider",
);
self.registries.write().unwrap().remove(&dubbo_path);
Ok(())
}
fn subscribe(
&self,
url: crate::common::url::Url,
listener: Self::NotifyListener,
) -> Result<(), crate::StdError> {
todo!()
}
fn unsubscribe(
&self,
url: crate::common::url::Url,
listener: Self::NotifyListener,
) -> Result<(), crate::StdError> {
todo!()
}
}
pub struct MemoryNotifyListener {}
impl NotifyListener for MemoryNotifyListener {
fn notify(&self, event: super::ServiceEvent) {
todo!()
}
fn notify_all(&self, event: super::ServiceEvent) {
todo!()
}
}