Extract the fully-qualified service name into a public static final field on the service container type.
diff --git a/benchmarks/src/generated/main/grpc/io/grpc/testing/TestServiceGrpc.java b/benchmarks/src/generated/main/grpc/io/grpc/testing/TestServiceGrpc.java
index 13bba51..bb06652 100644
--- a/benchmarks/src/generated/main/grpc/io/grpc/testing/TestServiceGrpc.java
+++ b/benchmarks/src/generated/main/grpc/io/grpc/testing/TestServiceGrpc.java
@@ -16,6 +16,8 @@
@javax.annotation.Generated("by gRPC proto compiler")
public class TestServiceGrpc {
+ public static final String SERVICE_NAME = "grpc.testing.TestService";
+
// Static method descriptors that strictly reflect the proto.
@io.grpc.ExperimentalApi
public static final io.grpc.MethodDescriptor<io.grpc.testing.SimpleRequest,
@@ -153,7 +155,7 @@
public static io.grpc.ServerServiceDefinition bindService(
final TestService serviceImpl) {
- return io.grpc.ServerServiceDefinition.builder("grpc.testing.TestService")
+ return io.grpc.ServerServiceDefinition.builder(SERVICE_NAME)
.addMethod(io.grpc.ServerMethodDefinition.create(
METHOD_UNARY_CALL,
asyncUnaryCall(
diff --git a/benchmarks/src/generated/main/grpc/io/grpc/testing/WorkerGrpc.java b/benchmarks/src/generated/main/grpc/io/grpc/testing/WorkerGrpc.java
index 064389a..6474c55 100644
--- a/benchmarks/src/generated/main/grpc/io/grpc/testing/WorkerGrpc.java
+++ b/benchmarks/src/generated/main/grpc/io/grpc/testing/WorkerGrpc.java
@@ -16,6 +16,8 @@
@javax.annotation.Generated("by gRPC proto compiler")
public class WorkerGrpc {
+ public static final String SERVICE_NAME = "grpc.testing.Worker";
+
// Static method descriptors that strictly reflect the proto.
@io.grpc.ExperimentalApi
public static final io.grpc.MethodDescriptor<io.grpc.testing.ClientArgs,
@@ -135,7 +137,7 @@
public static io.grpc.ServerServiceDefinition bindService(
final Worker serviceImpl) {
- return io.grpc.ServerServiceDefinition.builder("grpc.testing.Worker")
+ return io.grpc.ServerServiceDefinition.builder(SERVICE_NAME)
.addMethod(io.grpc.ServerMethodDefinition.create(
METHOD_RUN_TEST,
asyncBidiStreamingCall(
diff --git a/compiler/src/java_plugin/cpp/java_generator.cpp b/compiler/src/java_plugin/cpp/java_generator.cpp
index ed90c03..d231394 100644
--- a/compiler/src/java_plugin/cpp/java_generator.cpp
+++ b/compiler/src/java_plugin/cpp/java_generator.cpp
@@ -421,7 +421,7 @@
p->Indent();
p->Print(*vars,
"return "
- "$ServerServiceDefinition$.builder(\"$Package$$service_name$\")\n");
+ "$ServerServiceDefinition$.builder(SERVICE_NAME)\n");
p->Indent();
for (int i = 0; i < service->method_count(); ++i) {
const MethodDescriptor* method = service->method(i);
@@ -514,6 +514,11 @@
"public class $service_class_name$ {\n\n");
p->Indent();
+ p->Print(
+ *vars,
+ "public static final String SERVICE_NAME = "
+ "\"$Package$$service_name$\";\n\n");
+
PrintMethodFields(service, vars, p, generate_nano);
p->Print(
diff --git a/compiler/src/test/golden/TestService.java.txt b/compiler/src/test/golden/TestService.java.txt
index 105aaba..9237548 100644
--- a/compiler/src/test/golden/TestService.java.txt
+++ b/compiler/src/test/golden/TestService.java.txt
@@ -16,6 +16,8 @@
@javax.annotation.Generated("by gRPC proto compiler")
public class TestServiceGrpc {
+ public static final String SERVICE_NAME = "grpc.testing.TestService";
+
// Static method descriptors that strictly reflect the proto.
@io.grpc.ExperimentalApi
public static final io.grpc.MethodDescriptor<io.grpc.testing.integration.Test.SimpleRequest,
@@ -220,7 +222,7 @@
public static io.grpc.ServerServiceDefinition bindService(
final TestService serviceImpl) {
- return io.grpc.ServerServiceDefinition.builder("grpc.testing.TestService")
+ return io.grpc.ServerServiceDefinition.builder(SERVICE_NAME)
.addMethod(io.grpc.ServerMethodDefinition.create(
METHOD_UNARY_CALL,
asyncUnaryCall(
diff --git a/compiler/src/test/golden/TestServiceNano.java.txt b/compiler/src/test/golden/TestServiceNano.java.txt
index 916fe6b..5c05e98 100644
--- a/compiler/src/test/golden/TestServiceNano.java.txt
+++ b/compiler/src/test/golden/TestServiceNano.java.txt
@@ -18,6 +18,8 @@
@javax.annotation.Generated("by gRPC proto compiler")
public class TestServiceGrpc {
+ public static final String SERVICE_NAME = "grpc.testing.TestService";
+
// Static method descriptors that strictly reflect the proto.
@io.grpc.ExperimentalApi
public static final io.grpc.MethodDescriptor<io.grpc.testing.integration.nano.Test.SimpleRequest,
@@ -282,7 +284,7 @@
public static io.grpc.ServerServiceDefinition bindService(
final TestService serviceImpl) {
- return io.grpc.ServerServiceDefinition.builder("grpc.testing.TestService")
+ return io.grpc.ServerServiceDefinition.builder(SERVICE_NAME)
.addMethod(io.grpc.ServerMethodDefinition.create(
METHOD_UNARY_CALL,
asyncUnaryCall(
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 1c561b1..a67ac71 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
@@ -16,6 +16,8 @@
@javax.annotation.Generated("by gRPC proto compiler")
public class GreeterGrpc {
+ public static final String SERVICE_NAME = "helloworld.Greeter";
+
// Static method descriptors that strictly reflect the proto.
@io.grpc.ExperimentalApi
public static final io.grpc.MethodDescriptor<io.grpc.examples.helloworld.HelloRequest,
@@ -134,7 +136,7 @@
public static io.grpc.ServerServiceDefinition bindService(
final Greeter serviceImpl) {
- return io.grpc.ServerServiceDefinition.builder("helloworld.Greeter")
+ return io.grpc.ServerServiceDefinition.builder(SERVICE_NAME)
.addMethod(io.grpc.ServerMethodDefinition.create(
METHOD_SAY_HELLO,
asyncUnaryCall(
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 b31df9c..74a50e7 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
@@ -16,6 +16,8 @@
@javax.annotation.Generated("by gRPC proto compiler")
public class RouteGuideGrpc {
+ public static final String SERVICE_NAME = "routeguide.RouteGuide";
+
// Static method descriptors that strictly reflect the proto.
@io.grpc.ExperimentalApi
public static final io.grpc.MethodDescriptor<io.grpc.examples.routeguide.Point,
@@ -201,7 +203,7 @@
public static io.grpc.ServerServiceDefinition bindService(
final RouteGuide serviceImpl) {
- return io.grpc.ServerServiceDefinition.builder("routeguide.RouteGuide")
+ return io.grpc.ServerServiceDefinition.builder(SERVICE_NAME)
.addMethod(io.grpc.ServerMethodDefinition.create(
METHOD_GET_FEATURE,
asyncUnaryCall(
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 d0a151e..9f63b7e 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
@@ -16,6 +16,8 @@
@javax.annotation.Generated("by gRPC proto compiler")
public class ReconnectServiceGrpc {
+ public static final String SERVICE_NAME = "grpc.testing.ReconnectService";
+
// Static method descriptors that strictly reflect the proto.
@io.grpc.ExperimentalApi
public static final io.grpc.MethodDescriptor<com.google.protobuf.EmptyProtos.Empty,
@@ -171,7 +173,7 @@
public static io.grpc.ServerServiceDefinition bindService(
final ReconnectService serviceImpl) {
- return io.grpc.ServerServiceDefinition.builder("grpc.testing.ReconnectService")
+ return io.grpc.ServerServiceDefinition.builder(SERVICE_NAME)
.addMethod(io.grpc.ServerMethodDefinition.create(
METHOD_START,
asyncUnaryCall(
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 d55d6d9..249d793 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
@@ -16,6 +16,8 @@
@javax.annotation.Generated("by gRPC proto compiler")
public class TestServiceGrpc {
+ public static final String SERVICE_NAME = "grpc.testing.TestService";
+
// Static method descriptors that strictly reflect the proto.
@io.grpc.ExperimentalApi
public static final io.grpc.MethodDescriptor<com.google.protobuf.EmptyProtos.Empty,
@@ -257,7 +259,7 @@
public static io.grpc.ServerServiceDefinition bindService(
final TestService serviceImpl) {
- return io.grpc.ServerServiceDefinition.builder("grpc.testing.TestService")
+ return io.grpc.ServerServiceDefinition.builder(SERVICE_NAME)
.addMethod(io.grpc.ServerMethodDefinition.create(
METHOD_EMPTY_CALL,
asyncUnaryCall(
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 9e1f4a9..d7e3e9c 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
@@ -16,6 +16,8 @@
@javax.annotation.Generated("by gRPC proto compiler")
public class UnimplementedServiceGrpc {
+ public static final String SERVICE_NAME = "grpc.testing.UnimplementedService";
+
// Static method descriptors that strictly reflect the proto.
@io.grpc.ExperimentalApi
public static final io.grpc.MethodDescriptor<com.google.protobuf.EmptyProtos.Empty,
@@ -134,7 +136,7 @@
public static io.grpc.ServerServiceDefinition bindService(
final UnimplementedService serviceImpl) {
- return io.grpc.ServerServiceDefinition.builder("grpc.testing.UnimplementedService")
+ return io.grpc.ServerServiceDefinition.builder(SERVICE_NAME)
.addMethod(io.grpc.ServerMethodDefinition.create(
METHOD_UNIMPLEMENTED_CALL,
asyncUnaryCall(