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 2019/11/15 05:51:39 UTC

[dubbo] 01/03: fix grpc impl proxy problem, costomize protoc compiler

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

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

commit 7c68d77c055a61c5edf46b2f7a688e149f014673
Author: ken.lj <ke...@gmail.com>
AuthorDate: Fri Nov 15 10:23:12 2019 +0800

    fix grpc impl proxy problem, costomize protoc compiler
---
 compiler/build.gradle                           |  2 +-
 compiler/src/java_plugin/cpp/java_generator.cpp | 15 ++++++++++-----
 2 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/compiler/build.gradle b/compiler/build.gradle
index 8cbb08d..f94fef7 100644
--- a/compiler/build.gradle
+++ b/compiler/build.gradle
@@ -2,7 +2,7 @@ apply plugin: "cpp"
 apply plugin: "com.google.protobuf"
 
 group = "org.apache.dubbo"
-version = "1.19.0" // CURRENT_GRPC_VERSION
+version = "1.19.0-SNAPSHOT" // CURRENT_GRPC_VERSION
 
 description = 'The protoc plugin for gRPC Java'
 
diff --git a/compiler/src/java_plugin/cpp/java_generator.cpp b/compiler/src/java_plugin/cpp/java_generator.cpp
index e1861f0..98093ca 100644
--- a/compiler/src/java_plugin/cpp/java_generator.cpp
+++ b/compiler/src/java_plugin/cpp/java_generator.cpp
@@ -845,6 +845,11 @@ static void PrintImplBase(
         *vars,
         "public static abstract class $abstract_name$ implements $BindableService$, $dubbo_interface$ {\n\n");
 
+  p->Print(*vars, "private $dubbo_interface$ proxiedImpl;\n\n");
+  p->Print(*vars, "public final void setProxiedImpl($dubbo_interface$ proxiedImpl) {\n");
+  p->Print(*vars, " this.proxiedImpl = proxiedImpl;\n");
+  p->Print(*vars, "}\n\n");
+
   // RPC methods
   for (int i = 0; i < service->method_count(); ++i) {
     const MethodDescriptor* method = service->method(i);
@@ -905,7 +910,7 @@ static void PrintImplBase(
     p->Print(
         *vars,
         "@$Override$\n public final $ServerServiceDefinition$ bindService() {\n");
-    (*vars)["instance"] = "this";
+    (*vars)["instance"] = "proxiedImpl";
     PrintBindServiceMethodBody(service, vars, p, generate_nano);
     p->Print("}\n");
     p->Outdent();
@@ -1091,6 +1096,7 @@ static void PrintMethodHandlerClass(const ServiceDescriptor* service,
   }
   p->Print("\n");
   (*vars)["service_name"] = service->name() + "ImplBase";
+  (*vars)["dubbo_interface"] = "I" + service->name();
   p->Print(
       *vars,
       "private static final class MethodHandlers<Req, Resp> implements\n"
@@ -1098,10 +1104,10 @@ static void PrintMethodHandlerClass(const ServiceDescriptor* service,
       "    io.grpc.stub.ServerCalls.ServerStreamingMethod<Req, Resp>,\n"
       "    io.grpc.stub.ServerCalls.ClientStreamingMethod<Req, Resp>,\n"
       "    io.grpc.stub.ServerCalls.BidiStreamingMethod<Req, Resp> {\n"
-      "  private final $service_name$ serviceImpl;\n"
+      "  private final $dubbo_interface$ serviceImpl;\n"
       "  private final int methodId;\n"
       "\n"
-      "  MethodHandlers($service_name$ serviceImpl, int methodId) {\n"
+      "  MethodHandlers($dubbo_interface$ serviceImpl, int methodId) {\n"
       "    this.serviceImpl = serviceImpl;\n"
       "    this.methodId = methodId;\n"
       "  }\n\n");
@@ -1504,8 +1510,7 @@ void GenerateService(const ServiceDescriptor* service,
   vars["StreamObserver"] = "io.grpc.stub.StreamObserver";
   vars["Iterator"] = "java.util.Iterator";
   vars["Generated"] = "javax.annotation.Generated";
-  vars["ListenableFuture"] =
-      "com.google.common.util.concurrent.ListenableFuture";
+  vars["ListenableFuture"] = "com.google.common.util.concurrent.ListenableFuture";
   vars["default_method_body"] = "   throw new UnsupportedOperationException(\""
              "No need to override this method, extend XxxImplBase and override "
              "all methods it allows.\");";