You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by li...@apache.org on 2022/07/23 14:44:28 UTC

[dubbo-rust] 26/38: refactor(dubbo): update code structure

This is an automated email from the ASF dual-hosted git repository.

liujun pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/dubbo-rust.git

commit 6d0180827c0c4ca69b9d042f88cba35937f1c983
Author: yang <96...@qq.com>
AuthorDate: Tue Jun 28 21:50:34 2022 +0800

    refactor(dubbo): update code structure
---
 dubbo/src/helloworld/helloworld.rs                 |  6 ++--
 dubbo/src/lib.rs                                   |  2 +-
 dubbo/src/main.rs                                  |  2 +-
 .../{service => protocol}/grpc/grpc_exporter.rs    |  3 +-
 .../src/{service => protocol}/grpc/grpc_invoker.rs |  4 +--
 .../{service => protocol}/grpc/grpc_protocol.rs    |  2 +-
 .../src/{service => protocol}/grpc/grpc_server.rs  | 31 -----------------
 dubbo/src/{service => protocol}/grpc/mod.rs        |  4 +--
 dubbo/src/{service => protocol}/invocation.rs      |  0
 dubbo/src/{service/protocol.rs => protocol/mod.rs} | 12 +++++--
 .../grpc_exporter.rs => protocol/server_desc.rs}   | 40 ++++++++++------------
 dubbo/src/service/mod.rs                           | 20 -----------
 12 files changed, 39 insertions(+), 87 deletions(-)

diff --git a/dubbo/src/helloworld/helloworld.rs b/dubbo/src/helloworld/helloworld.rs
index 2b2ef39..a7a2a8b 100644
--- a/dubbo/src/helloworld/helloworld.rs
+++ b/dubbo/src/helloworld/helloworld.rs
@@ -112,9 +112,9 @@ pub mod greeter_client {
 pub mod greeter_server {
     #![allow(unused_variables, dead_code, missing_docs, clippy::let_unit_value)]
 
-    use crate::service::grpc::grpc_server::DubboGrpcService;
-    use crate::service::grpc::grpc_server::ServiceDesc;
-    use crate::service::protocol::Invoker;
+    use crate::protocol::server_desc::ServiceDesc;
+    use crate::protocol::DubboGrpcService;
+    use crate::protocol::Invoker;
     use tonic::codegen::*;
 
     ///Generated trait containing gRPC methods that should be implemented for use with GreeterServer.
diff --git a/dubbo/src/lib.rs b/dubbo/src/lib.rs
index f7cfaef..e292e47 100644
--- a/dubbo/src/lib.rs
+++ b/dubbo/src/lib.rs
@@ -17,5 +17,5 @@
 
 pub mod common;
 pub mod helloworld;
-pub mod service;
+pub mod protocol;
 pub mod utils;
diff --git a/dubbo/src/main.rs b/dubbo/src/main.rs
index 0dd0e47..906e5cb 100644
--- a/dubbo/src/main.rs
+++ b/dubbo/src/main.rs
@@ -17,7 +17,7 @@
 
 pub mod common;
 pub mod helloworld;
-pub mod service;
+pub mod protocol;
 pub mod utils;
 
 #[tokio::main]
diff --git a/dubbo/src/service/grpc/grpc_exporter.rs b/dubbo/src/protocol/grpc/grpc_exporter.rs
similarity index 94%
copy from dubbo/src/service/grpc/grpc_exporter.rs
copy to dubbo/src/protocol/grpc/grpc_exporter.rs
index 591064a..55c41a8 100644
--- a/dubbo/src/service/grpc/grpc_exporter.rs
+++ b/dubbo/src/protocol/grpc/grpc_exporter.rs
@@ -15,8 +15,7 @@
  * limitations under the License.
  */
 
-use crate::service::protocol::Invoker;
-use crate::service::protocol::*;
+use crate::protocol::{Exporter, Invoker};
 
 pub struct GrpcExporter<T> {
     invoker: T,
diff --git a/dubbo/src/service/grpc/grpc_invoker.rs b/dubbo/src/protocol/grpc/grpc_invoker.rs
similarity index 97%
rename from dubbo/src/service/grpc/grpc_invoker.rs
rename to dubbo/src/protocol/grpc/grpc_invoker.rs
index 402e75a..e64a1db 100644
--- a/dubbo/src/service/grpc/grpc_invoker.rs
+++ b/dubbo/src/protocol/grpc/grpc_invoker.rs
@@ -22,8 +22,8 @@ use tonic::transport::Channel;
 use tonic::transport::Endpoint;
 
 use crate::common::url::Url;
-use crate::service::invocation;
-use crate::service::protocol::*;
+use crate::protocol::invocation;
+use crate::protocol::Invoker;
 
 pub struct GrpcInvoker {
     client: Grpc<Channel>,
diff --git a/dubbo/src/service/grpc/grpc_protocol.rs b/dubbo/src/protocol/grpc/grpc_protocol.rs
similarity index 98%
rename from dubbo/src/service/grpc/grpc_protocol.rs
rename to dubbo/src/protocol/grpc/grpc_protocol.rs
index 4762abc..b33468c 100644
--- a/dubbo/src/service/grpc/grpc_protocol.rs
+++ b/dubbo/src/protocol/grpc/grpc_protocol.rs
@@ -21,7 +21,7 @@ use super::grpc_exporter::GrpcExporter;
 use super::grpc_invoker::GrpcInvoker;
 use super::grpc_server::GrpcServer;
 use crate::common::url::Url;
-use crate::service::protocol::Protocol;
+use crate::protocol::Protocol;
 
 pub struct GrpcProtocol {
     server_map: HashMap<String, GrpcServer>,
diff --git a/dubbo/src/service/grpc/grpc_server.rs b/dubbo/src/protocol/grpc/grpc_server.rs
similarity index 78%
rename from dubbo/src/service/grpc/grpc_server.rs
rename to dubbo/src/protocol/grpc/grpc_server.rs
index 3cc5294..872257b 100644
--- a/dubbo/src/service/grpc/grpc_server.rs
+++ b/dubbo/src/protocol/grpc/grpc_server.rs
@@ -15,7 +15,6 @@
  * limitations under the License.
  */
 
-use std::collections::HashMap;
 use std::task::Context;
 use std::task::Poll;
 
@@ -30,36 +29,6 @@ use crate::helloworld::helloworld::greeter_server::GreeterServer;
 use crate::helloworld::helloworld::greeter_server::*;
 use crate::utils::boxed_clone::BoxCloneService;
 
-pub trait DubboGrpcService<T> {
-    fn set_proxy_impl(&mut self, invoker: T);
-    fn service_desc(&self) -> ServiceDesc;
-}
-
-//type ServiceDesc struct {
-//     ServiceName string
-//     // The pointer to the service interface. Used to check whether the user
-//     // provided implementation satisfies the interface requirements.
-//     HandlerType interface{}
-//     Methods     []MethodDesc
-//     Streams     []StreamDesc
-//     Metadata    interface{}
-// }
-
-pub struct ServiceDesc {
-    service_name: String,
-    // methods: HashMap<String, String> // "/Greeter/hello": "unary"
-}
-
-impl ServiceDesc {
-    pub fn new(service_name: String, _methods: HashMap<String, String>) -> Self {
-        Self { service_name }
-    }
-
-    pub fn get_service_name(&self) -> String {
-        self.service_name.clone()
-    }
-}
-
 // codegen
 pub fn register_greeter_server<T: Greeter>(
     server: T,
diff --git a/dubbo/src/service/grpc/mod.rs b/dubbo/src/protocol/grpc/mod.rs
similarity index 97%
rename from dubbo/src/service/grpc/mod.rs
rename to dubbo/src/protocol/grpc/mod.rs
index 91ee2c0..f5a6ca3 100644
--- a/dubbo/src/service/grpc/mod.rs
+++ b/dubbo/src/protocol/grpc/mod.rs
@@ -26,9 +26,9 @@ use std::sync::RwLock;
 
 use crate::helloworld::helloworld::greeter_server::Greeter;
 use crate::helloworld::helloworld::{HelloReply, HelloRequest};
+use crate::protocol::DubboGrpcService;
 use crate::utils::boxed_clone::BoxCloneService;
 use grpc_invoker::GrpcInvoker;
-use grpc_server::DubboGrpcService;
 
 pub type GrpcBoxCloneService = BoxCloneService<
     http::Request<hyper::Body>,
@@ -48,7 +48,7 @@ lazy_static! {
 #[tokio::test]
 async fn test_hello() {
     use crate::common::url::Url;
-    use crate::service::protocol::Protocol;
+    use crate::protocol::Protocol;
     use grpc_server::register_greeter_server;
 
     let (svc, dubbo_svc) = register_greeter_server(MyGreeter {});
diff --git a/dubbo/src/service/invocation.rs b/dubbo/src/protocol/invocation.rs
similarity index 100%
rename from dubbo/src/service/invocation.rs
rename to dubbo/src/protocol/invocation.rs
diff --git a/dubbo/src/service/protocol.rs b/dubbo/src/protocol/mod.rs
similarity index 88%
rename from dubbo/src/service/protocol.rs
rename to dubbo/src/protocol/mod.rs
index bec2b7f..4199142 100644
--- a/dubbo/src/service/protocol.rs
+++ b/dubbo/src/protocol/mod.rs
@@ -15,11 +15,14 @@
  * limitations under the License.
  */
 
-use super::invocation;
-use crate::common::url::Url;
+pub mod grpc;
+pub mod invocation;
+pub mod server_desc;
 
 use async_trait::async_trait;
 
+use crate::common::url::Url;
+
 #[async_trait]
 pub trait Protocol {
     type Invoker;
@@ -45,3 +48,8 @@ pub trait Invoker {
     fn destroy(&self);
     fn get_url(&self) -> Url;
 }
+
+pub trait DubboGrpcService<T> {
+    fn set_proxy_impl(&mut self, invoker: T);
+    fn service_desc(&self) -> server_desc::ServiceDesc;
+}
diff --git a/dubbo/src/service/grpc/grpc_exporter.rs b/dubbo/src/protocol/server_desc.rs
similarity index 54%
rename from dubbo/src/service/grpc/grpc_exporter.rs
rename to dubbo/src/protocol/server_desc.rs
index 591064a..84cbe92 100644
--- a/dubbo/src/service/grpc/grpc_exporter.rs
+++ b/dubbo/src/protocol/server_desc.rs
@@ -15,33 +15,29 @@
  * limitations under the License.
  */
 
-use crate::service::protocol::Invoker;
-use crate::service::protocol::*;
+//type ServiceDesc struct {
+//     ServiceName string
+//     // The pointer to the service interface. Used to check whether the user
+//     // provided implementation satisfies the interface requirements.
+//     HandlerType interface{}
+//     Methods     []MethodDesc
+//     Streams     []StreamDesc
+//     Metadata    interface{}
+// }
 
-pub struct GrpcExporter<T> {
-    invoker: T,
-}
+use std::collections::HashMap;
 
-impl<T> GrpcExporter<T> {
-    pub fn new(_key: String, invoker: T) -> GrpcExporter<T> {
-        Self { invoker }
-    }
+pub struct ServiceDesc {
+    service_name: String,
+    // methods: HashMap<String, String> // "/Greeter/hello": "unary"
 }
 
-impl<T: Invoker + Clone> Exporter for GrpcExporter<T> {
-    type InvokerType = T;
-
-    fn unexport(&self) {}
-
-    fn get_invoker(&self) -> Self::InvokerType {
-        self.invoker.clone()
+impl ServiceDesc {
+    pub fn new(service_name: String, _methods: HashMap<String, String>) -> Self {
+        Self { service_name }
     }
-}
 
-impl<T: Invoker + Clone> Clone for GrpcExporter<T> {
-    fn clone(&self) -> Self {
-        Self {
-            invoker: self.invoker.clone(),
-        }
+    pub fn get_service_name(&self) -> String {
+        self.service_name.clone()
     }
 }
diff --git a/dubbo/src/service/mod.rs b/dubbo/src/service/mod.rs
deleted file mode 100644
index 753f567..0000000
--- a/dubbo/src/service/mod.rs
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-pub mod grpc;
-pub mod invocation;
-pub mod protocol;