Skip to content

Commit 867c76d

Browse files
committed
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 grpc#436
1 parent 9c27540 commit 867c76d

File tree

9 files changed

+177
-86
lines changed

9 files changed

+177
-86
lines changed

benchmarks/src/generated/main/grpc/io/grpc/testing/TestServiceGrpc.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
import static io.grpc.stub.ClientCalls.blockingUnaryCall;
88
import static io.grpc.stub.ClientCalls.blockingServerStreamingCall;
99
import static io.grpc.stub.ClientCalls.unaryFutureCall;
10-
import static io.grpc.stub.ServerCalls.asyncUnaryRequestCall;
11-
import static io.grpc.stub.ServerCalls.asyncStreamingRequestCall;
10+
import static io.grpc.stub.ServerCalls.asyncUnaryCall;
11+
import static io.grpc.stub.ServerCalls.asyncServerStreamingCall;
12+
import static io.grpc.stub.ServerCalls.asyncClientStreamingCall;
13+
import static io.grpc.stub.ServerCalls.asyncDuplexStreamingCall;
1214

1315
@javax.annotation.Generated("by gRPC proto compiler")
1416
public class TestServiceGrpc {
@@ -204,8 +206,8 @@ public static io.grpc.ServerServiceDefinition bindService(
204206
return io.grpc.ServerServiceDefinition.builder("grpc.testing.TestService")
205207
.addMethod(io.grpc.ServerMethodDefinition.create(
206208
METHOD_UNARY_CALL,
207-
asyncUnaryRequestCall(
208-
new io.grpc.stub.ServerCalls.UnaryRequestMethod<
209+
asyncUnaryCall(
210+
new io.grpc.stub.ServerCalls.UnaryMethod<
209211
io.grpc.testing.SimpleRequest,
210212
io.grpc.testing.SimpleResponse>() {
211213
@java.lang.Override
@@ -217,8 +219,8 @@ public void invoke(
217219
})))
218220
.addMethod(io.grpc.ServerMethodDefinition.create(
219221
METHOD_STREAMING_CALL,
220-
asyncStreamingRequestCall(
221-
new io.grpc.stub.ServerCalls.StreamingRequestMethod<
222+
asyncDuplexStreamingCall(
223+
new io.grpc.stub.ServerCalls.DuplexStreamingMethod<
222224
io.grpc.testing.SimpleRequest,
223225
io.grpc.testing.SimpleResponse>() {
224226
@java.lang.Override

benchmarks/src/generated/main/grpc/io/grpc/testing/WorkerGrpc.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
import static io.grpc.stub.ClientCalls.blockingUnaryCall;
88
import static io.grpc.stub.ClientCalls.blockingServerStreamingCall;
99
import static io.grpc.stub.ClientCalls.unaryFutureCall;
10-
import static io.grpc.stub.ServerCalls.asyncUnaryRequestCall;
11-
import static io.grpc.stub.ServerCalls.asyncStreamingRequestCall;
10+
import static io.grpc.stub.ServerCalls.asyncUnaryCall;
11+
import static io.grpc.stub.ServerCalls.asyncServerStreamingCall;
12+
import static io.grpc.stub.ServerCalls.asyncClientStreamingCall;
13+
import static io.grpc.stub.ServerCalls.asyncDuplexStreamingCall;
1214

1315
@javax.annotation.Generated("by gRPC proto compiler")
1416
public class WorkerGrpc {
@@ -186,8 +188,8 @@ public static io.grpc.ServerServiceDefinition bindService(
186188
return io.grpc.ServerServiceDefinition.builder("grpc.testing.Worker")
187189
.addMethod(io.grpc.ServerMethodDefinition.create(
188190
METHOD_RUN_TEST,
189-
asyncStreamingRequestCall(
190-
new io.grpc.stub.ServerCalls.StreamingRequestMethod<
191+
asyncDuplexStreamingCall(
192+
new io.grpc.stub.ServerCalls.DuplexStreamingMethod<
191193
io.grpc.testing.ClientArgs,
192194
io.grpc.testing.ClientStatus>() {
193195
@java.lang.Override
@@ -198,8 +200,8 @@ public io.grpc.stub.StreamObserver<io.grpc.testing.ClientArgs> invoke(
198200
})))
199201
.addMethod(io.grpc.ServerMethodDefinition.create(
200202
METHOD_RUN_SERVER,
201-
asyncStreamingRequestCall(
202-
new io.grpc.stub.ServerCalls.StreamingRequestMethod<
203+
asyncDuplexStreamingCall(
204+
new io.grpc.stub.ServerCalls.DuplexStreamingMethod<
203205
io.grpc.testing.ServerArgs,
204206
io.grpc.testing.ServerStatus>() {
205207
@java.lang.Override

compiler/src/java_plugin/cpp/java_generator.cpp

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -512,14 +512,27 @@ static void PrintBindServiceMethod(const ServiceDescriptor* service,
512512
(*vars)["input_type"] = MessageFullJavaName(method->input_type());
513513
(*vars)["output_type"] = MessageFullJavaName(method->output_type());
514514
bool client_streaming = method->client_streaming();
515+
bool server_streaming = method->server_streaming();
515516
if (client_streaming) {
516-
(*vars)["calls_method"] = "asyncStreamingRequestCall";
517-
(*vars)["invocation_class"] =
518-
"io.grpc.stub.ServerCalls.StreamingRequestMethod";
517+
if (server_streaming) {
518+
(*vars)["calls_method"] = "asyncDuplexStreamingCall";
519+
(*vars)["invocation_class"] =
520+
"io.grpc.stub.ServerCalls.DuplexStreamingMethod";
521+
} else {
522+
(*vars)["calls_method"] = "asyncClientStreamingCall";
523+
(*vars)["invocation_class"] =
524+
"io.grpc.stub.ServerCalls.ClientStreamingMethod";
525+
}
519526
} else {
520-
(*vars)["calls_method"] = "asyncUnaryRequestCall";
521-
(*vars)["invocation_class"] =
522-
"io.grpc.stub.ServerCalls.UnaryRequestMethod";
527+
if (server_streaming) {
528+
(*vars)["calls_method"] = "asyncServerStreamingCall";
529+
(*vars)["invocation_class"] =
530+
"io.grpc.stub.ServerCalls.ServerStreamingMethod";
531+
} else {
532+
(*vars)["calls_method"] = "asyncUnaryCall";
533+
(*vars)["invocation_class"] =
534+
"io.grpc.stub.ServerCalls.UnaryMethod";
535+
}
523536
}
524537
p->Print(*vars, ".addMethod($ServerMethodDefinition$.create(\n");
525538
p->Indent();
@@ -647,9 +660,13 @@ void PrintImports(Printer* p, bool generate_nano) {
647660
"import static "
648661
"io.grpc.stub.ClientCalls.unaryFutureCall;\n"
649662
"import static "
650-
"io.grpc.stub.ServerCalls.asyncUnaryRequestCall;\n"
663+
"io.grpc.stub.ServerCalls.asyncUnaryCall;\n"
664+
"import static "
665+
"io.grpc.stub.ServerCalls.asyncServerStreamingCall;\n"
666+
"import static "
667+
"io.grpc.stub.ServerCalls.asyncClientStreamingCall;\n"
651668
"import static "
652-
"io.grpc.stub.ServerCalls.asyncStreamingRequestCall;\n\n");
669+
"io.grpc.stub.ServerCalls.asyncDuplexStreamingCall;\n\n");
653670
if (generate_nano) {
654671
p->Print("import java.io.IOException;\n\n");
655672
}

compiler/src/test/golden/TestService.java.txt

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ import static io.grpc.stub.ClientCalls.duplexStreamingCall;
77
import static io.grpc.stub.ClientCalls.blockingUnaryCall;
88
import static io.grpc.stub.ClientCalls.blockingServerStreamingCall;
99
import static io.grpc.stub.ClientCalls.unaryFutureCall;
10-
import static io.grpc.stub.ServerCalls.asyncUnaryRequestCall;
11-
import static io.grpc.stub.ServerCalls.asyncStreamingRequestCall;
10+
import static io.grpc.stub.ServerCalls.asyncUnaryCall;
11+
import static io.grpc.stub.ServerCalls.asyncServerStreamingCall;
12+
import static io.grpc.stub.ServerCalls.asyncClientStreamingCall;
13+
import static io.grpc.stub.ServerCalls.asyncDuplexStreamingCall;
1214

1315
@javax.annotation.Generated("by gRPC proto compiler")
1416
public class TestServiceGrpc {
@@ -289,8 +291,8 @@ public class TestServiceGrpc {
289291
return io.grpc.ServerServiceDefinition.builder("grpc.testing.TestService")
290292
.addMethod(io.grpc.ServerMethodDefinition.create(
291293
METHOD_UNARY_CALL,
292-
asyncUnaryRequestCall(
293-
new io.grpc.stub.ServerCalls.UnaryRequestMethod<
294+
asyncUnaryCall(
295+
new io.grpc.stub.ServerCalls.UnaryMethod<
294296
io.grpc.testing.integration.Test.SimpleRequest,
295297
io.grpc.testing.integration.Test.SimpleResponse>() {
296298
@java.lang.Override
@@ -302,8 +304,8 @@ public class TestServiceGrpc {
302304
})))
303305
.addMethod(io.grpc.ServerMethodDefinition.create(
304306
METHOD_STREAMING_OUTPUT_CALL,
305-
asyncUnaryRequestCall(
306-
new io.grpc.stub.ServerCalls.UnaryRequestMethod<
307+
asyncServerStreamingCall(
308+
new io.grpc.stub.ServerCalls.ServerStreamingMethod<
307309
io.grpc.testing.integration.Test.StreamingOutputCallRequest,
308310
io.grpc.testing.integration.Test.StreamingOutputCallResponse>() {
309311
@java.lang.Override
@@ -315,8 +317,8 @@ public class TestServiceGrpc {
315317
})))
316318
.addMethod(io.grpc.ServerMethodDefinition.create(
317319
METHOD_STREAMING_INPUT_CALL,
318-
asyncStreamingRequestCall(
319-
new io.grpc.stub.ServerCalls.StreamingRequestMethod<
320+
asyncClientStreamingCall(
321+
new io.grpc.stub.ServerCalls.ClientStreamingMethod<
320322
io.grpc.testing.integration.Test.StreamingInputCallRequest,
321323
io.grpc.testing.integration.Test.StreamingInputCallResponse>() {
322324
@java.lang.Override
@@ -327,8 +329,8 @@ public class TestServiceGrpc {
327329
})))
328330
.addMethod(io.grpc.ServerMethodDefinition.create(
329331
METHOD_FULL_DUPLEX_CALL,
330-
asyncStreamingRequestCall(
331-
new io.grpc.stub.ServerCalls.StreamingRequestMethod<
332+
asyncDuplexStreamingCall(
333+
new io.grpc.stub.ServerCalls.DuplexStreamingMethod<
332334
io.grpc.testing.integration.Test.StreamingOutputCallRequest,
333335
io.grpc.testing.integration.Test.StreamingOutputCallResponse>() {
334336
@java.lang.Override
@@ -339,8 +341,8 @@ public class TestServiceGrpc {
339341
})))
340342
.addMethod(io.grpc.ServerMethodDefinition.create(
341343
METHOD_HALF_DUPLEX_CALL,
342-
asyncStreamingRequestCall(
343-
new io.grpc.stub.ServerCalls.StreamingRequestMethod<
344+
asyncDuplexStreamingCall(
345+
new io.grpc.stub.ServerCalls.DuplexStreamingMethod<
344346
io.grpc.testing.integration.Test.StreamingOutputCallRequest,
345347
io.grpc.testing.integration.Test.StreamingOutputCallResponse>() {
346348
@java.lang.Override

compiler/src/test/golden/TestServiceNano.java.txt

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ import static io.grpc.stub.ClientCalls.duplexStreamingCall;
77
import static io.grpc.stub.ClientCalls.blockingUnaryCall;
88
import static io.grpc.stub.ClientCalls.blockingServerStreamingCall;
99
import static io.grpc.stub.ClientCalls.unaryFutureCall;
10-
import static io.grpc.stub.ServerCalls.asyncUnaryRequestCall;
11-
import static io.grpc.stub.ServerCalls.asyncStreamingRequestCall;
10+
import static io.grpc.stub.ServerCalls.asyncUnaryCall;
11+
import static io.grpc.stub.ServerCalls.asyncServerStreamingCall;
12+
import static io.grpc.stub.ServerCalls.asyncClientStreamingCall;
13+
import static io.grpc.stub.ServerCalls.asyncDuplexStreamingCall;
1214

1315
import java.io.IOException;
1416

@@ -351,8 +353,8 @@ public class TestServiceGrpc {
351353
return io.grpc.ServerServiceDefinition.builder("grpc.testing.TestService")
352354
.addMethod(io.grpc.ServerMethodDefinition.create(
353355
METHOD_UNARY_CALL,
354-
asyncUnaryRequestCall(
355-
new io.grpc.stub.ServerCalls.UnaryRequestMethod<
356+
asyncUnaryCall(
357+
new io.grpc.stub.ServerCalls.UnaryMethod<
356358
io.grpc.testing.integration.Test.SimpleRequest,
357359
io.grpc.testing.integration.Test.SimpleResponse>() {
358360
@java.lang.Override
@@ -364,8 +366,8 @@ public class TestServiceGrpc {
364366
})))
365367
.addMethod(io.grpc.ServerMethodDefinition.create(
366368
METHOD_STREAMING_OUTPUT_CALL,
367-
asyncUnaryRequestCall(
368-
new io.grpc.stub.ServerCalls.UnaryRequestMethod<
369+
asyncServerStreamingCall(
370+
new io.grpc.stub.ServerCalls.ServerStreamingMethod<
369371
io.grpc.testing.integration.Test.StreamingOutputCallRequest,
370372
io.grpc.testing.integration.Test.StreamingOutputCallResponse>() {
371373
@java.lang.Override
@@ -377,8 +379,8 @@ public class TestServiceGrpc {
377379
})))
378380
.addMethod(io.grpc.ServerMethodDefinition.create(
379381
METHOD_STREAMING_INPUT_CALL,
380-
asyncStreamingRequestCall(
381-
new io.grpc.stub.ServerCalls.StreamingRequestMethod<
382+
asyncClientStreamingCall(
383+
new io.grpc.stub.ServerCalls.ClientStreamingMethod<
382384
io.grpc.testing.integration.Test.StreamingInputCallRequest,
383385
io.grpc.testing.integration.Test.StreamingInputCallResponse>() {
384386
@java.lang.Override
@@ -389,8 +391,8 @@ public class TestServiceGrpc {
389391
})))
390392
.addMethod(io.grpc.ServerMethodDefinition.create(
391393
METHOD_FULL_DUPLEX_CALL,
392-
asyncStreamingRequestCall(
393-
new io.grpc.stub.ServerCalls.StreamingRequestMethod<
394+
asyncDuplexStreamingCall(
395+
new io.grpc.stub.ServerCalls.DuplexStreamingMethod<
394396
io.grpc.testing.integration.Test.StreamingOutputCallRequest,
395397
io.grpc.testing.integration.Test.StreamingOutputCallResponse>() {
396398
@java.lang.Override
@@ -401,8 +403,8 @@ public class TestServiceGrpc {
401403
})))
402404
.addMethod(io.grpc.ServerMethodDefinition.create(
403405
METHOD_HALF_DUPLEX_CALL,
404-
asyncStreamingRequestCall(
405-
new io.grpc.stub.ServerCalls.StreamingRequestMethod<
406+
asyncDuplexStreamingCall(
407+
new io.grpc.stub.ServerCalls.DuplexStreamingMethod<
406408
io.grpc.testing.integration.Test.StreamingOutputCallRequest,
407409
io.grpc.testing.integration.Test.StreamingOutputCallResponse>() {
408410
@java.lang.Override

examples/src/generated/main/grpc/io/grpc/examples/helloworld/GreeterGrpc.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
import static io.grpc.stub.ClientCalls.blockingUnaryCall;
88
import static io.grpc.stub.ClientCalls.blockingServerStreamingCall;
99
import static io.grpc.stub.ClientCalls.unaryFutureCall;
10-
import static io.grpc.stub.ServerCalls.asyncUnaryRequestCall;
11-
import static io.grpc.stub.ServerCalls.asyncStreamingRequestCall;
10+
import static io.grpc.stub.ServerCalls.asyncUnaryCall;
11+
import static io.grpc.stub.ServerCalls.asyncServerStreamingCall;
12+
import static io.grpc.stub.ServerCalls.asyncClientStreamingCall;
13+
import static io.grpc.stub.ServerCalls.asyncDuplexStreamingCall;
1214

1315
@javax.annotation.Generated("by gRPC proto compiler")
1416
public class GreeterGrpc {
@@ -179,8 +181,8 @@ public static io.grpc.ServerServiceDefinition bindService(
179181
return io.grpc.ServerServiceDefinition.builder("helloworld.Greeter")
180182
.addMethod(io.grpc.ServerMethodDefinition.create(
181183
METHOD_SAY_HELLO,
182-
asyncUnaryRequestCall(
183-
new io.grpc.stub.ServerCalls.UnaryRequestMethod<
184+
asyncUnaryCall(
185+
new io.grpc.stub.ServerCalls.UnaryMethod<
184186
io.grpc.examples.helloworld.HelloRequest,
185187
io.grpc.examples.helloworld.HelloResponse>() {
186188
@java.lang.Override

examples/src/generated/main/grpc/io/grpc/examples/routeguide/RouteGuideGrpc.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
import static io.grpc.stub.ClientCalls.blockingUnaryCall;
88
import static io.grpc.stub.ClientCalls.blockingServerStreamingCall;
99
import static io.grpc.stub.ClientCalls.unaryFutureCall;
10-
import static io.grpc.stub.ServerCalls.asyncUnaryRequestCall;
11-
import static io.grpc.stub.ServerCalls.asyncStreamingRequestCall;
10+
import static io.grpc.stub.ServerCalls.asyncUnaryCall;
11+
import static io.grpc.stub.ServerCalls.asyncServerStreamingCall;
12+
import static io.grpc.stub.ServerCalls.asyncClientStreamingCall;
13+
import static io.grpc.stub.ServerCalls.asyncDuplexStreamingCall;
1214

1315
@javax.annotation.Generated("by gRPC proto compiler")
1416
public class RouteGuideGrpc {
@@ -264,8 +266,8 @@ public static io.grpc.ServerServiceDefinition bindService(
264266
return io.grpc.ServerServiceDefinition.builder("routeguide.RouteGuide")
265267
.addMethod(io.grpc.ServerMethodDefinition.create(
266268
METHOD_GET_FEATURE,
267-
asyncUnaryRequestCall(
268-
new io.grpc.stub.ServerCalls.UnaryRequestMethod<
269+
asyncUnaryCall(
270+
new io.grpc.stub.ServerCalls.UnaryMethod<
269271
io.grpc.examples.routeguide.Point,
270272
io.grpc.examples.routeguide.Feature>() {
271273
@java.lang.Override
@@ -277,8 +279,8 @@ public void invoke(
277279
})))
278280
.addMethod(io.grpc.ServerMethodDefinition.create(
279281
METHOD_LIST_FEATURES,
280-
asyncUnaryRequestCall(
281-
new io.grpc.stub.ServerCalls.UnaryRequestMethod<
282+
asyncServerStreamingCall(
283+
new io.grpc.stub.ServerCalls.ServerStreamingMethod<
282284
io.grpc.examples.routeguide.Rectangle,
283285
io.grpc.examples.routeguide.Feature>() {
284286
@java.lang.Override
@@ -290,8 +292,8 @@ public void invoke(
290292
})))
291293
.addMethod(io.grpc.ServerMethodDefinition.create(
292294
METHOD_RECORD_ROUTE,
293-
asyncStreamingRequestCall(
294-
new io.grpc.stub.ServerCalls.StreamingRequestMethod<
295+
asyncClientStreamingCall(
296+
new io.grpc.stub.ServerCalls.ClientStreamingMethod<
295297
io.grpc.examples.routeguide.Point,
296298
io.grpc.examples.routeguide.RouteSummary>() {
297299
@java.lang.Override
@@ -302,8 +304,8 @@ public io.grpc.stub.StreamObserver<io.grpc.examples.routeguide.Point> invoke(
302304
})))
303305
.addMethod(io.grpc.ServerMethodDefinition.create(
304306
METHOD_ROUTE_CHAT,
305-
asyncStreamingRequestCall(
306-
new io.grpc.stub.ServerCalls.StreamingRequestMethod<
307+
asyncDuplexStreamingCall(
308+
new io.grpc.stub.ServerCalls.DuplexStreamingMethod<
307309
io.grpc.examples.routeguide.RouteNote,
308310
io.grpc.examples.routeguide.RouteNote>() {
309311
@java.lang.Override

0 commit comments

Comments
 (0)