|
16 | 16 | */
|
17 | 17 |
|
18 | 18 | use std::collections::HashMap;
|
| 19 | +use std::sync::Arc; |
19 | 20 |
|
| 21 | +use super::memory_registry::MemoryRegistry; |
20 | 22 | use super::BoxRegistry;
|
| 23 | +use crate::codegen::TripleInvoker; |
| 24 | +use crate::common::consts; |
21 | 25 | use crate::common::url::Url;
|
| 26 | +use crate::protocol::triple::triple_exporter::TripleExporter; |
| 27 | +use crate::protocol::BoxExporter; |
| 28 | +use crate::protocol::BoxInvoker; |
| 29 | +use crate::protocol::Protocol; |
22 | 30 |
|
| 31 | +#[derive(Clone, Default)] |
23 | 32 | pub struct RegistryProtocol {
|
24 |
| - registries: HashMap<String, BoxRegistry>, |
| 33 | + // registerAddr: Registry |
| 34 | + registries: Arc<HashMap<String, BoxRegistry>>, |
| 35 | + // providerUrl: Exporter |
| 36 | + exporters: Arc<HashMap<String, BoxExporter>>, |
25 | 37 | }
|
26 | 38 |
|
27 | 39 | impl RegistryProtocol {
|
| 40 | + pub fn new() -> Self { |
| 41 | + RegistryProtocol { |
| 42 | + registries: Arc::new(HashMap::new()), |
| 43 | + exporters: Arc::new(HashMap::new()), |
| 44 | + } |
| 45 | + } |
| 46 | + |
| 47 | + pub fn get_registry(&self, url: Url) -> BoxRegistry { |
| 48 | + // self.registries.clone().insert(url.location.clone(), Box::new(MemoryRegistry::default())); |
| 49 | + |
| 50 | + // *(self.registries.get(&url.location).unwrap()) |
| 51 | + Box::new(MemoryRegistry::default()) |
| 52 | + } |
| 53 | +} |
| 54 | + |
| 55 | +#[async_trait::async_trait] |
| 56 | +impl Protocol for RegistryProtocol { |
| 57 | + type Invoker = BoxInvoker; |
| 58 | + |
28 | 59 | fn destroy(&self) {
|
29 | 60 | todo!()
|
30 | 61 | }
|
31 | 62 |
|
32 |
| - async fn export(self, url: Url) {} |
33 |
| - async fn refer(self, url: Url) {} |
| 63 | + async fn export(self, url: Url) -> BoxExporter { |
| 64 | + // getProviderUrl |
| 65 | + // getRegisterUrl |
| 66 | + // init Exporter based on provider_url |
| 67 | + // server registry based on register_url |
| 68 | + // start server health check |
| 69 | + Box::new(TripleExporter::new()) |
| 70 | + } |
| 71 | + async fn refer(self, url: Url) -> Self::Invoker { |
| 72 | + // getRegisterUrl |
| 73 | + // get Registry from registry_url |
| 74 | + // init directory based on registry_url and Registry |
| 75 | + // init Cluster based on Directory generates Invoker |
| 76 | + Box::new(TripleInvoker::new(url)) |
| 77 | + } |
| 78 | +} |
| 79 | + |
| 80 | +fn get_registry_url(mut url: Url) -> Url { |
| 81 | + if url.protocol == consts::REGISTRY_PROTOCOL { |
| 82 | + url.protocol = url.get_param("registry".to_string()).unwrap(); |
| 83 | + } |
| 84 | + |
| 85 | + url |
| 86 | +} |
| 87 | + |
| 88 | +fn get_provider_url(url: Url) -> Url { |
| 89 | + url |
34 | 90 | }
|
0 commit comments