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
This commit is contained in:
Eric Gribkoff 2016-10-27 14:34:55 -07:00
parent 9eb8f15110
commit aff1cac7da
14 changed files with 633 additions and 12 deletions

View File

@ -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);
}

View File

@ -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,

View File

@ -884,21 +884,63 @@ static void PrintMethodHandlerClass(const ServiceDescriptor* service,
static void PrintGetServiceDescriptorMethod(const ServiceDescriptor* service,
map<string, string>* 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";

View File

@ -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,

View File

@ -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<MethodDescriptor<?, ?>> 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<MethodDescriptor<?, ?>>(methods));
}
public ServiceDescriptor(String name, Object attachedObject, MethodDescriptor<?, ?>... methods) {
this(name, methods);
this.attachedObject = attachedObject;
}
public ServiceDescriptor(String name, Object attachedObject,
Collection<MethodDescriptor<?, ?>> 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<MethodDescriptor<?, ?>> 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;
}
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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,

View File

@ -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);
}

View File

@ -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<io.grpc.reflection.v1alpha.ServerReflectionRequest,
io.grpc.reflection.v1alpha.ServerReflectionResponse> 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 {
/**
* <pre>
* The reflection service is structured as a bidirectional stream, ensuring
* all related requests go to a single server.
* </pre>
*/
public io.grpc.stub.StreamObserver<io.grpc.reflection.v1alpha.ServerReflectionRequest> serverReflectionInfo(
io.grpc.stub.StreamObserver<io.grpc.reflection.v1alpha.ServerReflectionResponse> 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<ServerReflectionStub> {
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);
}
/**
* <pre>
* The reflection service is structured as a bidirectional stream, ensuring
* all related requests go to a single server.
* </pre>
*/
public io.grpc.stub.StreamObserver<io.grpc.reflection.v1alpha.ServerReflectionRequest> serverReflectionInfo(
io.grpc.stub.StreamObserver<io.grpc.reflection.v1alpha.ServerReflectionResponse> responseObserver) {
return asyncBidiStreamingCall(
getChannel().newCall(METHOD_SERVER_REFLECTION_INFO, getCallOptions()), responseObserver);
}
}
/**
*/
public static final class ServerReflectionBlockingStub extends io.grpc.stub.AbstractStub<ServerReflectionBlockingStub> {
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<ServerReflectionFutureStub> {
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<Req, Resp> implements
io.grpc.stub.ServerCalls.UnaryMethod<Req, Resp>,
io.grpc.stub.ServerCalls.ServerStreamingMethod<Req, Resp>,
io.grpc.stub.ServerCalls.ClientStreamingMethod<Req, Resp>,
io.grpc.stub.ServerCalls.BidiStreamingMethod<Req, Resp> {
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<Resp> responseObserver) {
switch (methodId) {
default:
throw new AssertionError();
}
}
@java.lang.Override
@java.lang.SuppressWarnings("unchecked")
public io.grpc.stub.StreamObserver<Req> invoke(
io.grpc.stub.StreamObserver<Resp> responseObserver) {
switch (methodId) {
case METHODID_SERVER_REFLECTION_INFO:
return (io.grpc.stub.StreamObserver<Req>) serviceImpl.serverReflectionInfo(
(io.grpc.stub.StreamObserver<io.grpc.reflection.v1alpha.ServerReflectionResponse>) 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;
}
}

View File

@ -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<io.grpc.reflection.testing.Request,
io.grpc.reflection.testing.Reply> 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<io.grpc.reflection.testing.Reply> 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<ReflectableServiceStub> {
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<io.grpc.reflection.testing.Reply> responseObserver) {
asyncUnaryCall(
getChannel().newCall(METHOD_METHOD, getCallOptions()), request, responseObserver);
}
}
/**
*/
public static final class ReflectableServiceBlockingStub extends io.grpc.stub.AbstractStub<ReflectableServiceBlockingStub> {
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<ReflectableServiceFutureStub> {
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<io.grpc.reflection.testing.Reply> 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<Req, Resp> implements
io.grpc.stub.ServerCalls.UnaryMethod<Req, Resp>,
io.grpc.stub.ServerCalls.ServerStreamingMethod<Req, Resp>,
io.grpc.stub.ServerCalls.ClientStreamingMethod<Req, Resp>,
io.grpc.stub.ServerCalls.BidiStreamingMethod<Req, Resp> {
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<Resp> responseObserver) {
switch (methodId) {
case METHODID_METHOD:
serviceImpl.method((io.grpc.reflection.testing.Request) request,
(io.grpc.stub.StreamObserver<io.grpc.reflection.testing.Reply>) responseObserver);
break;
default:
throw new AssertionError();
}
}
@java.lang.Override
@java.lang.SuppressWarnings("unchecked")
public io.grpc.stub.StreamObserver<Req> invoke(
io.grpc.stub.StreamObserver<Resp> 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;
}
}

View File

@ -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();
}

View File

@ -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);
}