Add Abstract{ServiceName} class in compiled service class

This commit is contained in:
Lukasz Strzalkowski 2016-04-06 02:07:22 +02:00 committed by Eric Anderson
parent 385d61ac4e
commit f8b71e72b3
13 changed files with 148 additions and 0 deletions

View File

@ -157,6 +157,12 @@ public class BenchmarkServiceGrpc {
}
}
public static abstract class AbstractBenchmarkService implements BenchmarkService, io.grpc.stub.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;

View File

@ -213,6 +213,12 @@ public class WorkerServiceGrpc {
}
}
public static abstract class AbstractWorkerService implements WorkerService, io.grpc.stub.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;

View File

@ -642,6 +642,27 @@ static void PrintBindServiceMethod(const ServiceDescriptor* service,
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,
@ -704,6 +725,7 @@ static void PrintService(const ServiceDescriptor* service,
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();
@ -754,6 +776,7 @@ void GenerateService(const ServiceDescriptor* service,
vars["MethodType"] = "io.grpc.MethodDescriptor.MethodType";
vars["ServerMethodDefinition"] =
"io.grpc.ServerMethodDefinition";
vars["BindableService"] = "io.grpc.stub.BindableService";
vars["ServerServiceDefinition"] =
"io.grpc.ServerServiceDefinition";
vars["AbstractStub"] = "io.grpc.stub.AbstractStub";

View File

@ -224,6 +224,12 @@ public class TestServiceGrpc {
}
}
public static abstract class AbstractTestService implements TestService, io.grpc.stub.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;

View File

@ -224,6 +224,12 @@ public class TestServiceGrpc {
}
}
public static abstract class AbstractTestService implements TestService, io.grpc.stub.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;

View File

@ -302,6 +302,12 @@ public class TestServiceGrpc {
}
}
public static abstract class AbstractTestService implements TestService, io.grpc.stub.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;

View File

@ -138,6 +138,12 @@ public class GreeterGrpc {
}
}
public static abstract class AbstractGreeter implements Greeter, io.grpc.stub.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

View File

@ -205,6 +205,12 @@ public class RouteGuideGrpc {
}
}
public static abstract class AbstractRouteGuide implements RouteGuide, io.grpc.stub.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;

View File

@ -120,6 +120,12 @@ public class LoadBalancerGrpc {
}
}
public static abstract class AbstractLoadBalancer implements LoadBalancer, io.grpc.stub.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

View File

@ -175,6 +175,12 @@ public class ReconnectServiceGrpc {
}
}
public static abstract class AbstractReconnectService implements ReconnectService, io.grpc.stub.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;

View File

@ -261,6 +261,12 @@ public class TestServiceGrpc {
}
}
public static abstract class AbstractTestService implements TestService, io.grpc.stub.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;

View File

@ -138,6 +138,12 @@ public class UnimplementedServiceGrpc {
}
}
public static abstract class AbstractUnimplementedService implements UnimplementedService, io.grpc.stub.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

View File

@ -0,0 +1,59 @@
/*
* 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.stub;
import io.grpc.ExperimentalApi;
import io.grpc.ServerServiceDefinition;
/**
* Provides a way to bind instance of service implementation to server.
*
* <p>Enables dynamic creation of {@link ServerServiceDefinition} when exact type of service class
* is unknown.
*
* <pre><code>Class<? extends BindableService> service = ...;
* ServerBuilder.forPort(...).addService(service.newInstance().bindService());
* </code></pre></p>
*
* <p>It is used by service's abstract class generated by compiler (eg.:
* RouteGuideGrpc.AbstractRouteGuide for RouteGuide service). Service implementation classes which
* want to be "dynamically" bind should inherit from this base class.</p>
*/
@ExperimentalApi
public interface BindableService {
/**
* Creates {@link ServerServiceDefinition} object for current instance of service implementation.
*
* @return ServerServiceDefinition object.
*/
ServerServiceDefinition bindService();
}