This is an automated email from the ASF dual-hosted git repository.
earthchen pushed a commit to branch 3.2
in repository https://gitbox.apache.org/repos/asf/dubbo.git
The following commit(s) were added to refs/heads/3.2 by this push:
new 4d5d9d8afc fix tri stub unary method overload (#13385)
4d5d9d8afc is described below
commit 4d5d9d8afc5d6d05010b8915ec72bdf9418ef02b
Author: earthchen <[email protected]>
AuthorDate: Thu Nov 23 12:49:16 2023 +0800
fix tri stub unary method overload (#13385)
* fix tri stub unary method overload
* fix tri stub unary method overload
* fix
* fix
* format
* format
---
.../main/resources/Dubbo3InterfaceStub.mustache | 14 ++++----
.../resources/Dubbo3TripleInterfaceStub.mustache | 29 ++++-------------
.../src/main/resources/Dubbo3TripleStub.mustache | 37 ++++++++++++++++++----
3 files changed, 44 insertions(+), 36 deletions(-)
diff --git a/dubbo-compiler/src/main/resources/Dubbo3InterfaceStub.mustache
b/dubbo-compiler/src/main/resources/Dubbo3InterfaceStub.mustache
index ebbaad9f7d..d0d6684cdf 100644
--- a/dubbo-compiler/src/main/resources/Dubbo3InterfaceStub.mustache
+++ b/dubbo-compiler/src/main/resources/Dubbo3InterfaceStub.mustache
@@ -23,7 +23,7 @@ import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicBoolean;
{{#deprecated}}
- @java.lang.Deprecated
[email protected]
{{/deprecated}}
public interface {{interfaceClassName}} extends
org.apache.dubbo.rpc.model.DubboStub {
@@ -35,10 +35,10 @@ public interface {{interfaceClassName}} extends
org.apache.dubbo.rpc.model.Dubbo
{{#unaryMethods}}
{{#javaDoc}}
- {{{javaDoc}}}
+ {{{javaDoc}}}
{{/javaDoc}}
{{#deprecated}}
- @java.lang.Deprecated
+ @java.lang.Deprecated
{{/deprecated}}
{{outputType}} {{methodName}}({{inputType}} request);
@@ -50,20 +50,20 @@ public interface {{interfaceClassName}} extends
org.apache.dubbo.rpc.model.Dubbo
{{#serverStreamingMethods}}
{{#javaDoc}}
- {{{javaDoc}}}
+ {{{javaDoc}}}
{{/javaDoc}}
{{#deprecated}}
- @java.lang.Deprecated
+ @java.lang.Deprecated
{{/deprecated}}
void {{methodName}}({{inputType}} request,
org.apache.dubbo.common.stream.StreamObserver<{{outputType}}> responseObserver);
{{/serverStreamingMethods}}
{{#biStreamingMethods}}
{{#javaDoc}}
- {{{javaDoc}}}
+ {{{javaDoc}}}
{{/javaDoc}}
{{#deprecated}}
- @java.lang.Deprecated
+ @java.lang.Deprecated
{{/deprecated}}
org.apache.dubbo.common.stream.StreamObserver<{{inputType}}>
{{methodName}}(org.apache.dubbo.common.stream.StreamObserver<{{outputType}}>
responseObserver);
{{/biStreamingMethods}}
diff --git
a/dubbo-compiler/src/main/resources/Dubbo3TripleInterfaceStub.mustache
b/dubbo-compiler/src/main/resources/Dubbo3TripleInterfaceStub.mustache
index 72b68c3d67..5c06c04d8f 100644
--- a/dubbo-compiler/src/main/resources/Dubbo3TripleInterfaceStub.mustache
+++ b/dubbo-compiler/src/main/resources/Dubbo3TripleInterfaceStub.mustache
@@ -16,7 +16,7 @@
*/
{{#packageName}}
- package {{packageName}};
+package {{packageName}};
{{/packageName}}
import org.apache.dubbo.common.stream.StreamObserver;
@@ -34,41 +34,26 @@ public interface {{interfaceClassName}} extends
org.apache.dubbo.rpc.model.Dubbo
{{#unaryMethods}}
{{#javaDoc}}
- {{{javaDoc}}}
+ {{{javaDoc}}}
{{/javaDoc}}
{{outputType}} {{methodName}}({{inputType}} request);
- default CompletableFuture<{{outputType}}>
{{methodName}}Async({{inputType}} request){
- return CompletableFuture.completedFuture({{methodName}}(request));
- }
+ CompletableFuture<{{outputType}}> {{methodName}}Async({{inputType}}
request);
+
- /**
- * This server stream type unary method is <b>only</b> used for generated
stub to support async unary method.
- * It will not be called if you are NOT using Dubbo3 generated triple stub
and <b>DO NOT</b> implement this method.
- */
- default void {{methodName}}({{inputType}} request,
StreamObserver<{{outputType}}> responseObserver){
- {{methodName}}Async(request).whenComplete((r, t) -> {
- if (t != null) {
- responseObserver.onError(t);
- } else {
- responseObserver.onNext(r);
- responseObserver.onCompleted();
- }
- });
- }
{{/unaryMethods}}
{{#serverStreamingMethods}}
{{#javaDoc}}
- {{{javaDoc}}}
+ {{{javaDoc}}}
{{/javaDoc}}
void {{methodName}}({{inputType}} request, StreamObserver<{{outputType}}>
responseObserver);
{{/serverStreamingMethods}}
{{#biStreamingWithoutClientStreamMethods}}
{{#javaDoc}}
- {{{javaDoc}}}
+ {{{javaDoc}}}
{{/javaDoc}}
StreamObserver<{{inputType}}>
{{methodName}}(StreamObserver<{{outputType}}> responseObserver);
{{/biStreamingWithoutClientStreamMethods}}
@@ -76,7 +61,7 @@ public interface {{interfaceClassName}} extends
org.apache.dubbo.rpc.model.Dubbo
{{#clientStreamingMethods}}
{{#javaDoc}}
- {{{javaDoc}}}
+ {{{javaDoc}}}
{{/javaDoc}}
StreamObserver<{{inputType}}>
{{methodName}}(StreamObserver<{{outputType}}> responseObserver);
{{/clientStreamingMethods}}
diff --git a/dubbo-compiler/src/main/resources/Dubbo3TripleStub.mustache
b/dubbo-compiler/src/main/resources/Dubbo3TripleStub.mustache
index af383bdcbc..4ecef4c333 100644
--- a/dubbo-compiler/src/main/resources/Dubbo3TripleStub.mustache
+++ b/dubbo-compiler/src/main/resources/Dubbo3TripleStub.mustache
@@ -16,7 +16,7 @@
*/
{{#packageName}}
- package {{packageName}};
+package {{packageName}};
{{/packageName}}
import org.apache.dubbo.common.stream.StreamObserver;
@@ -125,7 +125,7 @@ public final class {{className}} {
{{#unaryMethods}}
{{#javaDoc}}
- {{{javaDoc}}}
+ {{{javaDoc}}}
{{/javaDoc}}
@Override
public {{outputType}} {{methodName}}({{inputType}} request){
@@ -137,9 +137,8 @@ public final class {{className}} {
}
{{#javaDoc}}
- {{{javaDoc}}}
+ {{{javaDoc}}}
{{/javaDoc}}
- @Override
public void {{methodName}}({{inputType}} request,
StreamObserver<{{outputType}}> responseObserver){
StubInvocationUtil.unaryCall(invoker, {{methodName}}Method ,
request, responseObserver);
}
@@ -147,7 +146,7 @@ public final class {{className}} {
{{#serverStreamingMethods}}
{{#javaDoc}}
- {{{javaDoc}}}
+ {{{javaDoc}}}
{{/javaDoc}}
@Override
public void {{methodName}}({{inputType}} request,
StreamObserver<{{outputType}}> responseObserver){
@@ -157,7 +156,7 @@ public final class {{className}} {
{{#biStreamingWithoutClientStreamMethods}}
{{#javaDoc}}
- {{{javaDoc}}}
+ {{{javaDoc}}}
{{/javaDoc}}
@Override
public StreamObserver<{{inputType}}>
{{methodName}}(StreamObserver<{{outputType}}> responseObserver){
@@ -167,7 +166,7 @@ public final class {{className}} {
{{#clientStreamingMethods}}
{{#javaDoc}}
- {{{javaDoc}}}
+ {{{javaDoc}}}
{{/javaDoc}}
@Override
public StreamObserver<{{inputType}}>
{{methodName}}(StreamObserver<{{outputType}}> responseObserver){
@@ -193,6 +192,30 @@ public final class {{className}} {
};
}
+ {{#unaryMethods}}
+ @Override
+ public CompletableFuture<{{outputType}}>
{{methodName}}Async({{inputType}} request){
+ return
CompletableFuture.completedFuture({{methodName}}(request));
+ }
+ {{/unaryMethods}}
+
+ /**
+ * This server stream type unary method is <b>only</b> used for
generated stub to support async unary method.
+ * It will not be called if you are NOT using Dubbo3 generated triple
stub and <b>DO NOT</b> implement this method.
+ */
+ {{#unaryMethods}}
+ public void {{methodName}}({{inputType}} request,
StreamObserver<{{outputType}}> responseObserver){
+ {{methodName}}Async(request).whenComplete((r, t) -> {
+ if (t != null) {
+ responseObserver.onError(t);
+ } else {
+ responseObserver.onNext(r);
+ responseObserver.onCompleted();
+ }
+ });
+ }
+ {{/unaryMethods}}
+
@Override
public final Invoker<{{interfaceClassName}}> getInvoker(URL url) {
PathResolver pathResolver = url.getOrDefaultFrameworkModel()