apache_dubbo/protocol/
mod.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
18pub mod grpc;
19pub mod server_desc;
20pub mod triple;
21
22use async_trait::async_trait;
23
24use crate::common::url::Url;
25use crate::invocation::{Request, Response};
26use crate::utils::boxed_clone::BoxCloneService;
27
28#[async_trait]
29pub trait Protocol {
30    type Invoker;
31    type Exporter;
32
33    fn destroy(&self);
34    async fn export(self, url: Url) -> Self::Exporter;
35    async fn refer(self, url: Url) -> Self::Invoker;
36}
37
38pub trait Exporter {
39    type InvokerType: Invoker;
40
41    fn unexport(&self);
42    fn get_invoker(&self) -> Self::InvokerType;
43}
44
45pub trait Invoker {
46    fn invoke<M1>(&self, req: Request<M1>) -> Response<String>
47    where
48        M1: Send + 'static;
49    fn is_available(&self) -> bool;
50    fn destroy(&self);
51    fn get_url(&self) -> Url;
52}
53
54pub trait DubboGrpcService<T> {
55    fn set_proxy_impl(&mut self, invoker: T);
56    fn service_desc(&self) -> server_desc::ServiceDesc;
57}
58
59pub type GrpcBoxCloneService = BoxCloneService<
60    http::Request<hyper::Body>,
61    http::Response<hyper::Body>,
62    std::convert::Infallible,
63>;