Skip to content

Commit

Permalink
Add methods to ClientCalls for both blocking client and server stream…
Browse files Browse the repository at this point in the history
… and move the logic out of the generated file into the server streaming method
  • Loading branch information
larry-safran committed Aug 31, 2023
1 parent d2dec86 commit 2104a0f
Show file tree
Hide file tree
Showing 19 changed files with 101 additions and 109 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -235,12 +235,8 @@ protected MetricsServiceBlockingV2Stub build(
*/
public io.grpc.stub.BlockingClientCall<?, io.grpc.testing.integration.Metrics.GaugeResponse>
getAllGauges(io.grpc.testing.integration.Metrics.EmptyMessage request) throws java.lang.InterruptedException {
io.grpc.stub.BlockingClientCall<io.grpc.testing.integration.Metrics.EmptyMessage, io.grpc.testing.integration.Metrics.GaugeResponse> call =
io.grpc.stub.ClientCalls.blockingBidiStreamingCall(
getChannel(), getGetAllGaugesMethod(), getCallOptions());
call.write(request);
call.halfClose();
return call;
return io.grpc.stub.ClientCalls.blockingV2ServerStreamingCall(
getChannel(), getGetAllGaugesMethod(), getCallOptions(), request);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -611,12 +611,8 @@ public io.grpc.testing.integration.Messages.SimpleResponse cacheableUnaryCall(io
*/
public io.grpc.stub.BlockingClientCall<?, io.grpc.testing.integration.Messages.StreamingOutputCallResponse>
streamingOutputCall(io.grpc.testing.integration.Messages.StreamingOutputCallRequest request) throws java.lang.InterruptedException {
io.grpc.stub.BlockingClientCall<io.grpc.testing.integration.Messages.StreamingOutputCallRequest, io.grpc.testing.integration.Messages.StreamingOutputCallResponse> call =
io.grpc.stub.ClientCalls.blockingBidiStreamingCall(
getChannel(), getStreamingOutputCallMethod(), getCallOptions());
call.write(request);
call.halfClose();
return call;
return io.grpc.stub.ClientCalls.blockingV2ServerStreamingCall(
getChannel(), getStreamingOutputCallMethod(), getCallOptions(), request);
}

/**
Expand All @@ -627,7 +623,7 @@ public io.grpc.testing.integration.Messages.SimpleResponse cacheableUnaryCall(io
*/
public io.grpc.stub.BlockingClientCall<io.grpc.testing.integration.Messages.StreamingInputCallRequest, io.grpc.testing.integration.Messages.StreamingInputCallResponse>
streamingInputCall() {
return io.grpc.stub.ClientCalls.blockingBidiStreamingCall(
return io.grpc.stub.ClientCalls.blockingClientStreamingCall(
getChannel(), getStreamingInputCallMethod(), getCallOptions());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public final class LoadBalancerStatsServiceGrpc {

private LoadBalancerStatsServiceGrpc() {}

public static final String SERVICE_NAME = "grpc.testing.LoadBalancerStatsService";
public static final java.lang.String SERVICE_NAME = "grpc.testing.LoadBalancerStatsService";

// Static method descriptors that strictly reflect the proto.
private static volatile io.grpc.MethodDescriptor<io.grpc.testing.integration.Messages.LoadBalancerStatsRequest,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public final class MetricsServiceGrpc {

private MetricsServiceGrpc() {}

public static final String SERVICE_NAME = "grpc.testing.MetricsService";
public static final java.lang.String SERVICE_NAME = "grpc.testing.MetricsService";

// Static method descriptors that strictly reflect the proto.
private static volatile io.grpc.MethodDescriptor<io.grpc.testing.integration.Metrics.EmptyMessage,
Expand Down Expand Up @@ -233,14 +233,10 @@ protected MetricsServiceBlockingV2Stub build(
* the service
* </pre>
*/
public io.grpc.stub.BlockingClientCall<io.grpc.testing.integration.Metrics.EmptyMessage,io.grpc.testing.integration.Metrics.GaugeResponse>
public io.grpc.stub.BlockingClientCall<?, io.grpc.testing.integration.Metrics.GaugeResponse>
getAllGauges(io.grpc.testing.integration.Metrics.EmptyMessage request) throws java.lang.InterruptedException {
io.grpc.stub.BlockingClientCall<io.grpc.testing.integration.Metrics.EmptyMessage,io.grpc.testing.integration.Metrics.GaugeResponse> call =
io.grpc.stub.ClientCalls.blockingBidiStreamingCall(
getChannel(), getGetAllGaugesMethod(), getCallOptions());
call.write(request);
call.halfClose();
return call;
return io.grpc.stub.ClientCalls.blockingV2ServerStreamingCall(
getChannel(), getGetAllGaugesMethod(), getCallOptions(), request);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public final class ReconnectServiceGrpc {

private ReconnectServiceGrpc() {}

public static final String SERVICE_NAME = "grpc.testing.ReconnectService";
public static final java.lang.String SERVICE_NAME = "grpc.testing.ReconnectService";

// Static method descriptors that strictly reflect the proto.
private static volatile io.grpc.MethodDescriptor<io.grpc.testing.integration.Messages.ReconnectParams,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public final class TestServiceGrpc {

private TestServiceGrpc() {}

public static final String SERVICE_NAME = "grpc.testing.TestService";
public static final java.lang.String SERVICE_NAME = "grpc.testing.TestService";

// Static method descriptors that strictly reflect the proto.
private static volatile io.grpc.MethodDescriptor<io.grpc.testing.integration.EmptyProtos.Empty,
Expand Down Expand Up @@ -609,14 +609,10 @@ public io.grpc.testing.integration.Messages.SimpleResponse cacheableUnaryCall(io
* The server returns the payload with client desired type and sizes.
* </pre>
*/
public io.grpc.stub.BlockingClientCall<io.grpc.testing.integration.Messages.StreamingOutputCallRequest,io.grpc.testing.integration.Messages.StreamingOutputCallResponse>
public io.grpc.stub.BlockingClientCall<?, io.grpc.testing.integration.Messages.StreamingOutputCallResponse>
streamingOutputCall(io.grpc.testing.integration.Messages.StreamingOutputCallRequest request) throws java.lang.InterruptedException {
io.grpc.stub.BlockingClientCall<io.grpc.testing.integration.Messages.StreamingOutputCallRequest,io.grpc.testing.integration.Messages.StreamingOutputCallResponse> call =
io.grpc.stub.ClientCalls.blockingBidiStreamingCall(
getChannel(), getStreamingOutputCallMethod(), getCallOptions());
call.write(request);
call.halfClose();
return call;
return io.grpc.stub.ClientCalls.blockingV2ServerStreamingCall(
getChannel(), getStreamingOutputCallMethod(), getCallOptions(), request);
}

/**
Expand All @@ -625,9 +621,9 @@ public io.grpc.testing.integration.Messages.SimpleResponse cacheableUnaryCall(io
* The server returns the aggregated size of client payload as the result.
* </pre>
*/
public io.grpc.stub.BlockingClientCall<io.grpc.testing.integration.Messages.StreamingInputCallRequest,io.grpc.testing.integration.Messages.StreamingInputCallResponse>
public io.grpc.stub.BlockingClientCall<io.grpc.testing.integration.Messages.StreamingInputCallRequest, io.grpc.testing.integration.Messages.StreamingInputCallResponse>
streamingInputCall() {
return io.grpc.stub.ClientCalls.blockingBidiStreamingCall(
return io.grpc.stub.ClientCalls.blockingClientStreamingCall(
getChannel(), getStreamingInputCallMethod(), getCallOptions());
}

Expand All @@ -638,7 +634,7 @@ public io.grpc.testing.integration.Messages.SimpleResponse cacheableUnaryCall(io
* demonstrates the idea of full duplexing.
* </pre>
*/
public io.grpc.stub.BlockingClientCall<io.grpc.testing.integration.Messages.StreamingOutputCallRequest,io.grpc.testing.integration.Messages.StreamingOutputCallResponse>
public io.grpc.stub.BlockingClientCall<io.grpc.testing.integration.Messages.StreamingOutputCallRequest, io.grpc.testing.integration.Messages.StreamingOutputCallResponse>
fullDuplexCall() {
return io.grpc.stub.ClientCalls.blockingBidiStreamingCall(
getChannel(), getFullDuplexCallMethod(), getCallOptions());
Expand All @@ -652,7 +648,7 @@ public io.grpc.testing.integration.Messages.SimpleResponse cacheableUnaryCall(io
* first request.
* </pre>
*/
public io.grpc.stub.BlockingClientCall<io.grpc.testing.integration.Messages.StreamingOutputCallRequest,io.grpc.testing.integration.Messages.StreamingOutputCallResponse>
public io.grpc.stub.BlockingClientCall<io.grpc.testing.integration.Messages.StreamingOutputCallRequest, io.grpc.testing.integration.Messages.StreamingOutputCallResponse>
halfDuplexCall() {
return io.grpc.stub.ClientCalls.blockingBidiStreamingCall(
getChannel(), getHalfDuplexCallMethod(), getCallOptions());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public final class UnimplementedServiceGrpc {

private UnimplementedServiceGrpc() {}

public static final String SERVICE_NAME = "grpc.testing.UnimplementedService";
public static final java.lang.String SERVICE_NAME = "grpc.testing.UnimplementedService";

// Static method descriptors that strictly reflect the proto.
private static volatile io.grpc.MethodDescriptor<io.grpc.testing.integration.EmptyProtos.Empty,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public final class XdsUpdateClientConfigureServiceGrpc {

private XdsUpdateClientConfigureServiceGrpc() {}

public static final String SERVICE_NAME = "grpc.testing.XdsUpdateClientConfigureService";
public static final java.lang.String SERVICE_NAME = "grpc.testing.XdsUpdateClientConfigureService";

// Static method descriptors that strictly reflect the proto.
private static volatile io.grpc.MethodDescriptor<io.grpc.testing.integration.Messages.ClientConfigureRequest,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public final class XdsUpdateHealthServiceGrpc {

private XdsUpdateHealthServiceGrpc() {}

public static final String SERVICE_NAME = "grpc.testing.XdsUpdateHealthService";
public static final java.lang.String SERVICE_NAME = "grpc.testing.XdsUpdateHealthService";

// Static method descriptors that strictly reflect the proto.
private static volatile io.grpc.MethodDescriptor<io.grpc.testing.integration.EmptyProtos.Empty,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ public io.grpc.benchmarks.proto.Messages.SimpleResponse unaryCall(io.grpc.benchm
*/
public io.grpc.stub.BlockingClientCall<io.grpc.benchmarks.proto.Messages.SimpleRequest, io.grpc.benchmarks.proto.Messages.SimpleResponse>
streamingFromClient() {
return io.grpc.stub.ClientCalls.blockingBidiStreamingCall(
return io.grpc.stub.ClientCalls.blockingClientStreamingCall(
getChannel(), getStreamingFromClientMethod(), getCallOptions());
}

Expand All @@ -439,12 +439,8 @@ public io.grpc.benchmarks.proto.Messages.SimpleResponse unaryCall(io.grpc.benchm
*/
public io.grpc.stub.BlockingClientCall<?, io.grpc.benchmarks.proto.Messages.SimpleResponse>
streamingFromServer(io.grpc.benchmarks.proto.Messages.SimpleRequest request) throws java.lang.InterruptedException {
io.grpc.stub.BlockingClientCall<io.grpc.benchmarks.proto.Messages.SimpleRequest, io.grpc.benchmarks.proto.Messages.SimpleResponse> call =
io.grpc.stub.ClientCalls.blockingBidiStreamingCall(
getChannel(), getStreamingFromServerMethod(), getCallOptions());
call.write(request);
call.halfClose();
return call;
return io.grpc.stub.ClientCalls.blockingV2ServerStreamingCall(
getChannel(), getStreamingFromServerMethod(), getCallOptions(), request);
}

/**
Expand Down
30 changes: 15 additions & 15 deletions compiler/src/java_plugin/cpp/java_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -806,23 +806,23 @@ static void PrintStub(
" getChannel(), $method_method_name$(), getCallOptions(), $params$);\n");
break;
case BLOCKING_V2_CALL:
if (client_streaming) { // used for both client and bidi
p->Print(
if (client_streaming) { // client and bidi streaming
if (server_streaming) {
(*vars)["calls_method"] = "io.grpc.stub.ClientCalls.blockingBidiStreamingCall";
} else {
(*vars)["calls_method"] = "io.grpc.stub.ClientCalls.blockingClientStreamingCall";
}
p->Print(
*vars,
"return io.grpc.stub.ClientCalls.blockingBidiStreamingCall(\n"
"return $calls_method$(\n"
" getChannel(), $method_method_name$(), getCallOptions());\n");
} else if (server_streaming) {
p->Print(
*vars,
"$BlockingClientCall$<$input_type$, $output_type$> call =\n"
" io.grpc.stub.ClientCalls.blockingBidiStreamingCall(\n"
" getChannel(), $method_method_name$(), getCallOptions());\n"
"call.write(request);\n"
"call.halfClose();\n"
"return call;\n");
} else {
(*vars)["calls_method"] = "io.grpc.stub.ClientCalls.blockingUnaryCall";
(*vars)["params"] = "request";
} else { // server streaming and unary
(*vars)["params"] = "request";
if (server_streaming) {
(*vars)["calls_method"] = "io.grpc.stub.ClientCalls.blockingV2ServerStreamingCall";
} else {
(*vars)["calls_method"] = "io.grpc.stub.ClientCalls.blockingUnaryCall";
}

p->Print(
*vars,
Expand Down
10 changes: 3 additions & 7 deletions compiler/src/test/golden/TestService.java.txt
Original file line number Diff line number Diff line change
Expand Up @@ -593,12 +593,8 @@ public final class TestServiceGrpc {
*/
public io.grpc.stub.BlockingClientCall<?, io.grpc.testing.compiler.Test.StreamingOutputCallResponse>
streamingOutputCall(io.grpc.testing.compiler.Test.StreamingOutputCallRequest request) throws java.lang.InterruptedException {
io.grpc.stub.BlockingClientCall<io.grpc.testing.compiler.Test.StreamingOutputCallRequest, io.grpc.testing.compiler.Test.StreamingOutputCallResponse> call =
io.grpc.stub.ClientCalls.blockingBidiStreamingCall(
getChannel(), getStreamingOutputCallMethod(), getCallOptions());
call.write(request);
call.halfClose();
return call;
return io.grpc.stub.ClientCalls.blockingV2ServerStreamingCall(
getChannel(), getStreamingOutputCallMethod(), getCallOptions(), request);
}

/**
Expand All @@ -609,7 +605,7 @@ public final class TestServiceGrpc {
*/
public io.grpc.stub.BlockingClientCall<io.grpc.testing.compiler.Test.StreamingInputCallRequest, io.grpc.testing.compiler.Test.StreamingInputCallResponse>
streamingInputCall() {
return io.grpc.stub.ClientCalls.blockingBidiStreamingCall(
return io.grpc.stub.ClientCalls.blockingClientStreamingCall(
getChannel(), getStreamingInputCallMethod(), getCallOptions());
}

Expand Down
10 changes: 3 additions & 7 deletions compiler/src/testLite/golden/TestService.java.txt
Original file line number Diff line number Diff line change
Expand Up @@ -585,12 +585,8 @@ public final class TestServiceGrpc {
*/
public io.grpc.stub.BlockingClientCall<?, io.grpc.testing.compiler.Test.StreamingOutputCallResponse>
streamingOutputCall(io.grpc.testing.compiler.Test.StreamingOutputCallRequest request) throws java.lang.InterruptedException {
io.grpc.stub.BlockingClientCall<io.grpc.testing.compiler.Test.StreamingOutputCallRequest, io.grpc.testing.compiler.Test.StreamingOutputCallResponse> call =
io.grpc.stub.ClientCalls.blockingBidiStreamingCall(
getChannel(), getStreamingOutputCallMethod(), getCallOptions());
call.write(request);
call.halfClose();
return call;
return io.grpc.stub.ClientCalls.blockingV2ServerStreamingCall(
getChannel(), getStreamingOutputCallMethod(), getCallOptions(), request);
}

/**
Expand All @@ -601,7 +597,7 @@ public final class TestServiceGrpc {
*/
public io.grpc.stub.BlockingClientCall<io.grpc.testing.compiler.Test.StreamingInputCallRequest, io.grpc.testing.compiler.Test.StreamingInputCallResponse>
streamingInputCall() {
return io.grpc.stub.ClientCalls.blockingBidiStreamingCall(
return io.grpc.stub.ClientCalls.blockingClientStreamingCall(
getChannel(), getStreamingInputCallMethod(), getCallOptions());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,12 +237,8 @@ protected MetricsServiceBlockingV2Stub build(
*/
public io.grpc.stub.BlockingClientCall<?, io.grpc.testing.integration.Metrics.GaugeResponse>
getAllGauges(io.grpc.testing.integration.Metrics.EmptyMessage request) throws java.lang.InterruptedException {
io.grpc.stub.BlockingClientCall<io.grpc.testing.integration.Metrics.EmptyMessage, io.grpc.testing.integration.Metrics.GaugeResponse> call =
io.grpc.stub.ClientCalls.blockingBidiStreamingCall(
getChannel(), getGetAllGaugesMethod(), getCallOptions());
call.write(request);
call.halfClose();
return call;
return io.grpc.stub.ClientCalls.blockingV2ServerStreamingCall(
getChannel(), getGetAllGaugesMethod(), getCallOptions(), request);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -619,12 +619,8 @@ public io.grpc.testing.integration.Messages.SimpleResponse cacheableUnaryCall(io
*/
public io.grpc.stub.BlockingClientCall<?, io.grpc.testing.integration.Messages.StreamingOutputCallResponse>
streamingOutputCall(io.grpc.testing.integration.Messages.StreamingOutputCallRequest request) throws java.lang.InterruptedException {
io.grpc.stub.BlockingClientCall<io.grpc.testing.integration.Messages.StreamingOutputCallRequest, io.grpc.testing.integration.Messages.StreamingOutputCallResponse> call =
io.grpc.stub.ClientCalls.blockingBidiStreamingCall(
getChannel(), getStreamingOutputCallMethod(), getCallOptions());
call.write(request);
call.halfClose();
return call;
return io.grpc.stub.ClientCalls.blockingV2ServerStreamingCall(
getChannel(), getStreamingOutputCallMethod(), getCallOptions(), request);
}

/**
Expand All @@ -635,7 +631,7 @@ public io.grpc.testing.integration.Messages.SimpleResponse cacheableUnaryCall(io
*/
public io.grpc.stub.BlockingClientCall<io.grpc.testing.integration.Messages.StreamingInputCallRequest, io.grpc.testing.integration.Messages.StreamingInputCallResponse>
streamingInputCall() {
return io.grpc.stub.ClientCalls.blockingBidiStreamingCall(
return io.grpc.stub.ClientCalls.blockingClientStreamingCall(
getChannel(), getStreamingInputCallMethod(), getCallOptions());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,12 +283,8 @@ public io.grpc.health.v1.HealthCheckResponse check(io.grpc.health.v1.HealthCheck
*/
public io.grpc.stub.BlockingClientCall<?, io.grpc.health.v1.HealthCheckResponse>
watch(io.grpc.health.v1.HealthCheckRequest request) throws java.lang.InterruptedException {
io.grpc.stub.BlockingClientCall<io.grpc.health.v1.HealthCheckRequest, io.grpc.health.v1.HealthCheckResponse> call =
io.grpc.stub.ClientCalls.blockingBidiStreamingCall(
getChannel(), getWatchMethod(), getCallOptions());
call.write(request);
call.halfClose();
return call;
return io.grpc.stub.ClientCalls.blockingV2ServerStreamingCall(
getChannel(), getWatchMethod(), getCallOptions(), request);
}
}

Expand Down
Loading

0 comments on commit 2104a0f

Please sign in to comment.