apache_dubbo/protocol/triple/
triple_protocol.rs

1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements.  See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License.  You may obtain a copy of the License at
8 *
9 *     http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18use std::boxed::Box;
19use std::collections::HashMap;
20
21use async_trait::async_trait;
22
23use super::triple_exporter::TripleExporter;
24use super::triple_invoker::TripleInvoker;
25use super::triple_server::TripleServer;
26use crate::common::url::Url;
27use crate::protocol::Protocol;
28
29#[derive(Clone)]
30pub struct TripleProtocol {
31    servers: HashMap<String, TripleServer>,
32}
33
34impl Default for TripleProtocol {
35    fn default() -> Self {
36        Self::new()
37    }
38}
39
40impl TripleProtocol {
41    pub fn new() -> Self {
42        TripleProtocol {
43            servers: HashMap::new(),
44        }
45    }
46
47    pub fn get_server(&self, url: Url) -> Option<TripleServer> {
48        self.servers
49            .get(&url.service_key.join(","))
50            .map(|data| data.to_owned())
51    }
52}
53
54#[async_trait]
55impl Protocol for TripleProtocol {
56    type Invoker = TripleInvoker;
57
58    type Exporter = TripleExporter;
59
60    fn destroy(&self) {
61        todo!()
62    }
63
64    async fn export(mut self, url: Url) -> Self::Exporter {
65        let server = TripleServer::new(url.service_key.clone());
66        self.servers
67            .insert(url.service_key.join(","), server.clone());
68        server.serve(url.to_url()).await;
69
70        TripleExporter::new()
71    }
72
73    async fn refer(self, url: Url) -> Self::Invoker {
74        TripleInvoker::new(url)
75        // Self::Invoker
76    }
77}