package io.grpc.examples; import static io.grpc.stub.Calls.createMethodDescriptor; import static io.grpc.stub.Calls.asyncUnaryCall; import static io.grpc.stub.Calls.asyncServerStreamingCall; import static io.grpc.stub.Calls.asyncClientStreamingCall; import static io.grpc.stub.Calls.duplexStreamingCall; import static io.grpc.stub.Calls.blockingUnaryCall; import static io.grpc.stub.Calls.blockingServerStreamingCall; import static io.grpc.stub.Calls.unaryFutureCall; import static io.grpc.stub.ServerCalls.createMethodDefinition; import static io.grpc.stub.ServerCalls.asyncUnaryRequestCall; import static io.grpc.stub.ServerCalls.asyncStreamingRequestCall; import java.io.IOException; public class GreeterGrpc { private static final io.grpc.stub.Method METHOD_SAY_HELLO = io.grpc.stub.Method.create( io.grpc.MethodType.UNARY, "SayHello", io.grpc.nano.NanoUtils.marshaller( new io.grpc.nano.Parser() { @Override public io.grpc.examples.Helloworld.HelloRequest parse(com.google.protobuf.nano.CodedInputByteBufferNano input) throws IOException { return io.grpc.examples.Helloworld.HelloRequest.parseFrom(input); } }), io.grpc.nano.NanoUtils.marshaller( new io.grpc.nano.Parser() { @Override public io.grpc.examples.Helloworld.HelloReply parse(com.google.protobuf.nano.CodedInputByteBufferNano input) throws IOException { return io.grpc.examples.Helloworld.HelloReply.parseFrom(input); } })); public static GreeterStub newStub(io.grpc.Channel channel) { return new GreeterStub(channel, CONFIG); } public static GreeterBlockingStub newBlockingStub( io.grpc.Channel channel) { return new GreeterBlockingStub(channel, CONFIG); } public static GreeterFutureStub newFutureStub( io.grpc.Channel channel) { return new GreeterFutureStub(channel, CONFIG); } public static final GreeterServiceDescriptor CONFIG = new GreeterServiceDescriptor(); public static class GreeterServiceDescriptor extends io.grpc.stub.AbstractServiceDescriptor { public final io.grpc.MethodDescriptor sayHello; private GreeterServiceDescriptor() { sayHello = createMethodDescriptor( "helloworld.Greeter", METHOD_SAY_HELLO); } private GreeterServiceDescriptor( java.util.Map> methodMap) { sayHello = (io.grpc.MethodDescriptor) methodMap.get( CONFIG.sayHello.getName()); } @java.lang.Override protected GreeterServiceDescriptor build( java.util.Map> methodMap) { return new GreeterServiceDescriptor(methodMap); } @java.lang.Override public com.google.common.collect.ImmutableList> methods() { return com.google.common.collect.ImmutableList.>of( sayHello); } } public static interface Greeter { public void sayHello(io.grpc.examples.Helloworld.HelloRequest request, io.grpc.stub.StreamObserver responseObserver); } public static interface GreeterBlockingClient { public io.grpc.examples.Helloworld.HelloReply sayHello(io.grpc.examples.Helloworld.HelloRequest request); } public static interface GreeterFutureClient { public com.google.common.util.concurrent.ListenableFuture sayHello( io.grpc.examples.Helloworld.HelloRequest request); } public static class GreeterStub extends io.grpc.stub.AbstractStub implements Greeter { private GreeterStub(io.grpc.Channel channel, GreeterServiceDescriptor config) { super(channel, config); } @java.lang.Override protected GreeterStub build(io.grpc.Channel channel, GreeterServiceDescriptor config) { return new GreeterStub(channel, config); } @java.lang.Override public void sayHello(io.grpc.examples.Helloworld.HelloRequest request, io.grpc.stub.StreamObserver responseObserver) { asyncUnaryCall( channel.newCall(config.sayHello), request, responseObserver); } } public static class GreeterBlockingStub extends io.grpc.stub.AbstractStub implements GreeterBlockingClient { private GreeterBlockingStub(io.grpc.Channel channel, GreeterServiceDescriptor config) { super(channel, config); } @java.lang.Override protected GreeterBlockingStub build(io.grpc.Channel channel, GreeterServiceDescriptor config) { return new GreeterBlockingStub(channel, config); } @java.lang.Override public io.grpc.examples.Helloworld.HelloReply sayHello(io.grpc.examples.Helloworld.HelloRequest request) { return blockingUnaryCall( channel.newCall(config.sayHello), request); } } public static class GreeterFutureStub extends io.grpc.stub.AbstractStub implements GreeterFutureClient { private GreeterFutureStub(io.grpc.Channel channel, GreeterServiceDescriptor config) { super(channel, config); } @java.lang.Override protected GreeterFutureStub build(io.grpc.Channel channel, GreeterServiceDescriptor config) { return new GreeterFutureStub(channel, config); } @java.lang.Override public com.google.common.util.concurrent.ListenableFuture sayHello( io.grpc.examples.Helloworld.HelloRequest request) { return unaryFutureCall( channel.newCall(config.sayHello), request); } } public static io.grpc.ServerServiceDefinition bindService( final Greeter serviceImpl) { return io.grpc.ServerServiceDefinition.builder("helloworld.Greeter") .addMethod(createMethodDefinition( METHOD_SAY_HELLO, asyncUnaryRequestCall( new io.grpc.stub.ServerCalls.UnaryRequestMethod< io.grpc.examples.Helloworld.HelloRequest, io.grpc.examples.Helloworld.HelloReply>() { @java.lang.Override public void invoke( io.grpc.examples.Helloworld.HelloRequest request, io.grpc.stub.StreamObserver responseObserver) { serviceImpl.sayHello(request, responseObserver); } }))).build(); } }