apache_dubbo/registry/
memory_registry.rs1#![allow(unused_variables, dead_code, missing_docs)]
19use std::collections::HashMap;
20use std::sync::RwLock;
21
22use super::{NotifyListener, Registry};
23
24pub const REGISTRY_GROUP_KEY: &str = "registry.group";
29
30#[derive(Debug, Default)]
31pub struct MemoryRegistry {
32 registries: RwLock<HashMap<String, String>>,
33}
34
35impl MemoryRegistry {
36 pub fn new() -> MemoryRegistry {
37 MemoryRegistry {
38 registries: RwLock::new(HashMap::new()),
39 }
40 }
41}
42
43impl Registry for MemoryRegistry {
44 type NotifyListener = MemoryNotifyListener;
45
46 fn register(&mut self, mut url: crate::common::url::Url) -> Result<(), crate::StdError> {
47 let registry_group = match url.get_param(REGISTRY_GROUP_KEY.to_string()) {
49 Some(key) => key,
50 None => "dubbo".to_string(),
51 };
52
53 let dubbo_path = format!(
54 "/{}/{}/{}",
55 registry_group,
56 url.get_service_name().join(","),
57 "provider",
58 );
59
60 url.params.insert("anyhost".to_string(), "true".to_string());
61 let raw_url = format!("{}?{}", url.to_url(), url.encode_param(),);
63
64 self.registries.write().unwrap().insert(dubbo_path, raw_url);
65 Ok(())
66 }
67
68 fn unregister(&mut self, url: crate::common::url::Url) -> Result<(), crate::StdError> {
69 let registry_group = match url.get_param(REGISTRY_GROUP_KEY.to_string()) {
70 Some(key) => key,
71 None => "dubbo".to_string(),
72 };
73
74 let dubbo_path = format!(
75 "/{}/{}/{}",
76 registry_group,
77 url.get_service_name().join(","),
78 "provider",
79 );
80 self.registries.write().unwrap().remove(&dubbo_path);
81
82 Ok(())
83 }
84
85 fn subscribe(
86 &self,
87 url: crate::common::url::Url,
88 listener: Self::NotifyListener,
89 ) -> Result<(), crate::StdError> {
90 todo!()
91 }
92
93 fn unsubscribe(
94 &self,
95 url: crate::common::url::Url,
96 listener: Self::NotifyListener,
97 ) -> Result<(), crate::StdError> {
98 todo!()
99 }
100}
101
102pub struct MemoryNotifyListener {}
103
104impl NotifyListener for MemoryNotifyListener {
105 fn notify(&self, event: super::ServiceEvent) {
106 todo!()
107 }
108
109 fn notify_all(&self, event: super::ServiceEvent) {
110 todo!()
111 }
112}