You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by ya...@apache.org on 2023/01/23 03:05:31 UTC

[dubbo-rust] branch main updated: Rft: Update Invoker Trait (#97)

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

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


The following commit(s) were added to refs/heads/main by this push:
     new d0e21c1  Rft: Update Invoker Trait (#97)
d0e21c1 is described below

commit d0e21c1762e0b6fd2ca8570fc5d361fdb0628f9c
Author: Yang Yang <96...@qq.com>
AuthorDate: Mon Jan 23 11:05:26 2023 +0800

    Rft: Update Invoker Trait (#97)
    
    * refactor(dubbo): update invoker trait
---
 dubbo/src/protocol/mod.rs                   |  2 ++
 dubbo/src/protocol/triple/triple_invoker.rs | 24 ++++++++++++------------
 dubbo/src/triple/client/builder.rs          |  2 +-
 3 files changed, 15 insertions(+), 13 deletions(-)

diff --git a/dubbo/src/protocol/mod.rs b/dubbo/src/protocol/mod.rs
index 20042cb..f58212d 100644
--- a/dubbo/src/protocol/mod.rs
+++ b/dubbo/src/protocol/mod.rs
@@ -48,6 +48,8 @@ pub trait Invoker<ReqBody> {
 
     fn get_url(&self) -> Url;
 
+    fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>>;
+
     fn call(&mut self, req: ReqBody) -> Self::Future;
 }
 
diff --git a/dubbo/src/protocol/triple/triple_invoker.rs b/dubbo/src/protocol/triple/triple_invoker.rs
index 0193851..1cbe2ed 100644
--- a/dubbo/src/protocol/triple/triple_invoker.rs
+++ b/dubbo/src/protocol/triple/triple_invoker.rs
@@ -21,13 +21,11 @@ use tower_service::Service;
 
 use crate::common::url::Url;
 use crate::protocol::Invoker;
-use crate::triple::transport::connection::Connection;
+use crate::triple::client::builder::{ClientBoxService, ClientBuilder};
 
-#[allow(dead_code)]
-#[derive(Clone, Default)]
 pub struct TripleInvoker {
     url: Url,
-    conn: Connection,
+    conn: ClientBoxService,
 }
 
 impl TripleInvoker {
@@ -35,17 +33,12 @@ impl TripleInvoker {
         let uri = http::Uri::from_str(&url.to_url()).unwrap();
         Self {
             url,
-            conn: Connection::new().with_host(uri),
+            conn: ClientBuilder::from(uri).connect(),
         }
     }
 }
 
-impl<ReqBody> Invoker<http::Request<ReqBody>> for TripleInvoker
-where
-    ReqBody: http_body::Body + Unpin + Send + 'static,
-    ReqBody::Error: Into<crate::Error>,
-    ReqBody::Data: Send + Unpin,
-{
+impl Invoker<http::Request<hyper::Body>> for TripleInvoker {
     type Response = http::Response<crate::BoxBody>;
 
     type Error = crate::Error;
@@ -56,7 +49,14 @@ where
         self.url.clone()
     }
 
-    fn call(&mut self, req: http::Request<ReqBody>) -> Self::Future {
+    fn call(&mut self, req: http::Request<hyper::Body>) -> Self::Future {
         self.conn.call(req)
     }
+
+    fn poll_ready(
+        &mut self,
+        cx: &mut std::task::Context<'_>,
+    ) -> std::task::Poll<Result<(), Self::Error>> {
+        self.conn.poll_ready(cx)
+    }
 }
diff --git a/dubbo/src/triple/client/builder.rs b/dubbo/src/triple/client/builder.rs
index 8372c16..21afc0c 100644
--- a/dubbo/src/triple/client/builder.rs
+++ b/dubbo/src/triple/client/builder.rs
@@ -88,7 +88,7 @@ impl From<Uri> for ClientBuilder {
         Self {
             uri: u,
             timeout: None,
-            connector: "",
+            connector: "tcp",
         }
     }
 }