Provide base methods for Abstract stub
Default implementation returns status UNIMPLEMENTED. This allows adding
new methods to services without breaking existing code.
diff --git a/benchmarks/src/generated/main/grpc/io/grpc/benchmarks/proto/BenchmarkServiceGrpc.java b/benchmarks/src/generated/main/grpc/io/grpc/benchmarks/proto/BenchmarkServiceGrpc.java
index 6ca512f..7323b4a 100644
--- a/benchmarks/src/generated/main/grpc/io/grpc/benchmarks/proto/BenchmarkServiceGrpc.java
+++ b/benchmarks/src/generated/main/grpc/io/grpc/benchmarks/proto/BenchmarkServiceGrpc.java
@@ -12,6 +12,8 @@
import static io.grpc.stub.ServerCalls.asyncServerStreamingCall;
import static io.grpc.stub.ServerCalls.asyncClientStreamingCall;
import static io.grpc.stub.ServerCalls.asyncBidiStreamingCall;
+import static io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall;
+import static io.grpc.stub.ServerCalls.asyncUnimplementedStreamingCall;
@javax.annotation.Generated(
value = "by gRPC proto compiler",
@@ -65,6 +67,25 @@
io.grpc.stub.StreamObserver<io.grpc.benchmarks.proto.Messages.SimpleResponse> responseObserver);
}
+ public static abstract class AbstractBenchmarkService implements BenchmarkService, io.grpc.BindableService {
+
+ @java.lang.Override
+ public void unaryCall(io.grpc.benchmarks.proto.Messages.SimpleRequest request,
+ io.grpc.stub.StreamObserver<io.grpc.benchmarks.proto.Messages.SimpleResponse> responseObserver) {
+ asyncUnimplementedUnaryCall(METHOD_UNARY_CALL, responseObserver);
+ }
+
+ @java.lang.Override
+ public io.grpc.stub.StreamObserver<io.grpc.benchmarks.proto.Messages.SimpleRequest> streamingCall(
+ io.grpc.stub.StreamObserver<io.grpc.benchmarks.proto.Messages.SimpleResponse> responseObserver) {
+ return asyncUnimplementedStreamingCall(METHOD_STREAMING_CALL, responseObserver);
+ }
+
+ @java.lang.Override public io.grpc.ServerServiceDefinition bindService() {
+ return BenchmarkServiceGrpc.bindService(this);
+ }
+ }
+
public static interface BenchmarkServiceBlockingClient {
public io.grpc.benchmarks.proto.Messages.SimpleResponse unaryCall(io.grpc.benchmarks.proto.Messages.SimpleRequest request);
@@ -157,12 +178,6 @@
}
}
- public static abstract class AbstractBenchmarkService implements BenchmarkService, io.grpc.BindableService {
- @Override public io.grpc.ServerServiceDefinition bindService() {
- return BenchmarkServiceGrpc.bindService(this);
- }
- }
-
private static final int METHODID_UNARY_CALL = 0;
private static final int METHODID_STREAMING_CALL = 1;
diff --git a/benchmarks/src/generated/main/grpc/io/grpc/benchmarks/proto/WorkerServiceGrpc.java b/benchmarks/src/generated/main/grpc/io/grpc/benchmarks/proto/WorkerServiceGrpc.java
index 9e27954..552dd04 100644
--- a/benchmarks/src/generated/main/grpc/io/grpc/benchmarks/proto/WorkerServiceGrpc.java
+++ b/benchmarks/src/generated/main/grpc/io/grpc/benchmarks/proto/WorkerServiceGrpc.java
@@ -12,6 +12,8 @@
import static io.grpc.stub.ServerCalls.asyncServerStreamingCall;
import static io.grpc.stub.ServerCalls.asyncClientStreamingCall;
import static io.grpc.stub.ServerCalls.asyncBidiStreamingCall;
+import static io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall;
+import static io.grpc.stub.ServerCalls.asyncUnimplementedStreamingCall;
@javax.annotation.Generated(
value = "by gRPC proto compiler",
@@ -89,6 +91,37 @@
io.grpc.stub.StreamObserver<io.grpc.benchmarks.proto.Control.Void> responseObserver);
}
+ public static abstract class AbstractWorkerService implements WorkerService, io.grpc.BindableService {
+
+ @java.lang.Override
+ public io.grpc.stub.StreamObserver<io.grpc.benchmarks.proto.Control.ServerArgs> runServer(
+ io.grpc.stub.StreamObserver<io.grpc.benchmarks.proto.Control.ServerStatus> responseObserver) {
+ return asyncUnimplementedStreamingCall(METHOD_RUN_SERVER, responseObserver);
+ }
+
+ @java.lang.Override
+ public io.grpc.stub.StreamObserver<io.grpc.benchmarks.proto.Control.ClientArgs> runClient(
+ io.grpc.stub.StreamObserver<io.grpc.benchmarks.proto.Control.ClientStatus> responseObserver) {
+ return asyncUnimplementedStreamingCall(METHOD_RUN_CLIENT, responseObserver);
+ }
+
+ @java.lang.Override
+ public void coreCount(io.grpc.benchmarks.proto.Control.CoreRequest request,
+ io.grpc.stub.StreamObserver<io.grpc.benchmarks.proto.Control.CoreResponse> responseObserver) {
+ asyncUnimplementedUnaryCall(METHOD_CORE_COUNT, responseObserver);
+ }
+
+ @java.lang.Override
+ public void quitWorker(io.grpc.benchmarks.proto.Control.Void request,
+ io.grpc.stub.StreamObserver<io.grpc.benchmarks.proto.Control.Void> responseObserver) {
+ asyncUnimplementedUnaryCall(METHOD_QUIT_WORKER, responseObserver);
+ }
+
+ @java.lang.Override public io.grpc.ServerServiceDefinition bindService() {
+ return WorkerServiceGrpc.bindService(this);
+ }
+ }
+
public static interface WorkerServiceBlockingClient {
public io.grpc.benchmarks.proto.Control.CoreResponse coreCount(io.grpc.benchmarks.proto.Control.CoreRequest request);
@@ -213,12 +246,6 @@
}
}
- public static abstract class AbstractWorkerService implements WorkerService, io.grpc.BindableService {
- @Override public io.grpc.ServerServiceDefinition bindService() {
- return WorkerServiceGrpc.bindService(this);
- }
- }
-
private static final int METHODID_CORE_COUNT = 0;
private static final int METHODID_QUIT_WORKER = 1;
private static final int METHODID_RUN_SERVER = 2;
diff --git a/compiler/src/java_plugin/cpp/java_generator.cpp b/compiler/src/java_plugin/cpp/java_generator.cpp
index 81e452d..0aadd18 100644
--- a/compiler/src/java_plugin/cpp/java_generator.cpp
+++ b/compiler/src/java_plugin/cpp/java_generator.cpp
@@ -155,6 +155,7 @@
if (flavor == ProtoFlavor::NANO) {
p->Print(
+ *vars,
"private static final class NanoFactory<T extends com.google.protobuf.nano.MessageNano>\n"
" implements io.grpc.protobuf.nano.MessageNanoFactory<T> {\n"
" private final int id;\n"
@@ -163,7 +164,7 @@
" this.id = id;\n"
" }\n"
"\n"
- " @Override\n"
+ " @$Override$\n"
" public T newInstance() {\n"
" Object o;\n"
" switch (id) {\n");
@@ -204,7 +205,8 @@
BLOCKING_SERVER_INTERFACE = 3,
ASYNC_CLIENT_IMPL = 4,
BLOCKING_CLIENT_IMPL = 5,
- FUTURE_CLIENT_IMPL = 6
+ FUTURE_CLIENT_IMPL = 6,
+ ABSTRACT = 7,
};
enum CallType {
@@ -219,9 +221,14 @@
map<string, string>* vars,
Printer* p, StubType type, bool generate_nano) {
(*vars)["service_name"] = service->name();
+ (*vars)["abstract_name"] = "Abstract" + service->name();
string interface_name = service->name();
string impl_name = service->name();
+ bool abstract = false;
switch (type) {
+ case ABSTRACT:
+ abstract = true;
+ break;
case ASYNC_INTERFACE:
case ASYNC_CLIENT_IMPL:
impl_name += "Stub";
@@ -242,9 +249,10 @@
default:
GRPC_CODEGEN_FAIL << "Cannot determine class name for StubType: " << type;
}
- bool impl;
CallType call_type;
+ bool impl = false;
switch (type) {
+ case ABSTRACT:
case ASYNC_INTERFACE:
call_type = ASYNC_CALL;
impl = false;
@@ -277,7 +285,12 @@
(*vars)["impl_name"] = impl_name;
// Class head
- if (!impl) {
+ if (abstract) {
+ p->Print(
+ *vars,
+ "public static abstract class $abstract_name$ implements $service_name$, "
+ "$BindableService$ {\n");
+ } else if (!impl) {
p->Print(
*vars,
"public static interface $interface_name$ {\n");
@@ -343,7 +356,7 @@
// Method signature
p->Print("\n");
- if (impl) {
+ if (impl || abstract) {
p->Print(
*vars,
"@$Override$\n");
@@ -395,10 +408,34 @@
" $input_type$ request)");
break;
}
- if (impl) {
- // Method body for client impls
- p->Print(" {\n");
- p->Indent();
+
+ if (!(abstract || impl)) {
+ // Interface method - there will be no body, close method.
+ p->Print(";\n");
+ continue;
+ }
+
+ // Method body for abstract stub & client impls.
+ p->Print(" {\n");
+ p->Indent();
+
+ if (abstract) {
+ switch (call_type) {
+ // NB: Skipping validation of service methods. If something is wrong, we wouldn't get to
+ // this point as compiler would return errors when generating service interface.
+ case ASYNC_CALL:
+ if (client_streaming) {
+ p->Print(
+ *vars,
+ "return asyncUnimplementedStreamingCall($method_field_name$, responseObserver);\n");
+ } else {
+ p->Print(
+ *vars,
+ "asyncUnimplementedUnaryCall($method_field_name$, responseObserver);\n");
+ }
+ break;
+ }
+ } else if (impl) {
switch (call_type) {
case BLOCKING_CALL:
GRPC_CODEGEN_CHECK(!client_streaming)
@@ -451,12 +488,24 @@
" getChannel().newCall($method_field_name$, getCallOptions()), request);\n");
break;
}
- p->Outdent();
- p->Print("}\n");
- } else {
- p->Print(";\n");
}
+ p->Outdent();
+ p->Print("}\n");
}
+
+ if (abstract) {
+ p->Print("\n");
+ p->Print(*vars,
+ "@$Override$ public $ServerServiceDefinition$ bindService() {\n"
+ );
+ p->Indent();
+ p->Print(*vars,
+ "return $service_class_name$.bindService(this);\n"
+ );
+ p->Outdent();
+ p->Print("}\n");
+ }
+
p->Outdent();
p->Print("}\n\n");
}
@@ -642,27 +691,6 @@
p->Print("}\n");
}
-static void PrintAbstractServiceClass(const ServiceDescriptor* service,
- map<string, string>* vars,
- Printer* p) {
- p->Print(
- *vars,
- "public static abstract class Abstract$service_name$"
- " implements $service_name$, $BindableService$ {\n");
- p->Indent();
- p->Print(*vars,
- "@Override public $ServerServiceDefinition$ bindService() {\n"
- );
- p->Indent();
- p->Print(*vars,
- "return $service_class_name$.bindService(this);\n"
- );
- p->Outdent();
- p->Print("}\n");
- p->Outdent();
- p->Print("}\n\n");
-}
-
static void PrintService(const ServiceDescriptor* service,
map<string, string>* vars,
Printer* p,
@@ -720,12 +748,12 @@
bool generate_nano = flavor == ProtoFlavor::NANO;
PrintStub(service, vars, p, ASYNC_INTERFACE, generate_nano);
+ PrintStub(service, vars, p, ABSTRACT, generate_nano);
PrintStub(service, vars, p, BLOCKING_CLIENT_INTERFACE, generate_nano);
PrintStub(service, vars, p, FUTURE_CLIENT_INTERFACE, generate_nano);
PrintStub(service, vars, p, ASYNC_CLIENT_IMPL, generate_nano);
PrintStub(service, vars, p, BLOCKING_CLIENT_IMPL, generate_nano);
PrintStub(service, vars, p, FUTURE_CLIENT_IMPL, generate_nano);
- PrintAbstractServiceClass(service, vars, p);
PrintMethodHandlerClass(service, vars, p, generate_nano);
PrintBindServiceMethod(service, vars, p, generate_nano);
p->Outdent();
@@ -757,7 +785,11 @@
"import static "
"io.grpc.stub.ServerCalls.asyncClientStreamingCall;\n"
"import static "
- "io.grpc.stub.ServerCalls.asyncBidiStreamingCall;\n\n");
+ "io.grpc.stub.ServerCalls.asyncBidiStreamingCall;\n"
+ "import static "
+ "io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall;\n"
+ "import static "
+ "io.grpc.stub.ServerCalls.asyncUnimplementedStreamingCall;\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 b029819..cd82a81 100644
--- a/compiler/src/test/golden/TestService.java.txt
+++ b/compiler/src/test/golden/TestService.java.txt
@@ -12,6 +12,8 @@
import static io.grpc.stub.ServerCalls.asyncServerStreamingCall;
import static io.grpc.stub.ServerCalls.asyncClientStreamingCall;
import static io.grpc.stub.ServerCalls.asyncBidiStreamingCall;
+import static io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall;
+import static io.grpc.stub.ServerCalls.asyncUnimplementedStreamingCall;
@javax.annotation.Generated(
value = "by gRPC proto compiler",
@@ -101,6 +103,43 @@
io.grpc.stub.StreamObserver<io.grpc.testing.integration.Test.StreamingOutputCallResponse> responseObserver);
}
+ public static abstract class AbstractTestService implements TestService, io.grpc.BindableService {
+
+ @java.lang.Override
+ public void unaryCall(io.grpc.testing.integration.Test.SimpleRequest request,
+ io.grpc.stub.StreamObserver<io.grpc.testing.integration.Test.SimpleResponse> responseObserver) {
+ asyncUnimplementedUnaryCall(METHOD_UNARY_CALL, responseObserver);
+ }
+
+ @java.lang.Override
+ public void streamingOutputCall(io.grpc.testing.integration.Test.StreamingOutputCallRequest request,
+ io.grpc.stub.StreamObserver<io.grpc.testing.integration.Test.StreamingOutputCallResponse> responseObserver) {
+ asyncUnimplementedUnaryCall(METHOD_STREAMING_OUTPUT_CALL, responseObserver);
+ }
+
+ @java.lang.Override
+ public io.grpc.stub.StreamObserver<io.grpc.testing.integration.Test.StreamingInputCallRequest> streamingInputCall(
+ io.grpc.stub.StreamObserver<io.grpc.testing.integration.Test.StreamingInputCallResponse> responseObserver) {
+ return asyncUnimplementedStreamingCall(METHOD_STREAMING_INPUT_CALL, responseObserver);
+ }
+
+ @java.lang.Override
+ public io.grpc.stub.StreamObserver<io.grpc.testing.integration.Test.StreamingOutputCallRequest> fullBidiCall(
+ io.grpc.stub.StreamObserver<io.grpc.testing.integration.Test.StreamingOutputCallResponse> responseObserver) {
+ return asyncUnimplementedStreamingCall(METHOD_FULL_BIDI_CALL, responseObserver);
+ }
+
+ @java.lang.Override
+ public io.grpc.stub.StreamObserver<io.grpc.testing.integration.Test.StreamingOutputCallRequest> halfBidiCall(
+ io.grpc.stub.StreamObserver<io.grpc.testing.integration.Test.StreamingOutputCallResponse> responseObserver) {
+ return asyncUnimplementedStreamingCall(METHOD_HALF_BIDI_CALL, responseObserver);
+ }
+
+ @java.lang.Override public io.grpc.ServerServiceDefinition bindService() {
+ return TestServiceGrpc.bindService(this);
+ }
+ }
+
public static interface TestServiceBlockingClient {
public io.grpc.testing.integration.Test.SimpleResponse unaryCall(io.grpc.testing.integration.Test.SimpleRequest request);
@@ -224,12 +263,6 @@
}
}
- public static abstract class AbstractTestService implements TestService, io.grpc.BindableService {
- @Override public io.grpc.ServerServiceDefinition bindService() {
- return TestServiceGrpc.bindService(this);
- }
- }
-
private static final int METHODID_UNARY_CALL = 0;
private static final int METHODID_STREAMING_OUTPUT_CALL = 1;
private static final int METHODID_STREAMING_INPUT_CALL = 2;
diff --git a/compiler/src/testLite/golden/TestService.java.txt b/compiler/src/testLite/golden/TestService.java.txt
index 726bf70..1270fc7 100644
--- a/compiler/src/testLite/golden/TestService.java.txt
+++ b/compiler/src/testLite/golden/TestService.java.txt
@@ -12,6 +12,8 @@
import static io.grpc.stub.ServerCalls.asyncServerStreamingCall;
import static io.grpc.stub.ServerCalls.asyncClientStreamingCall;
import static io.grpc.stub.ServerCalls.asyncBidiStreamingCall;
+import static io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall;
+import static io.grpc.stub.ServerCalls.asyncUnimplementedStreamingCall;
@javax.annotation.Generated(
value = "by gRPC proto compiler",
@@ -101,6 +103,43 @@
io.grpc.stub.StreamObserver<io.grpc.testing.integration.Test.StreamingOutputCallResponse> responseObserver);
}
+ public static abstract class AbstractTestService implements TestService, io.grpc.BindableService {
+
+ @java.lang.Override
+ public void unaryCall(io.grpc.testing.integration.Test.SimpleRequest request,
+ io.grpc.stub.StreamObserver<io.grpc.testing.integration.Test.SimpleResponse> responseObserver) {
+ asyncUnimplementedUnaryCall(METHOD_UNARY_CALL, responseObserver);
+ }
+
+ @java.lang.Override
+ public void streamingOutputCall(io.grpc.testing.integration.Test.StreamingOutputCallRequest request,
+ io.grpc.stub.StreamObserver<io.grpc.testing.integration.Test.StreamingOutputCallResponse> responseObserver) {
+ asyncUnimplementedUnaryCall(METHOD_STREAMING_OUTPUT_CALL, responseObserver);
+ }
+
+ @java.lang.Override
+ public io.grpc.stub.StreamObserver<io.grpc.testing.integration.Test.StreamingInputCallRequest> streamingInputCall(
+ io.grpc.stub.StreamObserver<io.grpc.testing.integration.Test.StreamingInputCallResponse> responseObserver) {
+ return asyncUnimplementedStreamingCall(METHOD_STREAMING_INPUT_CALL, responseObserver);
+ }
+
+ @java.lang.Override
+ public io.grpc.stub.StreamObserver<io.grpc.testing.integration.Test.StreamingOutputCallRequest> fullBidiCall(
+ io.grpc.stub.StreamObserver<io.grpc.testing.integration.Test.StreamingOutputCallResponse> responseObserver) {
+ return asyncUnimplementedStreamingCall(METHOD_FULL_BIDI_CALL, responseObserver);
+ }
+
+ @java.lang.Override
+ public io.grpc.stub.StreamObserver<io.grpc.testing.integration.Test.StreamingOutputCallRequest> halfBidiCall(
+ io.grpc.stub.StreamObserver<io.grpc.testing.integration.Test.StreamingOutputCallResponse> responseObserver) {
+ return asyncUnimplementedStreamingCall(METHOD_HALF_BIDI_CALL, responseObserver);
+ }
+
+ @java.lang.Override public io.grpc.ServerServiceDefinition bindService() {
+ return TestServiceGrpc.bindService(this);
+ }
+ }
+
public static interface TestServiceBlockingClient {
public io.grpc.testing.integration.Test.SimpleResponse unaryCall(io.grpc.testing.integration.Test.SimpleRequest request);
@@ -224,12 +263,6 @@
}
}
- public static abstract class AbstractTestService implements TestService, io.grpc.BindableService {
- @Override public io.grpc.ServerServiceDefinition bindService() {
- return TestServiceGrpc.bindService(this);
- }
- }
-
private static final int METHODID_UNARY_CALL = 0;
private static final int METHODID_STREAMING_OUTPUT_CALL = 1;
private static final int METHODID_STREAMING_INPUT_CALL = 2;
diff --git a/compiler/src/testNano/golden/TestService.java.txt b/compiler/src/testNano/golden/TestService.java.txt
index 0be68b1..88dc9cd 100644
--- a/compiler/src/testNano/golden/TestService.java.txt
+++ b/compiler/src/testNano/golden/TestService.java.txt
@@ -12,6 +12,8 @@
import static io.grpc.stub.ServerCalls.asyncServerStreamingCall;
import static io.grpc.stub.ServerCalls.asyncClientStreamingCall;
import static io.grpc.stub.ServerCalls.asyncBidiStreamingCall;
+import static io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall;
+import static io.grpc.stub.ServerCalls.asyncUnimplementedStreamingCall;
import java.io.IOException;
@@ -104,7 +106,7 @@
this.id = id;
}
- @Override
+ @java.lang.Override
public T newInstance() {
Object o;
switch (id) {
@@ -179,6 +181,43 @@
io.grpc.stub.StreamObserver<io.grpc.testing.integration.nano.Test.StreamingOutputCallResponse> responseObserver);
}
+ public static abstract class AbstractTestService implements TestService, io.grpc.BindableService {
+
+ @java.lang.Override
+ public void unaryCall(io.grpc.testing.integration.nano.Test.SimpleRequest request,
+ io.grpc.stub.StreamObserver<io.grpc.testing.integration.nano.Test.SimpleResponse> responseObserver) {
+ asyncUnimplementedUnaryCall(METHOD_UNARY_CALL, responseObserver);
+ }
+
+ @java.lang.Override
+ public void streamingOutputCall(io.grpc.testing.integration.nano.Test.StreamingOutputCallRequest request,
+ io.grpc.stub.StreamObserver<io.grpc.testing.integration.nano.Test.StreamingOutputCallResponse> responseObserver) {
+ asyncUnimplementedUnaryCall(METHOD_STREAMING_OUTPUT_CALL, responseObserver);
+ }
+
+ @java.lang.Override
+ public io.grpc.stub.StreamObserver<io.grpc.testing.integration.nano.Test.StreamingInputCallRequest> streamingInputCall(
+ io.grpc.stub.StreamObserver<io.grpc.testing.integration.nano.Test.StreamingInputCallResponse> responseObserver) {
+ return asyncUnimplementedStreamingCall(METHOD_STREAMING_INPUT_CALL, responseObserver);
+ }
+
+ @java.lang.Override
+ public io.grpc.stub.StreamObserver<io.grpc.testing.integration.nano.Test.StreamingOutputCallRequest> fullBidiCall(
+ io.grpc.stub.StreamObserver<io.grpc.testing.integration.nano.Test.StreamingOutputCallResponse> responseObserver) {
+ return asyncUnimplementedStreamingCall(METHOD_FULL_BIDI_CALL, responseObserver);
+ }
+
+ @java.lang.Override
+ public io.grpc.stub.StreamObserver<io.grpc.testing.integration.nano.Test.StreamingOutputCallRequest> halfBidiCall(
+ io.grpc.stub.StreamObserver<io.grpc.testing.integration.nano.Test.StreamingOutputCallResponse> responseObserver) {
+ return asyncUnimplementedStreamingCall(METHOD_HALF_BIDI_CALL, responseObserver);
+ }
+
+ @java.lang.Override public io.grpc.ServerServiceDefinition bindService() {
+ return TestServiceGrpc.bindService(this);
+ }
+ }
+
public static interface TestServiceBlockingClient {
public io.grpc.testing.integration.nano.Test.SimpleResponse unaryCall(io.grpc.testing.integration.nano.Test.SimpleRequest request);
@@ -302,12 +341,6 @@
}
}
- public static abstract class AbstractTestService implements TestService, io.grpc.BindableService {
- @Override public io.grpc.ServerServiceDefinition bindService() {
- return TestServiceGrpc.bindService(this);
- }
- }
-
private static final int METHODID_UNARY_CALL = 0;
private static final int METHODID_STREAMING_OUTPUT_CALL = 1;
private static final int METHODID_STREAMING_INPUT_CALL = 2;
diff --git a/examples/src/generated/main/grpc/io/grpc/examples/helloworld/GreeterGrpc.java b/examples/src/generated/main/grpc/io/grpc/examples/helloworld/GreeterGrpc.java
index 3a896df..0771628 100644
--- a/examples/src/generated/main/grpc/io/grpc/examples/helloworld/GreeterGrpc.java
+++ b/examples/src/generated/main/grpc/io/grpc/examples/helloworld/GreeterGrpc.java
@@ -12,6 +12,8 @@
import static io.grpc.stub.ServerCalls.asyncServerStreamingCall;
import static io.grpc.stub.ServerCalls.asyncClientStreamingCall;
import static io.grpc.stub.ServerCalls.asyncBidiStreamingCall;
+import static io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall;
+import static io.grpc.stub.ServerCalls.asyncUnimplementedStreamingCall;
@javax.annotation.Generated(
value = "by gRPC proto compiler",
@@ -53,6 +55,19 @@
io.grpc.stub.StreamObserver<io.grpc.examples.helloworld.HelloReply> responseObserver);
}
+ public static abstract class AbstractGreeter implements Greeter, io.grpc.BindableService {
+
+ @java.lang.Override
+ public void sayHello(io.grpc.examples.helloworld.HelloRequest request,
+ io.grpc.stub.StreamObserver<io.grpc.examples.helloworld.HelloReply> responseObserver) {
+ asyncUnimplementedUnaryCall(METHOD_SAY_HELLO, responseObserver);
+ }
+
+ @java.lang.Override public io.grpc.ServerServiceDefinition bindService() {
+ return GreeterGrpc.bindService(this);
+ }
+ }
+
public static interface GreeterBlockingClient {
public io.grpc.examples.helloworld.HelloReply sayHello(io.grpc.examples.helloworld.HelloRequest request);
@@ -138,12 +153,6 @@
}
}
- public static abstract class AbstractGreeter implements Greeter, io.grpc.BindableService {
- @Override public io.grpc.ServerServiceDefinition bindService() {
- return GreeterGrpc.bindService(this);
- }
- }
-
private static final int METHODID_SAY_HELLO = 0;
private static class MethodHandlers<Req, Resp> implements
diff --git a/examples/src/generated/main/grpc/io/grpc/examples/routeguide/RouteGuideGrpc.java b/examples/src/generated/main/grpc/io/grpc/examples/routeguide/RouteGuideGrpc.java
index 72c3ec2..72c7fb1 100644
--- a/examples/src/generated/main/grpc/io/grpc/examples/routeguide/RouteGuideGrpc.java
+++ b/examples/src/generated/main/grpc/io/grpc/examples/routeguide/RouteGuideGrpc.java
@@ -12,6 +12,8 @@
import static io.grpc.stub.ServerCalls.asyncServerStreamingCall;
import static io.grpc.stub.ServerCalls.asyncClientStreamingCall;
import static io.grpc.stub.ServerCalls.asyncBidiStreamingCall;
+import static io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall;
+import static io.grpc.stub.ServerCalls.asyncUnimplementedStreamingCall;
@javax.annotation.Generated(
value = "by gRPC proto compiler",
@@ -89,6 +91,37 @@
io.grpc.stub.StreamObserver<io.grpc.examples.routeguide.RouteNote> responseObserver);
}
+ public static abstract class AbstractRouteGuide implements RouteGuide, io.grpc.BindableService {
+
+ @java.lang.Override
+ public void getFeature(io.grpc.examples.routeguide.Point request,
+ io.grpc.stub.StreamObserver<io.grpc.examples.routeguide.Feature> responseObserver) {
+ asyncUnimplementedUnaryCall(METHOD_GET_FEATURE, responseObserver);
+ }
+
+ @java.lang.Override
+ public void listFeatures(io.grpc.examples.routeguide.Rectangle request,
+ io.grpc.stub.StreamObserver<io.grpc.examples.routeguide.Feature> responseObserver) {
+ asyncUnimplementedUnaryCall(METHOD_LIST_FEATURES, responseObserver);
+ }
+
+ @java.lang.Override
+ public io.grpc.stub.StreamObserver<io.grpc.examples.routeguide.Point> recordRoute(
+ io.grpc.stub.StreamObserver<io.grpc.examples.routeguide.RouteSummary> responseObserver) {
+ return asyncUnimplementedStreamingCall(METHOD_RECORD_ROUTE, responseObserver);
+ }
+
+ @java.lang.Override
+ public io.grpc.stub.StreamObserver<io.grpc.examples.routeguide.RouteNote> routeChat(
+ io.grpc.stub.StreamObserver<io.grpc.examples.routeguide.RouteNote> responseObserver) {
+ return asyncUnimplementedStreamingCall(METHOD_ROUTE_CHAT, responseObserver);
+ }
+
+ @java.lang.Override public io.grpc.ServerServiceDefinition bindService() {
+ return RouteGuideGrpc.bindService(this);
+ }
+ }
+
public static interface RouteGuideBlockingClient {
public io.grpc.examples.routeguide.Feature getFeature(io.grpc.examples.routeguide.Point request);
@@ -205,12 +238,6 @@
}
}
- public static abstract class AbstractRouteGuide implements RouteGuide, io.grpc.BindableService {
- @Override public io.grpc.ServerServiceDefinition bindService() {
- return RouteGuideGrpc.bindService(this);
- }
- }
-
private static final int METHODID_GET_FEATURE = 0;
private static final int METHODID_LIST_FEATURES = 1;
private static final int METHODID_RECORD_ROUTE = 2;
diff --git a/grpclb/src/generated/main/grpc/io/grpc/grpclb/LoadBalancerGrpc.java b/grpclb/src/generated/main/grpc/io/grpc/grpclb/LoadBalancerGrpc.java
index 5b3c136..dd43cac 100644
--- a/grpclb/src/generated/main/grpc/io/grpc/grpclb/LoadBalancerGrpc.java
+++ b/grpclb/src/generated/main/grpc/io/grpc/grpclb/LoadBalancerGrpc.java
@@ -12,6 +12,8 @@
import static io.grpc.stub.ServerCalls.asyncServerStreamingCall;
import static io.grpc.stub.ServerCalls.asyncClientStreamingCall;
import static io.grpc.stub.ServerCalls.asyncBidiStreamingCall;
+import static io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall;
+import static io.grpc.stub.ServerCalls.asyncUnimplementedStreamingCall;
@javax.annotation.Generated(
value = "by gRPC proto compiler",
@@ -53,6 +55,19 @@
io.grpc.stub.StreamObserver<io.grpc.grpclb.LoadBalanceResponse> responseObserver);
}
+ public static abstract class AbstractLoadBalancer implements LoadBalancer, io.grpc.BindableService {
+
+ @java.lang.Override
+ public io.grpc.stub.StreamObserver<io.grpc.grpclb.LoadBalanceRequest> balanceLoad(
+ io.grpc.stub.StreamObserver<io.grpc.grpclb.LoadBalanceResponse> responseObserver) {
+ return asyncUnimplementedStreamingCall(METHOD_BALANCE_LOAD, responseObserver);
+ }
+
+ @java.lang.Override public io.grpc.ServerServiceDefinition bindService() {
+ return LoadBalancerGrpc.bindService(this);
+ }
+ }
+
public static interface LoadBalancerBlockingClient {
}
@@ -120,12 +135,6 @@
}
}
- public static abstract class AbstractLoadBalancer implements LoadBalancer, io.grpc.BindableService {
- @Override public io.grpc.ServerServiceDefinition bindService() {
- return LoadBalancerGrpc.bindService(this);
- }
- }
-
private static final int METHODID_BALANCE_LOAD = 0;
private static class MethodHandlers<Req, Resp> implements
diff --git a/interop-testing/src/generated/main/grpc/io/grpc/testing/integration/ReconnectServiceGrpc.java b/interop-testing/src/generated/main/grpc/io/grpc/testing/integration/ReconnectServiceGrpc.java
index 4f0e614..5f97637 100644
--- a/interop-testing/src/generated/main/grpc/io/grpc/testing/integration/ReconnectServiceGrpc.java
+++ b/interop-testing/src/generated/main/grpc/io/grpc/testing/integration/ReconnectServiceGrpc.java
@@ -12,6 +12,8 @@
import static io.grpc.stub.ServerCalls.asyncServerStreamingCall;
import static io.grpc.stub.ServerCalls.asyncClientStreamingCall;
import static io.grpc.stub.ServerCalls.asyncBidiStreamingCall;
+import static io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall;
+import static io.grpc.stub.ServerCalls.asyncUnimplementedStreamingCall;
@javax.annotation.Generated(
value = "by gRPC proto compiler",
@@ -65,6 +67,25 @@
io.grpc.stub.StreamObserver<io.grpc.testing.integration.Messages.ReconnectInfo> responseObserver);
}
+ public static abstract class AbstractReconnectService implements ReconnectService, io.grpc.BindableService {
+
+ @java.lang.Override
+ public void start(com.google.protobuf.EmptyProtos.Empty request,
+ io.grpc.stub.StreamObserver<com.google.protobuf.EmptyProtos.Empty> responseObserver) {
+ asyncUnimplementedUnaryCall(METHOD_START, responseObserver);
+ }
+
+ @java.lang.Override
+ public void stop(com.google.protobuf.EmptyProtos.Empty request,
+ io.grpc.stub.StreamObserver<io.grpc.testing.integration.Messages.ReconnectInfo> responseObserver) {
+ asyncUnimplementedUnaryCall(METHOD_STOP, responseObserver);
+ }
+
+ @java.lang.Override public io.grpc.ServerServiceDefinition bindService() {
+ return ReconnectServiceGrpc.bindService(this);
+ }
+ }
+
public static interface ReconnectServiceBlockingClient {
public com.google.protobuf.EmptyProtos.Empty start(com.google.protobuf.EmptyProtos.Empty request);
@@ -175,12 +196,6 @@
}
}
- public static abstract class AbstractReconnectService implements ReconnectService, io.grpc.BindableService {
- @Override public io.grpc.ServerServiceDefinition bindService() {
- return ReconnectServiceGrpc.bindService(this);
- }
- }
-
private static final int METHODID_START = 0;
private static final int METHODID_STOP = 1;
diff --git a/interop-testing/src/generated/main/grpc/io/grpc/testing/integration/TestServiceGrpc.java b/interop-testing/src/generated/main/grpc/io/grpc/testing/integration/TestServiceGrpc.java
index e55df54..cb5648e 100644
--- a/interop-testing/src/generated/main/grpc/io/grpc/testing/integration/TestServiceGrpc.java
+++ b/interop-testing/src/generated/main/grpc/io/grpc/testing/integration/TestServiceGrpc.java
@@ -12,6 +12,8 @@
import static io.grpc.stub.ServerCalls.asyncServerStreamingCall;
import static io.grpc.stub.ServerCalls.asyncClientStreamingCall;
import static io.grpc.stub.ServerCalls.asyncBidiStreamingCall;
+import static io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall;
+import static io.grpc.stub.ServerCalls.asyncUnimplementedStreamingCall;
@javax.annotation.Generated(
value = "by gRPC proto compiler",
@@ -113,6 +115,49 @@
io.grpc.stub.StreamObserver<io.grpc.testing.integration.Messages.StreamingOutputCallResponse> responseObserver);
}
+ public static abstract class AbstractTestService implements TestService, io.grpc.BindableService {
+
+ @java.lang.Override
+ public void emptyCall(com.google.protobuf.EmptyProtos.Empty request,
+ io.grpc.stub.StreamObserver<com.google.protobuf.EmptyProtos.Empty> responseObserver) {
+ asyncUnimplementedUnaryCall(METHOD_EMPTY_CALL, responseObserver);
+ }
+
+ @java.lang.Override
+ public void unaryCall(io.grpc.testing.integration.Messages.SimpleRequest request,
+ io.grpc.stub.StreamObserver<io.grpc.testing.integration.Messages.SimpleResponse> responseObserver) {
+ asyncUnimplementedUnaryCall(METHOD_UNARY_CALL, responseObserver);
+ }
+
+ @java.lang.Override
+ public void streamingOutputCall(io.grpc.testing.integration.Messages.StreamingOutputCallRequest request,
+ io.grpc.stub.StreamObserver<io.grpc.testing.integration.Messages.StreamingOutputCallResponse> responseObserver) {
+ asyncUnimplementedUnaryCall(METHOD_STREAMING_OUTPUT_CALL, responseObserver);
+ }
+
+ @java.lang.Override
+ public io.grpc.stub.StreamObserver<io.grpc.testing.integration.Messages.StreamingInputCallRequest> streamingInputCall(
+ io.grpc.stub.StreamObserver<io.grpc.testing.integration.Messages.StreamingInputCallResponse> responseObserver) {
+ return asyncUnimplementedStreamingCall(METHOD_STREAMING_INPUT_CALL, responseObserver);
+ }
+
+ @java.lang.Override
+ public io.grpc.stub.StreamObserver<io.grpc.testing.integration.Messages.StreamingOutputCallRequest> fullDuplexCall(
+ io.grpc.stub.StreamObserver<io.grpc.testing.integration.Messages.StreamingOutputCallResponse> responseObserver) {
+ return asyncUnimplementedStreamingCall(METHOD_FULL_DUPLEX_CALL, responseObserver);
+ }
+
+ @java.lang.Override
+ public io.grpc.stub.StreamObserver<io.grpc.testing.integration.Messages.StreamingOutputCallRequest> halfDuplexCall(
+ io.grpc.stub.StreamObserver<io.grpc.testing.integration.Messages.StreamingOutputCallResponse> responseObserver) {
+ return asyncUnimplementedStreamingCall(METHOD_HALF_DUPLEX_CALL, responseObserver);
+ }
+
+ @java.lang.Override public io.grpc.ServerServiceDefinition bindService() {
+ return TestServiceGrpc.bindService(this);
+ }
+ }
+
public static interface TestServiceBlockingClient {
public com.google.protobuf.EmptyProtos.Empty emptyCall(com.google.protobuf.EmptyProtos.Empty request);
@@ -261,12 +306,6 @@
}
}
- public static abstract class AbstractTestService implements TestService, io.grpc.BindableService {
- @Override public io.grpc.ServerServiceDefinition bindService() {
- return TestServiceGrpc.bindService(this);
- }
- }
-
private static final int METHODID_EMPTY_CALL = 0;
private static final int METHODID_UNARY_CALL = 1;
private static final int METHODID_STREAMING_OUTPUT_CALL = 2;
diff --git a/interop-testing/src/generated/main/grpc/io/grpc/testing/integration/UnimplementedServiceGrpc.java b/interop-testing/src/generated/main/grpc/io/grpc/testing/integration/UnimplementedServiceGrpc.java
index 7a93922..2005131 100644
--- a/interop-testing/src/generated/main/grpc/io/grpc/testing/integration/UnimplementedServiceGrpc.java
+++ b/interop-testing/src/generated/main/grpc/io/grpc/testing/integration/UnimplementedServiceGrpc.java
@@ -12,6 +12,8 @@
import static io.grpc.stub.ServerCalls.asyncServerStreamingCall;
import static io.grpc.stub.ServerCalls.asyncClientStreamingCall;
import static io.grpc.stub.ServerCalls.asyncBidiStreamingCall;
+import static io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall;
+import static io.grpc.stub.ServerCalls.asyncUnimplementedStreamingCall;
@javax.annotation.Generated(
value = "by gRPC proto compiler",
@@ -53,6 +55,19 @@
io.grpc.stub.StreamObserver<com.google.protobuf.EmptyProtos.Empty> responseObserver);
}
+ public static abstract class AbstractUnimplementedService implements UnimplementedService, io.grpc.BindableService {
+
+ @java.lang.Override
+ public void unimplementedCall(com.google.protobuf.EmptyProtos.Empty request,
+ io.grpc.stub.StreamObserver<com.google.protobuf.EmptyProtos.Empty> responseObserver) {
+ asyncUnimplementedUnaryCall(METHOD_UNIMPLEMENTED_CALL, responseObserver);
+ }
+
+ @java.lang.Override public io.grpc.ServerServiceDefinition bindService() {
+ return UnimplementedServiceGrpc.bindService(this);
+ }
+ }
+
public static interface UnimplementedServiceBlockingClient {
public com.google.protobuf.EmptyProtos.Empty unimplementedCall(com.google.protobuf.EmptyProtos.Empty request);
@@ -138,12 +153,6 @@
}
}
- public static abstract class AbstractUnimplementedService implements UnimplementedService, io.grpc.BindableService {
- @Override public io.grpc.ServerServiceDefinition bindService() {
- return UnimplementedServiceGrpc.bindService(this);
- }
- }
-
private static final int METHODID_UNIMPLEMENTED_CALL = 0;
private static class MethodHandlers<Req, Resp> implements
diff --git a/stub/src/main/java/io/grpc/stub/ServerCalls.java b/stub/src/main/java/io/grpc/stub/ServerCalls.java
index 94c9997..e076e24 100644
--- a/stub/src/main/java/io/grpc/stub/ServerCalls.java
+++ b/stub/src/main/java/io/grpc/stub/ServerCalls.java
@@ -31,6 +31,8 @@
package io.grpc.stub;
+import static com.google.common.base.Preconditions.checkNotNull;
+
import io.grpc.ExperimentalApi;
import io.grpc.Metadata;
import io.grpc.MethodDescriptor;
@@ -349,4 +351,52 @@
public void onComplete() {
}
}
+
+ /**
+ * Sets unimplemented status for method on given response stream for unary call.
+ *
+ * @param methodDescriptor of method for which error will be thrown.
+ * @param responseObserver on which error will be set.
+ */
+ public static void asyncUnimplementedUnaryCall(MethodDescriptor<?, ?> methodDescriptor,
+ StreamObserver<?> responseObserver) {
+ checkNotNull(methodDescriptor);
+ checkNotNull(responseObserver);
+ responseObserver.onError(Status.UNIMPLEMENTED
+ .withDescription(String.format("Method %s is unimplemented",
+ methodDescriptor.getFullMethodName()))
+ .asException());
+ }
+
+ /**
+ * Sets unimplemented status for streaming call.
+ *
+ * @param methodDescriptor of method for which error will be thrown.
+ * @param responseObserver on which error will be set.
+ */
+ public static <T> StreamObserver<T> asyncUnimplementedStreamingCall(
+ MethodDescriptor<?, ?> methodDescriptor, StreamObserver<?> responseObserver) {
+ // NB: For streaming call we want to do the same as for unary call. Fail-fast by setting error
+ // on responseObserver and then return no-op observer.
+ asyncUnimplementedUnaryCall(methodDescriptor, responseObserver);
+ return new NoopStreamObserver<T>();
+ }
+
+ /**
+ * No-op implementation of StreamObserver. Used in abstract stubs for default implementations of
+ * methods which throws UNIMPLEMENTED error and tests.
+ */
+ static class NoopStreamObserver<V> implements StreamObserver<V> {
+ @Override
+ public void onNext(V value) {
+ }
+
+ @Override
+ public void onError(Throwable t) {
+ }
+
+ @Override
+ public void onCompleted() {
+ }
+ }
}
diff --git a/stub/src/test/java/io/grpc/stub/ServerCallsTest.java b/stub/src/test/java/io/grpc/stub/ServerCallsTest.java
index f956230..d92ce91 100644
--- a/stub/src/test/java/io/grpc/stub/ServerCallsTest.java
+++ b/stub/src/test/java/io/grpc/stub/ServerCallsTest.java
@@ -124,7 +124,7 @@
}
});
invokeCalled.set(true);
- return new NoOpStreamObserver();
+ return new ServerCalls.NoopStreamObserver<Integer>();
}
});
ServerCall.Listener<Integer> callListener =
@@ -156,7 +156,7 @@
@Override
public StreamObserver<Integer> invoke(StreamObserver<Integer> responseObserver) {
callObserver.set((ServerCallStreamObserver<Integer>) responseObserver);
- return new NoOpStreamObserver();
+ return new ServerCalls.NoopStreamObserver<Integer>();
}
});
ServerCall.Listener<Integer> callListener =
@@ -184,7 +184,7 @@
@Override
public StreamObserver<Integer> invoke(StreamObserver<Integer> responseObserver) {
callObserver.set((ServerCallStreamObserver<Integer>) responseObserver);
- return new NoOpStreamObserver();
+ return new ServerCalls.NoopStreamObserver<Integer>();
}
});
ServerCall.Listener<Integer> callListener =
@@ -212,7 +212,7 @@
@Override
public StreamObserver<Integer> invoke(StreamObserver<Integer> responseObserver) {
callObserver.set((ServerCallStreamObserver<Integer>) responseObserver);
- return new NoOpStreamObserver();
+ return new ServerCalls.NoopStreamObserver<Integer>();
}
});
ServerCall.Listener<Integer> callListener =
@@ -236,7 +236,7 @@
ServerCallStreamObserver<Integer> serverCallObserver =
(ServerCallStreamObserver<Integer>) responseObserver;
serverCallObserver.disableAutoInboundFlowControl();
- return new NoOpStreamObserver();
+ return new ServerCalls.NoopStreamObserver<Integer>();
}
});
ServerCall.Listener<Integer> callListener =
@@ -328,7 +328,7 @@
semaphore.release();
}
});
- return new NoOpStreamObserver() {
+ return new ServerCalls.NoopStreamObserver<Integer>() {
@Override
public void onCompleted() {
serverCallObserver.onCompleted();
@@ -370,20 +370,6 @@
assertArrayEquals(new int[]{0, 1, 1, 2, 2, 2}, receivedMessages);
}
- private static class NoOpStreamObserver implements StreamObserver<Integer> {
- @Override
- public void onNext(Integer value) {
- }
-
- @Override
- public void onError(Throwable t) {
- }
-
- @Override
- public void onCompleted() {
- }
- }
-
public static class IntegerMarshaller implements MethodDescriptor.Marshaller<Integer> {
@Override
public InputStream stream(Integer value) {