From aff1cac7da3613a9df6b8170f1d09e32fe305f05 Mon Sep 17 00:00:00 2001 From: Eric Gribkoff Date: Thu, 27 Oct 2016 14:34:55 -0700 Subject: [PATCH] Compiler/core changes to support the proto reflection API core: adds @Nullable Object getAttachedObject() to ServiceDescriptor compiler: Plumbing necessary to access proto file descriptors via the reflection service --- .../proto/BenchmarkServiceGrpc.java | 8 + .../benchmarks/proto/WorkerServiceGrpc.java | 8 + .../src/java_plugin/cpp/java_generator.cpp | 68 +++++- compiler/src/test/golden/TestService.java.txt | 8 + .../main/java/io/grpc/ServiceDescriptor.java | 23 ++ .../grpc/io/grpc/grpclb/LoadBalancerGrpc.java | 8 + .../integration/MetricsServiceGrpc.java | 8 + .../integration/ReconnectServiceGrpc.java | 8 + .../testing/integration/TestServiceGrpc.java | 8 + .../integration/UnimplementedServiceGrpc.java | 8 + .../v1alpha/ServerReflectionGrpc.java | 216 +++++++++++++++++ .../testing/ReflectableServiceGrpc.java | 224 ++++++++++++++++++ .../ProtoFileDescriptorWrapper.java | 42 ++++ .../grpc/io/grpc/health/v1/HealthGrpc.java | 8 + 14 files changed, 633 insertions(+), 12 deletions(-) create mode 100644 protobuf/src/generated/main/grpc/io/grpc/reflection/v1alpha/ServerReflectionGrpc.java create mode 100644 protobuf/src/generated/test/grpc/io/grpc/reflection/testing/ReflectableServiceGrpc.java create mode 100644 protobuf/src/main/java/io/grpc/protobuf/reflection/ProtoFileDescriptorWrapper.java 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 f9547cc2d8..3cb9149e93 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 @@ -262,11 +262,19 @@ public class BenchmarkServiceGrpc { } } + public static final class BenchmarkServiceDescriptorWrapper implements io.grpc.protobuf.reflection.ProtoFileDescriptorWrapper { + @java.lang.Override + public com.google.protobuf.Descriptors.FileDescriptor getFileDescriptor() { + return io.grpc.benchmarks.proto.Services.getDescriptor(); + } + } + private static io.grpc.ServiceDescriptor serviceDescriptor; public static synchronized io.grpc.ServiceDescriptor getServiceDescriptor() { if (serviceDescriptor == null) { serviceDescriptor = new io.grpc.ServiceDescriptor(SERVICE_NAME, + new BenchmarkServiceDescriptorWrapper(), METHOD_UNARY_CALL, METHOD_STREAMING_CALL); } 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 e17f80b005..e686cd3a04 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 @@ -380,11 +380,19 @@ public class WorkerServiceGrpc { } } + public static final class WorkerServiceDescriptorWrapper implements io.grpc.protobuf.reflection.ProtoFileDescriptorWrapper { + @java.lang.Override + public com.google.protobuf.Descriptors.FileDescriptor getFileDescriptor() { + return io.grpc.benchmarks.proto.Services.getDescriptor(); + } + } + private static io.grpc.ServiceDescriptor serviceDescriptor; public static synchronized io.grpc.ServiceDescriptor getServiceDescriptor() { if (serviceDescriptor == null) { serviceDescriptor = new io.grpc.ServiceDescriptor(SERVICE_NAME, + new WorkerServiceDescriptorWrapper(), METHOD_RUN_SERVER, METHOD_RUN_CLIENT, METHOD_CORE_COUNT, diff --git a/compiler/src/java_plugin/cpp/java_generator.cpp b/compiler/src/java_plugin/cpp/java_generator.cpp index 7c9045eea9..d209f6847d 100644 --- a/compiler/src/java_plugin/cpp/java_generator.cpp +++ b/compiler/src/java_plugin/cpp/java_generator.cpp @@ -884,21 +884,63 @@ static void PrintMethodHandlerClass(const ServiceDescriptor* service, static void PrintGetServiceDescriptorMethod(const ServiceDescriptor* service, map* vars, Printer* p, - bool generate_nano) { + ProtoFlavor flavor) { (*vars)["service_name"] = service->name(); - p->Print( + + + if (flavor == ProtoFlavor::NORMAL) { + (*vars)["proto_descriptor_wrapper"] = service->name() + "DescriptorWrapper"; + (*vars)["proto_class_name"] = google::protobuf::compiler::java::ClassName(service->file()); + p->Print( + *vars, + "public static final class $proto_descriptor_wrapper$ implements $ProtoFileDescriptorWrapper$ {\n"); + p->Indent(); + p->Print(*vars, "@$Override$\n"); + p->Print( + *vars, + "public com.google.protobuf.Descriptors.FileDescriptor getFileDescriptor() {\n"); + p->Indent(); + p->Print(*vars, "return $proto_class_name$.getDescriptor();\n"); + p->Outdent(); + p->Print(*vars, "}\n"); + p->Outdent(); + p->Print(*vars, "}\n\n"); + + p->Print( + *vars, + "private static $ServiceDescriptor$ serviceDescriptor;\n\n"); + + p->Print( + *vars, + "public static synchronized $ServiceDescriptor$ getServiceDescriptor() {\n"); + p->Indent(); + p->Print("if (serviceDescriptor == null) {\n"); + p->Indent(); + p->Print( + *vars, + "serviceDescriptor = new $ServiceDescriptor$(SERVICE_NAME,\n"); + p->Indent(); + p->Indent(); + p->Print( + *vars, + "new $proto_descriptor_wrapper$()"); + p->Outdent(); + p->Outdent(); + } else { + p->Print( *vars, "private static $ServiceDescriptor$ serviceDescriptor;\n\n"); + p->Print( + *vars, + "public static synchronized $ServiceDescriptor$ getServiceDescriptor() {\n"); + p->Indent(); + p->Print("if (serviceDescriptor == null) {\n"); + p->Indent(); + p->Print( + *vars, + "serviceDescriptor = new $ServiceDescriptor$(SERVICE_NAME"); + } - p->Print( - *vars, - "public static synchronized $ServiceDescriptor$ getServiceDescriptor() {\n"); - p->Indent(); - p->Print("if (serviceDescriptor == null) {\n"); - p->Indent(); - p->Print( - *vars, - "serviceDescriptor = new $ServiceDescriptor$(SERVICE_NAME"); p->Indent(); p->Indent(); for (int i = 0; i < service->method_count(); ++i) { @@ -1078,7 +1120,7 @@ static void PrintService(const ServiceDescriptor* service, "}\n\n"); } PrintMethodHandlerClass(service, vars, p, generate_nano, enable_deprecated); - PrintGetServiceDescriptorMethod(service, vars, p, generate_nano); + PrintGetServiceDescriptorMethod(service, vars, p, flavor); p->Outdent(); p->Print("}\n"); } @@ -1138,6 +1180,8 @@ void GenerateService(const ServiceDescriptor* service, "io.grpc.ServerServiceDefinition"; vars["ServiceDescriptor"] = "io.grpc.ServiceDescriptor"; + vars["ProtoFileDescriptorWrapper"] = + "io.grpc.protobuf.reflection.ProtoFileDescriptorWrapper"; vars["AbstractStub"] = "io.grpc.stub.AbstractStub"; vars["MethodDescriptor"] = "io.grpc.MethodDescriptor"; vars["NanoUtils"] = "io.grpc.protobuf.nano.NanoUtils"; diff --git a/compiler/src/test/golden/TestService.java.txt b/compiler/src/test/golden/TestService.java.txt index f6715a2550..31650c1f23 100644 --- a/compiler/src/test/golden/TestService.java.txt +++ b/compiler/src/test/golden/TestService.java.txt @@ -425,11 +425,19 @@ public class TestServiceGrpc { } } + public static final class TestServiceDescriptorWrapper implements io.grpc.protobuf.reflection.ProtoFileDescriptorWrapper { + @java.lang.Override + public com.google.protobuf.Descriptors.FileDescriptor getFileDescriptor() { + return io.grpc.testing.integration.Test.getDescriptor(); + } + } + private static io.grpc.ServiceDescriptor serviceDescriptor; public static synchronized io.grpc.ServiceDescriptor getServiceDescriptor() { if (serviceDescriptor == null) { serviceDescriptor = new io.grpc.ServiceDescriptor(SERVICE_NAME, + new TestServiceDescriptorWrapper(), METHOD_UNARY_CALL, METHOD_STREAMING_OUTPUT_CALL, METHOD_STREAMING_INPUT_CALL, diff --git a/core/src/main/java/io/grpc/ServiceDescriptor.java b/core/src/main/java/io/grpc/ServiceDescriptor.java index 37359074ca..a378bd799f 100644 --- a/core/src/main/java/io/grpc/ServiceDescriptor.java +++ b/core/src/main/java/io/grpc/ServiceDescriptor.java @@ -38,6 +38,8 @@ import java.util.Arrays; import java.util.Collection; import java.util.Collections; +import javax.annotation.Nullable; + /** * Descriptor for a service. */ @@ -45,6 +47,7 @@ public final class ServiceDescriptor { private final String name; private final Collection> methods; + private Object attachedObject = null; public ServiceDescriptor(String name, MethodDescriptor... methods) { this(name, Arrays.asList(methods)); @@ -55,6 +58,17 @@ public final class ServiceDescriptor { this.methods = Collections.unmodifiableList(new ArrayList>(methods)); } + public ServiceDescriptor(String name, Object attachedObject, MethodDescriptor... methods) { + this(name, methods); + this.attachedObject = attachedObject; + } + + public ServiceDescriptor(String name, Object attachedObject, + Collection> methods) { + this(name, methods); + this.attachedObject = attachedObject; + } + /** Simple name of the service. It is not an absolute path. */ public String getName() { return name; @@ -67,4 +81,13 @@ public final class ServiceDescriptor { public Collection> getMethods() { return methods; } + + /** + * The generated code may attach an object to a service descriptor, such as the proto codegen + * attaching a object that allows retrieving the underlying proto object. + */ + @Nullable + public Object getAttachedObject() { + return attachedObject; + } } \ No newline at end of file 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 c548399a9a..793e337db3 100644 --- a/grpclb/src/generated/main/grpc/io/grpc/grpclb/LoadBalancerGrpc.java +++ b/grpclb/src/generated/main/grpc/io/grpc/grpclb/LoadBalancerGrpc.java @@ -193,11 +193,19 @@ public class LoadBalancerGrpc { } } + public static final class LoadBalancerDescriptorWrapper implements io.grpc.protobuf.reflection.ProtoFileDescriptorWrapper { + @java.lang.Override + public com.google.protobuf.Descriptors.FileDescriptor getFileDescriptor() { + return io.grpc.grpclb.LoadBalancerProto.getDescriptor(); + } + } + private static io.grpc.ServiceDescriptor serviceDescriptor; public static synchronized io.grpc.ServiceDescriptor getServiceDescriptor() { if (serviceDescriptor == null) { serviceDescriptor = new io.grpc.ServiceDescriptor(SERVICE_NAME, + new LoadBalancerDescriptorWrapper(), METHOD_BALANCE_LOAD); } diff --git a/interop-testing/src/generated/main/grpc/io/grpc/testing/integration/MetricsServiceGrpc.java b/interop-testing/src/generated/main/grpc/io/grpc/testing/integration/MetricsServiceGrpc.java index 1ebca18f1b..476ed40aa0 100644 --- a/interop-testing/src/generated/main/grpc/io/grpc/testing/integration/MetricsServiceGrpc.java +++ b/interop-testing/src/generated/main/grpc/io/grpc/testing/integration/MetricsServiceGrpc.java @@ -271,11 +271,19 @@ public class MetricsServiceGrpc { } } + public static final class MetricsServiceDescriptorWrapper implements io.grpc.protobuf.reflection.ProtoFileDescriptorWrapper { + @java.lang.Override + public com.google.protobuf.Descriptors.FileDescriptor getFileDescriptor() { + return io.grpc.testing.integration.Metrics.getDescriptor(); + } + } + private static io.grpc.ServiceDescriptor serviceDescriptor; public static synchronized io.grpc.ServiceDescriptor getServiceDescriptor() { if (serviceDescriptor == null) { serviceDescriptor = new io.grpc.ServiceDescriptor(SERVICE_NAME, + new MetricsServiceDescriptorWrapper(), METHOD_GET_ALL_GAUGES, METHOD_GET_GAUGE); } 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 3ca4b1c697..5e395b4f0d 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 @@ -269,11 +269,19 @@ public class ReconnectServiceGrpc { } } + public static final class ReconnectServiceDescriptorWrapper implements io.grpc.protobuf.reflection.ProtoFileDescriptorWrapper { + @java.lang.Override + public com.google.protobuf.Descriptors.FileDescriptor getFileDescriptor() { + return io.grpc.testing.integration.Test.getDescriptor(); + } + } + private static io.grpc.ServiceDescriptor serviceDescriptor; public static synchronized io.grpc.ServiceDescriptor getServiceDescriptor() { if (serviceDescriptor == null) { serviceDescriptor = new io.grpc.ServiceDescriptor(SERVICE_NAME, + new ReconnectServiceDescriptorWrapper(), METHOD_START, METHOD_STOP); } 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 f73b1d06ed..09ced170e2 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 @@ -556,11 +556,19 @@ public class TestServiceGrpc { } } + public static final class TestServiceDescriptorWrapper implements io.grpc.protobuf.reflection.ProtoFileDescriptorWrapper { + @java.lang.Override + public com.google.protobuf.Descriptors.FileDescriptor getFileDescriptor() { + return io.grpc.testing.integration.Test.getDescriptor(); + } + } + private static io.grpc.ServiceDescriptor serviceDescriptor; public static synchronized io.grpc.ServiceDescriptor getServiceDescriptor() { if (serviceDescriptor == null) { serviceDescriptor = new io.grpc.ServiceDescriptor(SERVICE_NAME, + new TestServiceDescriptorWrapper(), METHOD_EMPTY_CALL, METHOD_UNARY_CALL, METHOD_STREAMING_OUTPUT_CALL, 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 8200a2f586..3bde78e291 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 @@ -235,11 +235,19 @@ public class UnimplementedServiceGrpc { } } + public static final class UnimplementedServiceDescriptorWrapper implements io.grpc.protobuf.reflection.ProtoFileDescriptorWrapper { + @java.lang.Override + public com.google.protobuf.Descriptors.FileDescriptor getFileDescriptor() { + return io.grpc.testing.integration.Test.getDescriptor(); + } + } + private static io.grpc.ServiceDescriptor serviceDescriptor; public static synchronized io.grpc.ServiceDescriptor getServiceDescriptor() { if (serviceDescriptor == null) { serviceDescriptor = new io.grpc.ServiceDescriptor(SERVICE_NAME, + new UnimplementedServiceDescriptorWrapper(), METHOD_UNIMPLEMENTED_CALL); } diff --git a/protobuf/src/generated/main/grpc/io/grpc/reflection/v1alpha/ServerReflectionGrpc.java b/protobuf/src/generated/main/grpc/io/grpc/reflection/v1alpha/ServerReflectionGrpc.java new file mode 100644 index 0000000000..b5663a7fb6 --- /dev/null +++ b/protobuf/src/generated/main/grpc/io/grpc/reflection/v1alpha/ServerReflectionGrpc.java @@ -0,0 +1,216 @@ +package io.grpc.reflection.v1alpha; + +import static io.grpc.stub.ClientCalls.asyncUnaryCall; +import static io.grpc.stub.ClientCalls.asyncServerStreamingCall; +import static io.grpc.stub.ClientCalls.asyncClientStreamingCall; +import static io.grpc.stub.ClientCalls.asyncBidiStreamingCall; +import static io.grpc.stub.ClientCalls.blockingUnaryCall; +import static io.grpc.stub.ClientCalls.blockingServerStreamingCall; +import static io.grpc.stub.ClientCalls.futureUnaryCall; +import static io.grpc.MethodDescriptor.generateFullMethodName; +import static io.grpc.stub.ServerCalls.asyncUnaryCall; +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 (version 1.1.0-SNAPSHOT)", + comments = "Source: io/grpc/reflection/v1alpha/reflection.proto") +public class ServerReflectionGrpc { + + private ServerReflectionGrpc() {} + + public static final String SERVICE_NAME = "grpc.reflection.v1alpha.ServerReflection"; + + // Static method descriptors that strictly reflect the proto. + @io.grpc.ExperimentalApi("https://github.com/grpc/grpc-java/issues/1901") + public static final io.grpc.MethodDescriptor METHOD_SERVER_REFLECTION_INFO = + io.grpc.MethodDescriptor.create( + io.grpc.MethodDescriptor.MethodType.BIDI_STREAMING, + generateFullMethodName( + "grpc.reflection.v1alpha.ServerReflection", "ServerReflectionInfo"), + io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.reflection.v1alpha.ServerReflectionRequest.getDefaultInstance()), + io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.reflection.v1alpha.ServerReflectionResponse.getDefaultInstance())); + + /** + * Creates a new async stub that supports all call types for the service + */ + public static ServerReflectionStub newStub(io.grpc.Channel channel) { + return new ServerReflectionStub(channel); + } + + /** + * Creates a new blocking-style stub that supports unary and streaming output calls on the service + */ + public static ServerReflectionBlockingStub newBlockingStub( + io.grpc.Channel channel) { + return new ServerReflectionBlockingStub(channel); + } + + /** + * Creates a new ListenableFuture-style stub that supports unary and streaming output calls on the service + */ + public static ServerReflectionFutureStub newFutureStub( + io.grpc.Channel channel) { + return new ServerReflectionFutureStub(channel); + } + + /** + */ + public static abstract class ServerReflectionImplBase implements io.grpc.BindableService { + + /** + *
+     * The reflection service is structured as a bidirectional stream, ensuring
+     * all related requests go to a single server.
+     * 
+ */ + public io.grpc.stub.StreamObserver serverReflectionInfo( + io.grpc.stub.StreamObserver responseObserver) { + return asyncUnimplementedStreamingCall(METHOD_SERVER_REFLECTION_INFO, responseObserver); + } + + @java.lang.Override public io.grpc.ServerServiceDefinition bindService() { + return io.grpc.ServerServiceDefinition.builder(getServiceDescriptor()) + .addMethod( + METHOD_SERVER_REFLECTION_INFO, + asyncBidiStreamingCall( + new MethodHandlers< + io.grpc.reflection.v1alpha.ServerReflectionRequest, + io.grpc.reflection.v1alpha.ServerReflectionResponse>( + this, METHODID_SERVER_REFLECTION_INFO))) + .build(); + } + } + + /** + */ + public static final class ServerReflectionStub extends io.grpc.stub.AbstractStub { + private ServerReflectionStub(io.grpc.Channel channel) { + super(channel); + } + + private ServerReflectionStub(io.grpc.Channel channel, + io.grpc.CallOptions callOptions) { + super(channel, callOptions); + } + + @java.lang.Override + protected ServerReflectionStub build(io.grpc.Channel channel, + io.grpc.CallOptions callOptions) { + return new ServerReflectionStub(channel, callOptions); + } + + /** + *
+     * The reflection service is structured as a bidirectional stream, ensuring
+     * all related requests go to a single server.
+     * 
+ */ + public io.grpc.stub.StreamObserver serverReflectionInfo( + io.grpc.stub.StreamObserver responseObserver) { + return asyncBidiStreamingCall( + getChannel().newCall(METHOD_SERVER_REFLECTION_INFO, getCallOptions()), responseObserver); + } + } + + /** + */ + public static final class ServerReflectionBlockingStub extends io.grpc.stub.AbstractStub { + private ServerReflectionBlockingStub(io.grpc.Channel channel) { + super(channel); + } + + private ServerReflectionBlockingStub(io.grpc.Channel channel, + io.grpc.CallOptions callOptions) { + super(channel, callOptions); + } + + @java.lang.Override + protected ServerReflectionBlockingStub build(io.grpc.Channel channel, + io.grpc.CallOptions callOptions) { + return new ServerReflectionBlockingStub(channel, callOptions); + } + } + + /** + */ + public static final class ServerReflectionFutureStub extends io.grpc.stub.AbstractStub { + private ServerReflectionFutureStub(io.grpc.Channel channel) { + super(channel); + } + + private ServerReflectionFutureStub(io.grpc.Channel channel, + io.grpc.CallOptions callOptions) { + super(channel, callOptions); + } + + @java.lang.Override + protected ServerReflectionFutureStub build(io.grpc.Channel channel, + io.grpc.CallOptions callOptions) { + return new ServerReflectionFutureStub(channel, callOptions); + } + } + + private static final int METHODID_SERVER_REFLECTION_INFO = 0; + + private static class MethodHandlers implements + io.grpc.stub.ServerCalls.UnaryMethod, + io.grpc.stub.ServerCalls.ServerStreamingMethod, + io.grpc.stub.ServerCalls.ClientStreamingMethod, + io.grpc.stub.ServerCalls.BidiStreamingMethod { + private final ServerReflectionImplBase serviceImpl; + private final int methodId; + + public MethodHandlers(ServerReflectionImplBase serviceImpl, int methodId) { + this.serviceImpl = serviceImpl; + this.methodId = methodId; + } + + @java.lang.Override + @java.lang.SuppressWarnings("unchecked") + public void invoke(Req request, io.grpc.stub.StreamObserver responseObserver) { + switch (methodId) { + default: + throw new AssertionError(); + } + } + + @java.lang.Override + @java.lang.SuppressWarnings("unchecked") + public io.grpc.stub.StreamObserver invoke( + io.grpc.stub.StreamObserver responseObserver) { + switch (methodId) { + case METHODID_SERVER_REFLECTION_INFO: + return (io.grpc.stub.StreamObserver) serviceImpl.serverReflectionInfo( + (io.grpc.stub.StreamObserver) responseObserver); + default: + throw new AssertionError(); + } + } + } + + public static final class ServerReflectionDescriptorWrapper implements io.grpc.protobuf.reflection.ProtoFileDescriptorWrapper { + @java.lang.Override + public com.google.protobuf.Descriptors.FileDescriptor getFileDescriptor() { + return io.grpc.reflection.v1alpha.ServerReflectionProto.getDescriptor(); + } + } + + private static io.grpc.ServiceDescriptor serviceDescriptor; + + public static synchronized io.grpc.ServiceDescriptor getServiceDescriptor() { + if (serviceDescriptor == null) { + serviceDescriptor = new io.grpc.ServiceDescriptor(SERVICE_NAME, + new ServerReflectionDescriptorWrapper(), + METHOD_SERVER_REFLECTION_INFO); + } + + return serviceDescriptor; + } +} diff --git a/protobuf/src/generated/test/grpc/io/grpc/reflection/testing/ReflectableServiceGrpc.java b/protobuf/src/generated/test/grpc/io/grpc/reflection/testing/ReflectableServiceGrpc.java new file mode 100644 index 0000000000..99398bae39 --- /dev/null +++ b/protobuf/src/generated/test/grpc/io/grpc/reflection/testing/ReflectableServiceGrpc.java @@ -0,0 +1,224 @@ +package io.grpc.reflection.testing; + +import static io.grpc.stub.ClientCalls.asyncUnaryCall; +import static io.grpc.stub.ClientCalls.asyncServerStreamingCall; +import static io.grpc.stub.ClientCalls.asyncClientStreamingCall; +import static io.grpc.stub.ClientCalls.asyncBidiStreamingCall; +import static io.grpc.stub.ClientCalls.blockingUnaryCall; +import static io.grpc.stub.ClientCalls.blockingServerStreamingCall; +import static io.grpc.stub.ClientCalls.futureUnaryCall; +import static io.grpc.MethodDescriptor.generateFullMethodName; +import static io.grpc.stub.ServerCalls.asyncUnaryCall; +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 (version 1.1.0-SNAPSHOT)", + comments = "Source: io/grpc/reflection/testing/reflection_test.proto") +public class ReflectableServiceGrpc { + + private ReflectableServiceGrpc() {} + + public static final String SERVICE_NAME = "grpc.reflection.testing.ReflectableService"; + + // Static method descriptors that strictly reflect the proto. + @io.grpc.ExperimentalApi("https://github.com/grpc/grpc-java/issues/1901") + public static final io.grpc.MethodDescriptor METHOD_METHOD = + io.grpc.MethodDescriptor.create( + io.grpc.MethodDescriptor.MethodType.UNARY, + generateFullMethodName( + "grpc.reflection.testing.ReflectableService", "Method"), + io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.reflection.testing.Request.getDefaultInstance()), + io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.reflection.testing.Reply.getDefaultInstance())); + + /** + * Creates a new async stub that supports all call types for the service + */ + public static ReflectableServiceStub newStub(io.grpc.Channel channel) { + return new ReflectableServiceStub(channel); + } + + /** + * Creates a new blocking-style stub that supports unary and streaming output calls on the service + */ + public static ReflectableServiceBlockingStub newBlockingStub( + io.grpc.Channel channel) { + return new ReflectableServiceBlockingStub(channel); + } + + /** + * Creates a new ListenableFuture-style stub that supports unary and streaming output calls on the service + */ + public static ReflectableServiceFutureStub newFutureStub( + io.grpc.Channel channel) { + return new ReflectableServiceFutureStub(channel); + } + + /** + */ + public static abstract class ReflectableServiceImplBase implements io.grpc.BindableService { + + /** + */ + public void method(io.grpc.reflection.testing.Request request, + io.grpc.stub.StreamObserver responseObserver) { + asyncUnimplementedUnaryCall(METHOD_METHOD, responseObserver); + } + + @java.lang.Override public io.grpc.ServerServiceDefinition bindService() { + return io.grpc.ServerServiceDefinition.builder(getServiceDescriptor()) + .addMethod( + METHOD_METHOD, + asyncUnaryCall( + new MethodHandlers< + io.grpc.reflection.testing.Request, + io.grpc.reflection.testing.Reply>( + this, METHODID_METHOD))) + .build(); + } + } + + /** + */ + public static final class ReflectableServiceStub extends io.grpc.stub.AbstractStub { + private ReflectableServiceStub(io.grpc.Channel channel) { + super(channel); + } + + private ReflectableServiceStub(io.grpc.Channel channel, + io.grpc.CallOptions callOptions) { + super(channel, callOptions); + } + + @java.lang.Override + protected ReflectableServiceStub build(io.grpc.Channel channel, + io.grpc.CallOptions callOptions) { + return new ReflectableServiceStub(channel, callOptions); + } + + /** + */ + public void method(io.grpc.reflection.testing.Request request, + io.grpc.stub.StreamObserver responseObserver) { + asyncUnaryCall( + getChannel().newCall(METHOD_METHOD, getCallOptions()), request, responseObserver); + } + } + + /** + */ + public static final class ReflectableServiceBlockingStub extends io.grpc.stub.AbstractStub { + private ReflectableServiceBlockingStub(io.grpc.Channel channel) { + super(channel); + } + + private ReflectableServiceBlockingStub(io.grpc.Channel channel, + io.grpc.CallOptions callOptions) { + super(channel, callOptions); + } + + @java.lang.Override + protected ReflectableServiceBlockingStub build(io.grpc.Channel channel, + io.grpc.CallOptions callOptions) { + return new ReflectableServiceBlockingStub(channel, callOptions); + } + + /** + */ + public io.grpc.reflection.testing.Reply method(io.grpc.reflection.testing.Request request) { + return blockingUnaryCall( + getChannel(), METHOD_METHOD, getCallOptions(), request); + } + } + + /** + */ + public static final class ReflectableServiceFutureStub extends io.grpc.stub.AbstractStub { + private ReflectableServiceFutureStub(io.grpc.Channel channel) { + super(channel); + } + + private ReflectableServiceFutureStub(io.grpc.Channel channel, + io.grpc.CallOptions callOptions) { + super(channel, callOptions); + } + + @java.lang.Override + protected ReflectableServiceFutureStub build(io.grpc.Channel channel, + io.grpc.CallOptions callOptions) { + return new ReflectableServiceFutureStub(channel, callOptions); + } + + /** + */ + public com.google.common.util.concurrent.ListenableFuture method( + io.grpc.reflection.testing.Request request) { + return futureUnaryCall( + getChannel().newCall(METHOD_METHOD, getCallOptions()), request); + } + } + + private static final int METHODID_METHOD = 0; + + private static class MethodHandlers implements + io.grpc.stub.ServerCalls.UnaryMethod, + io.grpc.stub.ServerCalls.ServerStreamingMethod, + io.grpc.stub.ServerCalls.ClientStreamingMethod, + io.grpc.stub.ServerCalls.BidiStreamingMethod { + private final ReflectableServiceImplBase serviceImpl; + private final int methodId; + + public MethodHandlers(ReflectableServiceImplBase serviceImpl, int methodId) { + this.serviceImpl = serviceImpl; + this.methodId = methodId; + } + + @java.lang.Override + @java.lang.SuppressWarnings("unchecked") + public void invoke(Req request, io.grpc.stub.StreamObserver responseObserver) { + switch (methodId) { + case METHODID_METHOD: + serviceImpl.method((io.grpc.reflection.testing.Request) request, + (io.grpc.stub.StreamObserver) responseObserver); + break; + default: + throw new AssertionError(); + } + } + + @java.lang.Override + @java.lang.SuppressWarnings("unchecked") + public io.grpc.stub.StreamObserver invoke( + io.grpc.stub.StreamObserver responseObserver) { + switch (methodId) { + default: + throw new AssertionError(); + } + } + } + + public static final class ReflectableServiceDescriptorWrapper implements io.grpc.protobuf.reflection.ProtoFileDescriptorWrapper { + @java.lang.Override + public com.google.protobuf.Descriptors.FileDescriptor getFileDescriptor() { + return io.grpc.reflection.testing.ReflectionTestProto.getDescriptor(); + } + } + + private static io.grpc.ServiceDescriptor serviceDescriptor; + + public static synchronized io.grpc.ServiceDescriptor getServiceDescriptor() { + if (serviceDescriptor == null) { + serviceDescriptor = new io.grpc.ServiceDescriptor(SERVICE_NAME, + new ReflectableServiceDescriptorWrapper(), + METHOD_METHOD); + } + + return serviceDescriptor; + } +} diff --git a/protobuf/src/main/java/io/grpc/protobuf/reflection/ProtoFileDescriptorWrapper.java b/protobuf/src/main/java/io/grpc/protobuf/reflection/ProtoFileDescriptorWrapper.java new file mode 100644 index 0000000000..0b129b4b07 --- /dev/null +++ b/protobuf/src/main/java/io/grpc/protobuf/reflection/ProtoFileDescriptorWrapper.java @@ -0,0 +1,42 @@ +/* + * Copyright 2016, Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package io.grpc.protobuf.reflection; + +import com.google.protobuf.Descriptors.FileDescriptor; + +/** + * The generated code implements this interface to provide access to the underlying proto + * file descriptor. + */ +public interface ProtoFileDescriptorWrapper { + FileDescriptor getFileDescriptor(); +} diff --git a/services/src/generated/main/grpc/io/grpc/health/v1/HealthGrpc.java b/services/src/generated/main/grpc/io/grpc/health/v1/HealthGrpc.java index 34785c0f74..56b0796e3e 100644 --- a/services/src/generated/main/grpc/io/grpc/health/v1/HealthGrpc.java +++ b/services/src/generated/main/grpc/io/grpc/health/v1/HealthGrpc.java @@ -203,11 +203,19 @@ public class HealthGrpc { } } + public static final class HealthDescriptorWrapper implements io.grpc.protobuf.reflection.ProtoFileDescriptorWrapper { + @java.lang.Override + public com.google.protobuf.Descriptors.FileDescriptor getFileDescriptor() { + return io.grpc.health.v1.HealthProto.getDescriptor(); + } + } + private static io.grpc.ServiceDescriptor serviceDescriptor; public static synchronized io.grpc.ServiceDescriptor getServiceDescriptor() { if (serviceDescriptor == null) { serviceDescriptor = new io.grpc.ServiceDescriptor(SERVICE_NAME, + new HealthDescriptorWrapper(), METHOD_CHECK); }