Eliminate MethodDescriptor from startCall and interceptCall for servers
Make the MethodDescriptor a property of ServerCall
Move ServerMethodDefinition into ServerServiceDefinition
diff --git a/compiler/src/java_plugin/cpp/java_generator.cpp b/compiler/src/java_plugin/cpp/java_generator.cpp
index de72794..292a6cf 100644
--- a/compiler/src/java_plugin/cpp/java_generator.cpp
+++ b/compiler/src/java_plugin/cpp/java_generator.cpp
@@ -851,6 +851,31 @@
p->Print("}\n\n");
}
+static void PrintGetServiceDescriptorMethod(const ServiceDescriptor* service,
+ map<string, string>* vars,
+ Printer* p,
+ bool generate_nano) {
+ (*vars)["service_name"] = service->name();
+ p->Print(
+ *vars,
+ "public static $ServiceDescriptor$ getServiceDescriptor() {\n");
+ p->Indent();
+ p->Print(*vars,
+ "return new $ServiceDescriptor$(SERVICE_NAME");
+ p->Indent();
+ p->Indent();
+ for (int i = 0; i < service->method_count(); ++i) {
+ const MethodDescriptor* method = service->method(i);
+ (*vars)["method_field_name"] = MethodPropertiesFieldName(method);
+ p->Print(*vars, ",\n$method_field_name$");
+ }
+ p->Print(");\n");
+ p->Outdent();
+ p->Outdent();
+ p->Outdent();
+ p->Print("}\n\n");
+}
+
static void PrintBindServiceMethod(const ServiceDescriptor* service,
map<string, string>* vars,
Printer* p,
@@ -863,7 +888,7 @@
p->Indent();
p->Print(*vars,
"return "
- "$ServerServiceDefinition$.builder(SERVICE_NAME)\n");
+ "$ServerServiceDefinition$.builder(getServiceDescriptor())\n");
p->Indent();
p->Indent();
for (int i = 0; i < service->method_count(); ++i) {
@@ -994,6 +1019,7 @@
PrintStub(service, vars, p, BLOCKING_CLIENT_IMPL, generate_nano);
PrintStub(service, vars, p, FUTURE_CLIENT_IMPL, generate_nano);
PrintMethodHandlerClass(service, vars, p, generate_nano);
+ PrintGetServiceDescriptorMethod(service, vars, p, generate_nano);
PrintBindServiceMethod(service, vars, p, generate_nano);
p->Outdent();
p->Print("}\n");
@@ -1050,6 +1076,8 @@
vars["BindableService"] = "io.grpc.BindableService";
vars["ServerServiceDefinition"] =
"io.grpc.ServerServiceDefinition";
+ vars["ServiceDescriptor"] =
+ "io.grpc.ServiceDescriptor";
vars["AbstractStub"] = "io.grpc.stub.AbstractStub";
vars["ImmutableList"] = "com.google.common.collect.ImmutableList";
vars["Collection"] = "java.util.Collection";
diff --git a/compiler/src/test/golden/TestService.java.txt b/compiler/src/test/golden/TestService.java.txt
index 27da25d..d2db52d 100644
--- a/compiler/src/test/golden/TestService.java.txt
+++ b/compiler/src/test/golden/TestService.java.txt
@@ -400,9 +400,18 @@
}
}
+ public static io.grpc.ServiceDescriptor getServiceDescriptor() {
+ return new io.grpc.ServiceDescriptor(SERVICE_NAME,
+ METHOD_UNARY_CALL,
+ METHOD_STREAMING_OUTPUT_CALL,
+ METHOD_STREAMING_INPUT_CALL,
+ METHOD_FULL_BIDI_CALL,
+ METHOD_HALF_BIDI_CALL);
+ }
+
public static io.grpc.ServerServiceDefinition bindService(
final TestService serviceImpl) {
- return io.grpc.ServerServiceDefinition.builder(SERVICE_NAME)
+ return io.grpc.ServerServiceDefinition.builder(getServiceDescriptor())
.addMethod(
METHOD_UNARY_CALL,
asyncUnaryCall(
diff --git a/compiler/src/testLite/golden/TestService.java.txt b/compiler/src/testLite/golden/TestService.java.txt
index dfd559f..7eb5472 100644
--- a/compiler/src/testLite/golden/TestService.java.txt
+++ b/compiler/src/testLite/golden/TestService.java.txt
@@ -400,9 +400,18 @@
}
}
+ public static io.grpc.ServiceDescriptor getServiceDescriptor() {
+ return new io.grpc.ServiceDescriptor(SERVICE_NAME,
+ METHOD_UNARY_CALL,
+ METHOD_STREAMING_OUTPUT_CALL,
+ METHOD_STREAMING_INPUT_CALL,
+ METHOD_FULL_BIDI_CALL,
+ METHOD_HALF_BIDI_CALL);
+ }
+
public static io.grpc.ServerServiceDefinition bindService(
final TestService serviceImpl) {
- return io.grpc.ServerServiceDefinition.builder(SERVICE_NAME)
+ return io.grpc.ServerServiceDefinition.builder(getServiceDescriptor())
.addMethod(
METHOD_UNARY_CALL,
asyncUnaryCall(
diff --git a/compiler/src/testNano/golden/TestService.java.txt b/compiler/src/testNano/golden/TestService.java.txt
index 27104de..95462db 100644
--- a/compiler/src/testNano/golden/TestService.java.txt
+++ b/compiler/src/testNano/golden/TestService.java.txt
@@ -478,9 +478,18 @@
}
}
+ public static io.grpc.ServiceDescriptor getServiceDescriptor() {
+ return new io.grpc.ServiceDescriptor(SERVICE_NAME,
+ METHOD_UNARY_CALL,
+ METHOD_STREAMING_OUTPUT_CALL,
+ METHOD_STREAMING_INPUT_CALL,
+ METHOD_FULL_BIDI_CALL,
+ METHOD_HALF_BIDI_CALL);
+ }
+
public static io.grpc.ServerServiceDefinition bindService(
final TestService serviceImpl) {
- return io.grpc.ServerServiceDefinition.builder(SERVICE_NAME)
+ return io.grpc.ServerServiceDefinition.builder(getServiceDescriptor())
.addMethod(
METHOD_UNARY_CALL,
asyncUnaryCall(