Separate ServerCall binding utilities per method type.
This gives us more flexibility in API changes in the future.
Unary call and server streaming call should call the flow-control method
call.request() only once. Previously it was called whenever a request
arrives, which is wrong. Now it's fixed.
Resolves #436
diff --git a/compiler/src/java_plugin/cpp/java_generator.cpp b/compiler/src/java_plugin/cpp/java_generator.cpp
index 5795157..bac19ca 100644
--- a/compiler/src/java_plugin/cpp/java_generator.cpp
+++ b/compiler/src/java_plugin/cpp/java_generator.cpp
@@ -512,14 +512,27 @@
(*vars)["input_type"] = MessageFullJavaName(method->input_type());
(*vars)["output_type"] = MessageFullJavaName(method->output_type());
bool client_streaming = method->client_streaming();
+ bool server_streaming = method->server_streaming();
if (client_streaming) {
- (*vars)["calls_method"] = "asyncStreamingRequestCall";
- (*vars)["invocation_class"] =
- "io.grpc.stub.ServerCalls.StreamingRequestMethod";
+ if (server_streaming) {
+ (*vars)["calls_method"] = "asyncDuplexStreamingCall";
+ (*vars)["invocation_class"] =
+ "io.grpc.stub.ServerCalls.DuplexStreamingMethod";
+ } else {
+ (*vars)["calls_method"] = "asyncClientStreamingCall";
+ (*vars)["invocation_class"] =
+ "io.grpc.stub.ServerCalls.ClientStreamingMethod";
+ }
} else {
- (*vars)["calls_method"] = "asyncUnaryRequestCall";
- (*vars)["invocation_class"] =
- "io.grpc.stub.ServerCalls.UnaryRequestMethod";
+ if (server_streaming) {
+ (*vars)["calls_method"] = "asyncServerStreamingCall";
+ (*vars)["invocation_class"] =
+ "io.grpc.stub.ServerCalls.ServerStreamingMethod";
+ } else {
+ (*vars)["calls_method"] = "asyncUnaryCall";
+ (*vars)["invocation_class"] =
+ "io.grpc.stub.ServerCalls.UnaryMethod";
+ }
}
p->Print(*vars, ".addMethod($ServerMethodDefinition$.create(\n");
p->Indent();
@@ -647,9 +660,13 @@
"import static "
"io.grpc.stub.ClientCalls.unaryFutureCall;\n"
"import static "
- "io.grpc.stub.ServerCalls.asyncUnaryRequestCall;\n"
+ "io.grpc.stub.ServerCalls.asyncUnaryCall;\n"
"import static "
- "io.grpc.stub.ServerCalls.asyncStreamingRequestCall;\n\n");
+ "io.grpc.stub.ServerCalls.asyncServerStreamingCall;\n"
+ "import static "
+ "io.grpc.stub.ServerCalls.asyncClientStreamingCall;\n"
+ "import static "
+ "io.grpc.stub.ServerCalls.asyncDuplexStreamingCall;\n\n");
if (generate_nano) {
p->Print("import java.io.IOException;\n\n");
}
diff --git a/compiler/src/test/golden/TestService.java.txt b/compiler/src/test/golden/TestService.java.txt
index a8b4f47..13d92f3 100644
--- a/compiler/src/test/golden/TestService.java.txt
+++ b/compiler/src/test/golden/TestService.java.txt
@@ -7,8 +7,10 @@
import static io.grpc.stub.ClientCalls.blockingUnaryCall;
import static io.grpc.stub.ClientCalls.blockingServerStreamingCall;
import static io.grpc.stub.ClientCalls.unaryFutureCall;
-import static io.grpc.stub.ServerCalls.asyncUnaryRequestCall;
-import static io.grpc.stub.ServerCalls.asyncStreamingRequestCall;
+import static io.grpc.stub.ServerCalls.asyncUnaryCall;
+import static io.grpc.stub.ServerCalls.asyncServerStreamingCall;
+import static io.grpc.stub.ServerCalls.asyncClientStreamingCall;
+import static io.grpc.stub.ServerCalls.asyncDuplexStreamingCall;
@javax.annotation.Generated("by gRPC proto compiler")
public class TestServiceGrpc {
@@ -289,8 +291,8 @@
return io.grpc.ServerServiceDefinition.builder("grpc.testing.TestService")
.addMethod(io.grpc.ServerMethodDefinition.create(
METHOD_UNARY_CALL,
- asyncUnaryRequestCall(
- new io.grpc.stub.ServerCalls.UnaryRequestMethod<
+ asyncUnaryCall(
+ new io.grpc.stub.ServerCalls.UnaryMethod<
io.grpc.testing.integration.Test.SimpleRequest,
io.grpc.testing.integration.Test.SimpleResponse>() {
@java.lang.Override
@@ -302,8 +304,8 @@
})))
.addMethod(io.grpc.ServerMethodDefinition.create(
METHOD_STREAMING_OUTPUT_CALL,
- asyncUnaryRequestCall(
- new io.grpc.stub.ServerCalls.UnaryRequestMethod<
+ asyncServerStreamingCall(
+ new io.grpc.stub.ServerCalls.ServerStreamingMethod<
io.grpc.testing.integration.Test.StreamingOutputCallRequest,
io.grpc.testing.integration.Test.StreamingOutputCallResponse>() {
@java.lang.Override
@@ -315,8 +317,8 @@
})))
.addMethod(io.grpc.ServerMethodDefinition.create(
METHOD_STREAMING_INPUT_CALL,
- asyncStreamingRequestCall(
- new io.grpc.stub.ServerCalls.StreamingRequestMethod<
+ asyncClientStreamingCall(
+ new io.grpc.stub.ServerCalls.ClientStreamingMethod<
io.grpc.testing.integration.Test.StreamingInputCallRequest,
io.grpc.testing.integration.Test.StreamingInputCallResponse>() {
@java.lang.Override
@@ -327,8 +329,8 @@
})))
.addMethod(io.grpc.ServerMethodDefinition.create(
METHOD_FULL_DUPLEX_CALL,
- asyncStreamingRequestCall(
- new io.grpc.stub.ServerCalls.StreamingRequestMethod<
+ asyncDuplexStreamingCall(
+ new io.grpc.stub.ServerCalls.DuplexStreamingMethod<
io.grpc.testing.integration.Test.StreamingOutputCallRequest,
io.grpc.testing.integration.Test.StreamingOutputCallResponse>() {
@java.lang.Override
@@ -339,8 +341,8 @@
})))
.addMethod(io.grpc.ServerMethodDefinition.create(
METHOD_HALF_DUPLEX_CALL,
- asyncStreamingRequestCall(
- new io.grpc.stub.ServerCalls.StreamingRequestMethod<
+ asyncDuplexStreamingCall(
+ new io.grpc.stub.ServerCalls.DuplexStreamingMethod<
io.grpc.testing.integration.Test.StreamingOutputCallRequest,
io.grpc.testing.integration.Test.StreamingOutputCallResponse>() {
@java.lang.Override
diff --git a/compiler/src/test/golden/TestServiceNano.java.txt b/compiler/src/test/golden/TestServiceNano.java.txt
index 114f671..07e98a8 100644
--- a/compiler/src/test/golden/TestServiceNano.java.txt
+++ b/compiler/src/test/golden/TestServiceNano.java.txt
@@ -7,8 +7,10 @@
import static io.grpc.stub.ClientCalls.blockingUnaryCall;
import static io.grpc.stub.ClientCalls.blockingServerStreamingCall;
import static io.grpc.stub.ClientCalls.unaryFutureCall;
-import static io.grpc.stub.ServerCalls.asyncUnaryRequestCall;
-import static io.grpc.stub.ServerCalls.asyncStreamingRequestCall;
+import static io.grpc.stub.ServerCalls.asyncUnaryCall;
+import static io.grpc.stub.ServerCalls.asyncServerStreamingCall;
+import static io.grpc.stub.ServerCalls.asyncClientStreamingCall;
+import static io.grpc.stub.ServerCalls.asyncDuplexStreamingCall;
import java.io.IOException;
@@ -351,8 +353,8 @@
return io.grpc.ServerServiceDefinition.builder("grpc.testing.TestService")
.addMethod(io.grpc.ServerMethodDefinition.create(
METHOD_UNARY_CALL,
- asyncUnaryRequestCall(
- new io.grpc.stub.ServerCalls.UnaryRequestMethod<
+ asyncUnaryCall(
+ new io.grpc.stub.ServerCalls.UnaryMethod<
io.grpc.testing.integration.Test.SimpleRequest,
io.grpc.testing.integration.Test.SimpleResponse>() {
@java.lang.Override
@@ -364,8 +366,8 @@
})))
.addMethod(io.grpc.ServerMethodDefinition.create(
METHOD_STREAMING_OUTPUT_CALL,
- asyncUnaryRequestCall(
- new io.grpc.stub.ServerCalls.UnaryRequestMethod<
+ asyncServerStreamingCall(
+ new io.grpc.stub.ServerCalls.ServerStreamingMethod<
io.grpc.testing.integration.Test.StreamingOutputCallRequest,
io.grpc.testing.integration.Test.StreamingOutputCallResponse>() {
@java.lang.Override
@@ -377,8 +379,8 @@
})))
.addMethod(io.grpc.ServerMethodDefinition.create(
METHOD_STREAMING_INPUT_CALL,
- asyncStreamingRequestCall(
- new io.grpc.stub.ServerCalls.StreamingRequestMethod<
+ asyncClientStreamingCall(
+ new io.grpc.stub.ServerCalls.ClientStreamingMethod<
io.grpc.testing.integration.Test.StreamingInputCallRequest,
io.grpc.testing.integration.Test.StreamingInputCallResponse>() {
@java.lang.Override
@@ -389,8 +391,8 @@
})))
.addMethod(io.grpc.ServerMethodDefinition.create(
METHOD_FULL_DUPLEX_CALL,
- asyncStreamingRequestCall(
- new io.grpc.stub.ServerCalls.StreamingRequestMethod<
+ asyncDuplexStreamingCall(
+ new io.grpc.stub.ServerCalls.DuplexStreamingMethod<
io.grpc.testing.integration.Test.StreamingOutputCallRequest,
io.grpc.testing.integration.Test.StreamingOutputCallResponse>() {
@java.lang.Override
@@ -401,8 +403,8 @@
})))
.addMethod(io.grpc.ServerMethodDefinition.create(
METHOD_HALF_DUPLEX_CALL,
- asyncStreamingRequestCall(
- new io.grpc.stub.ServerCalls.StreamingRequestMethod<
+ asyncDuplexStreamingCall(
+ new io.grpc.stub.ServerCalls.DuplexStreamingMethod<
io.grpc.testing.integration.Test.StreamingOutputCallRequest,
io.grpc.testing.integration.Test.StreamingOutputCallResponse>() {
@java.lang.Override