Commit ecb0d6b6 authored by Luca Arrotta's avatar Luca Arrotta

bidirectional stream example added

parent 864fdcff
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/Lab3-Examples.iml" filepath="$PROJECT_DIR$/.idea/Lab3-Examples.iml" />
</modules>
</component>
</project>
\ No newline at end of file
syntax = "proto3";
package com.example.grpc;
// Request payload
message ClientRequest {
string stringRequest = 1;
}
message ServerResponse {
string stringResponse = 1;
}
service BidirectionalService {
rpc bidirectional(stream ClientRequest) returns (stream ServerResponse);
}
...@@ -3,17 +3,8 @@ package com.example.grpc; ...@@ -3,17 +3,8 @@ package com.example.grpc;
// Request payload // Request payload
message HelloRequest { message HelloRequest {
// Each message attribute is strongly typed.
// You also must assign a "tag" number.
// Each tag number is unique within the message.
string name = 1; string name = 1;
// This defines a strongly typed list of String
repeated string hobbies = 2; repeated string hobbies = 2;
// There are many more basics types, like Enum, Map
// See https://developers.google.com/protocol-buffers/docs/proto3
// for more information.
} }
message HelloResponse { message HelloResponse {
......
package com.example.grpc;
import static io.grpc.MethodDescriptor.generateFullMethodName;
import static io.grpc.stub.ClientCalls.asyncBidiStreamingCall;
import static io.grpc.stub.ClientCalls.asyncClientStreamingCall;
import static io.grpc.stub.ClientCalls.asyncServerStreamingCall;
import static io.grpc.stub.ClientCalls.asyncUnaryCall;
import static io.grpc.stub.ClientCalls.blockingServerStreamingCall;
import static io.grpc.stub.ClientCalls.blockingUnaryCall;
import static io.grpc.stub.ClientCalls.futureUnaryCall;
import static io.grpc.stub.ServerCalls.asyncBidiStreamingCall;
import static io.grpc.stub.ServerCalls.asyncClientStreamingCall;
import static io.grpc.stub.ServerCalls.asyncServerStreamingCall;
import static io.grpc.stub.ServerCalls.asyncUnaryCall;
import static io.grpc.stub.ServerCalls.asyncUnimplementedStreamingCall;
import static io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall;
/**
*/
@javax.annotation.Generated(
value = "by gRPC proto compiler (version 1.25.0)",
comments = "Source: BidirectionalService.proto")
public final class BidirectionalServiceGrpc {
private BidirectionalServiceGrpc() {}
public static final String SERVICE_NAME = "com.example.grpc.BidirectionalService";
// Static method descriptors that strictly reflect the proto.
private static volatile io.grpc.MethodDescriptor<com.example.grpc.BidirectionalServiceOuterClass.ClientRequest,
com.example.grpc.BidirectionalServiceOuterClass.ServerResponse> getBidirectionalMethod;
@io.grpc.stub.annotations.RpcMethod(
fullMethodName = SERVICE_NAME + '/' + "bidirectional",
requestType = com.example.grpc.BidirectionalServiceOuterClass.ClientRequest.class,
responseType = com.example.grpc.BidirectionalServiceOuterClass.ServerResponse.class,
methodType = io.grpc.MethodDescriptor.MethodType.BIDI_STREAMING)
public static io.grpc.MethodDescriptor<com.example.grpc.BidirectionalServiceOuterClass.ClientRequest,
com.example.grpc.BidirectionalServiceOuterClass.ServerResponse> getBidirectionalMethod() {
io.grpc.MethodDescriptor<com.example.grpc.BidirectionalServiceOuterClass.ClientRequest, com.example.grpc.BidirectionalServiceOuterClass.ServerResponse> getBidirectionalMethod;
if ((getBidirectionalMethod = BidirectionalServiceGrpc.getBidirectionalMethod) == null) {
synchronized (BidirectionalServiceGrpc.class) {
if ((getBidirectionalMethod = BidirectionalServiceGrpc.getBidirectionalMethod) == null) {
BidirectionalServiceGrpc.getBidirectionalMethod = getBidirectionalMethod =
io.grpc.MethodDescriptor.<com.example.grpc.BidirectionalServiceOuterClass.ClientRequest, com.example.grpc.BidirectionalServiceOuterClass.ServerResponse>newBuilder()
.setType(io.grpc.MethodDescriptor.MethodType.BIDI_STREAMING)
.setFullMethodName(generateFullMethodName(SERVICE_NAME, "bidirectional"))
.setSampledToLocalTracing(true)
.setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller(
com.example.grpc.BidirectionalServiceOuterClass.ClientRequest.getDefaultInstance()))
.setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller(
com.example.grpc.BidirectionalServiceOuterClass.ServerResponse.getDefaultInstance()))
.setSchemaDescriptor(new BidirectionalServiceMethodDescriptorSupplier("bidirectional"))
.build();
}
}
}
return getBidirectionalMethod;
}
/**
* Creates a new async stub that supports all call types for the service
*/
public static BidirectionalServiceStub newStub(io.grpc.Channel channel) {
return new BidirectionalServiceStub(channel);
}
/**
* Creates a new blocking-style stub that supports unary and streaming output calls on the service
*/
public static BidirectionalServiceBlockingStub newBlockingStub(
io.grpc.Channel channel) {
return new BidirectionalServiceBlockingStub(channel);
}
/**
* Creates a new ListenableFuture-style stub that supports unary calls on the service
*/
public static BidirectionalServiceFutureStub newFutureStub(
io.grpc.Channel channel) {
return new BidirectionalServiceFutureStub(channel);
}
/**
*/
public static abstract class BidirectionalServiceImplBase implements io.grpc.BindableService {
/**
*/
public io.grpc.stub.StreamObserver<com.example.grpc.BidirectionalServiceOuterClass.ClientRequest> bidirectional(
io.grpc.stub.StreamObserver<com.example.grpc.BidirectionalServiceOuterClass.ServerResponse> responseObserver) {
return asyncUnimplementedStreamingCall(getBidirectionalMethod(), responseObserver);
}
@java.lang.Override public final io.grpc.ServerServiceDefinition bindService() {
return io.grpc.ServerServiceDefinition.builder(getServiceDescriptor())
.addMethod(
getBidirectionalMethod(),
asyncBidiStreamingCall(
new MethodHandlers<
com.example.grpc.BidirectionalServiceOuterClass.ClientRequest,
com.example.grpc.BidirectionalServiceOuterClass.ServerResponse>(
this, METHODID_BIDIRECTIONAL)))
.build();
}
}
/**
*/
public static final class BidirectionalServiceStub extends io.grpc.stub.AbstractStub<BidirectionalServiceStub> {
private BidirectionalServiceStub(io.grpc.Channel channel) {
super(channel);
}
private BidirectionalServiceStub(io.grpc.Channel channel,
io.grpc.CallOptions callOptions) {
super(channel, callOptions);
}
@java.lang.Override
protected BidirectionalServiceStub build(io.grpc.Channel channel,
io.grpc.CallOptions callOptions) {
return new BidirectionalServiceStub(channel, callOptions);
}
/**
*/
public io.grpc.stub.StreamObserver<com.example.grpc.BidirectionalServiceOuterClass.ClientRequest> bidirectional(
io.grpc.stub.StreamObserver<com.example.grpc.BidirectionalServiceOuterClass.ServerResponse> responseObserver) {
return asyncBidiStreamingCall(
getChannel().newCall(getBidirectionalMethod(), getCallOptions()), responseObserver);
}
}
/**
*/
public static final class BidirectionalServiceBlockingStub extends io.grpc.stub.AbstractStub<BidirectionalServiceBlockingStub> {
private BidirectionalServiceBlockingStub(io.grpc.Channel channel) {
super(channel);
}
private BidirectionalServiceBlockingStub(io.grpc.Channel channel,
io.grpc.CallOptions callOptions) {
super(channel, callOptions);
}
@java.lang.Override
protected BidirectionalServiceBlockingStub build(io.grpc.Channel channel,
io.grpc.CallOptions callOptions) {
return new BidirectionalServiceBlockingStub(channel, callOptions);
}
}
/**
*/
public static final class BidirectionalServiceFutureStub extends io.grpc.stub.AbstractStub<BidirectionalServiceFutureStub> {
private BidirectionalServiceFutureStub(io.grpc.Channel channel) {
super(channel);
}
private BidirectionalServiceFutureStub(io.grpc.Channel channel,
io.grpc.CallOptions callOptions) {
super(channel, callOptions);
}
@java.lang.Override
protected BidirectionalServiceFutureStub build(io.grpc.Channel channel,
io.grpc.CallOptions callOptions) {
return new BidirectionalServiceFutureStub(channel, callOptions);
}
}
private static final int METHODID_BIDIRECTIONAL = 0;
private static final 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 BidirectionalServiceImplBase serviceImpl;
private final int methodId;
MethodHandlers(BidirectionalServiceImplBase 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_BIDIRECTIONAL:
return (io.grpc.stub.StreamObserver<Req>) serviceImpl.bidirectional(
(io.grpc.stub.StreamObserver<com.example.grpc.BidirectionalServiceOuterClass.ServerResponse>) responseObserver);
default:
throw new AssertionError();
}
}
}
private static abstract class BidirectionalServiceBaseDescriptorSupplier
implements io.grpc.protobuf.ProtoFileDescriptorSupplier, io.grpc.protobuf.ProtoServiceDescriptorSupplier {
BidirectionalServiceBaseDescriptorSupplier() {}
@java.lang.Override
public com.google.protobuf.Descriptors.FileDescriptor getFileDescriptor() {
return com.example.grpc.BidirectionalServiceOuterClass.getDescriptor();
}
@java.lang.Override
public com.google.protobuf.Descriptors.ServiceDescriptor getServiceDescriptor() {
return getFileDescriptor().findServiceByName("BidirectionalService");
}
}
private static final class BidirectionalServiceFileDescriptorSupplier
extends BidirectionalServiceBaseDescriptorSupplier {
BidirectionalServiceFileDescriptorSupplier() {}
}
private static final class BidirectionalServiceMethodDescriptorSupplier
extends BidirectionalServiceBaseDescriptorSupplier
implements io.grpc.protobuf.ProtoMethodDescriptorSupplier {
private final String methodName;
BidirectionalServiceMethodDescriptorSupplier(String methodName) {
this.methodName = methodName;
}
@java.lang.Override
public com.google.protobuf.Descriptors.MethodDescriptor getMethodDescriptor() {
return getServiceDescriptor().findMethodByName(methodName);
}
}
private static volatile io.grpc.ServiceDescriptor serviceDescriptor;
public static io.grpc.ServiceDescriptor getServiceDescriptor() {
io.grpc.ServiceDescriptor result = serviceDescriptor;
if (result == null) {
synchronized (BidirectionalServiceGrpc.class) {
result = serviceDescriptor;
if (result == null) {
serviceDescriptor = result = io.grpc.ServiceDescriptor.newBuilder(SERVICE_NAME)
.setSchemaDescriptor(new BidirectionalServiceFileDescriptorSupplier())
.addMethod(getBidirectionalMethod())
.build();
}
}
}
return result;
}
}
// Generated by the protocol buffer compiler. DO NOT EDIT!
// source: BidirectionalService.proto
package com.example.grpc;
public final class BidirectionalServiceOuterClass {
private BidirectionalServiceOuterClass() {}
public static void registerAllExtensions(
com.google.protobuf.ExtensionRegistryLite registry) {
}
public static void registerAllExtensions(
com.google.protobuf.ExtensionRegistry registry) {
registerAllExtensions(
(com.google.protobuf.ExtensionRegistryLite) registry);
}
public interface ClientRequestOrBuilder extends
// @@protoc_insertion_point(interface_extends:com.example.grpc.ClientRequest)
com.google.protobuf.MessageOrBuilder {
/**
* <code>string stringRequest = 1;</code>
* @return The stringRequest.
*/
java.lang.String getStringRequest();
/**
* <code>string stringRequest = 1;</code>
* @return The bytes for stringRequest.
*/
com.google.protobuf.ByteString
getStringRequestBytes();
}
/**
* Protobuf type {@code com.example.grpc.ClientRequest}
*/
public static final class ClientRequest extends
com.google.protobuf.GeneratedMessageV3 implements
// @@protoc_insertion_point(message_implements:com.example.grpc.ClientRequest)
ClientRequestOrBuilder {
private static final long serialVersionUID = 0L;
// Use ClientRequest.newBuilder() to construct.
private ClientRequest(com.google.protobuf.GeneratedMessageV3.Builder<?> builder) {
super(builder);
}
private ClientRequest() {
stringRequest_ = "";
}
@java.lang.Override
@SuppressWarnings({"unused"})
protected java.lang.Object newInstance(
UnusedPrivateParameter unused) {
return new ClientRequest();
}
@java.lang.Override
public final com.google.protobuf.UnknownFieldSet
getUnknownFields() {
return this.unknownFields;
}
private ClientRequest(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
this();
if (extensionRegistry == null) {
throw new java.lang.NullPointerException();
}
com.google.protobuf.UnknownFieldSet.Builder unknownFields =
com.google.protobuf.UnknownFieldSet.newBuilder();
try {
boolean done = false;
while (!done) {
int tag = input.readTag();
switch (tag) {
case 0:
done = true;
break;
case 10: {
java.lang.String s = input.readStringRequireUtf8();
stringRequest_ = s;
break;
}
default: {
if (!parseUnknownField(
input, unknownFields, extensionRegistry, tag)) {
done = true;
}
break;
}
}
}
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
throw e.setUnfinishedMessage(this);
} catch (java.io.IOException e) {
throw new com.google.protobuf.InvalidProtocolBufferException(
e).setUnfinishedMessage(this);
} finally {
this.unknownFields = unknownFields.build();
makeExtensionsImmutable();
}
}
public static final com.google.protobuf.Descriptors.Descriptor
getDescriptor() {
return com.example.grpc.BidirectionalServiceOuterClass.internal_static_com_example_grpc_ClientRequest_descriptor;
}
@java.lang.Override
protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internalGetFieldAccessorTable() {
return com.example.grpc.BidirectionalServiceOuterClass.internal_static_com_example_grpc_ClientRequest_fieldAccessorTable
.ensureFieldAccessorsInitialized(
com.example.grpc.BidirectionalServiceOuterClass.ClientRequest.class, com.example.grpc.BidirectionalServiceOuterClass.ClientRequest.Builder.class);
}
public static final int STRINGREQUEST_FIELD_NUMBER = 1;
private volatile java.lang.Object stringRequest_;
/**
* <code>string stringRequest = 1;</code>
* @return The stringRequest.
*/
public java.lang.String getStringRequest() {
java.lang.Object ref = stringRequest_;
if (ref instanceof java.lang.String) {
return (java.lang.String) ref;
} else {
com.google.protobuf.ByteString bs =
(com.google.protobuf.ByteString) ref;
java.lang.String s = bs.toStringUtf8();
stringRequest_ = s;
return s;
}
}
/**
* <code>string stringRequest = 1;</code>
* @return The bytes for stringRequest.
*/
public com.google.protobuf.ByteString
getStringRequestBytes() {
java.lang.Object ref = stringRequest_;
if (ref instanceof java.lang.String) {
com.google.protobuf.ByteString b =
com.google.protobuf.ByteString.copyFromUtf8(
(java.lang.String) ref);
stringRequest_ = b;
return b;
} else {
return (com.google.protobuf.ByteString) ref;
}
}
private byte memoizedIsInitialized = -1;
@java.lang.Override
public final boolean isInitialized() {
byte isInitialized = memoizedIsInitialized;
if (isInitialized == 1) return true;
if (isInitialized == 0) return false;
memoizedIsInitialized = 1;
return true;
}
@java.lang.Override
public void writeTo(com.google.protobuf.CodedOutputStream output)
throws java.io.IOException {
if (!getStringRequestBytes().isEmpty()) {
com.google.protobuf.GeneratedMessageV3.writeString(output, 1, stringRequest_);
}
unknownFields.writeTo(output);
}
@java.lang.Override
public int getSerializedSize() {
int size = memoizedSize;
if (size != -1) return size;
size = 0;
if (!getStringRequestBytes().isEmpty()) {
size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, stringRequest_);
}
size += unknownFields.getSerializedSize();
memoizedSize = size;
return size;
}
@java.lang.Override
public boolean equals(final java.lang.Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof com.example.grpc.BidirectionalServiceOuterClass.ClientRequest)) {
return super.equals(obj);
}
com.example.grpc.BidirectionalServiceOuterClass.ClientRequest other = (com.example.grpc.BidirectionalServiceOuterClass.ClientRequest) obj;
if (!getStringRequest()
.equals(other.getStringRequest())) return false;
if (!unknownFields.equals(other.unknownFields)) return false;
return true;
}
@java.lang.Override
public int hashCode() {
if (memoizedHashCode != 0) {
return memoizedHashCode;
}
int hash = 41;
hash = (19 * hash) + getDescriptor().hashCode();
hash = (37 * hash) + STRINGREQUEST_FIELD_NUMBER;
hash = (53 * hash) + getStringRequest().hashCode();
hash = (29 * hash) + unknownFields.hashCode();
memoizedHashCode = hash;
return hash;
}
public static com.example.grpc.BidirectionalServiceOuterClass.ClientRequest parseFrom(
java.nio.ByteBuffer data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static com.example.grpc.BidirectionalServiceOuterClass.ClientRequest parseFrom(
java.nio.ByteBuffer data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static com.example.grpc.BidirectionalServiceOuterClass.ClientRequest parseFrom(
com.google.protobuf.ByteString data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static com.example.grpc.BidirectionalServiceOuterClass.ClientRequest parseFrom(
com.google.protobuf.ByteString data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static com.example.grpc.BidirectionalServiceOuterClass.ClientRequest parseFrom(byte[] data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static com.example.grpc.BidirectionalServiceOuterClass.ClientRequest parseFrom(
byte[] data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static com.example.grpc.BidirectionalServiceOuterClass.ClientRequest parseFrom(java.io.InputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input);
}
public static com.example.grpc.BidirectionalServiceOuterClass.ClientRequest parseFrom(
java.io.InputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input, extensionRegistry);
}
public static com.example.grpc.BidirectionalServiceOuterClass.ClientRequest parseDelimitedFrom(java.io.InputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseDelimitedWithIOException(PARSER, input);
}
public static com.example.grpc.BidirectionalServiceOuterClass.ClientRequest parseDelimitedFrom(
java.io.InputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseDelimitedWithIOException(PARSER, input, extensionRegistry);
}
public static com.example.grpc.BidirectionalServiceOuterClass.ClientRequest parseFrom(
com.google.protobuf.CodedInputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input);
}
public static com.example.grpc.BidirectionalServiceOuterClass.ClientRequest parseFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input, extensionRegistry);
}
@java.lang.Override
public Builder newBuilderForType() { return newBuilder(); }
public static Builder newBuilder() {
return DEFAULT_INSTANCE.toBuilder();
}
public static Builder newBuilder(com.example.grpc.BidirectionalServiceOuterClass.ClientRequest prototype) {
return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype);
}
@java.lang.Override
public Builder toBuilder() {
return this == DEFAULT_INSTANCE
? new Builder() : new Builder().mergeFrom(this);
}
@java.lang.Override
protected Builder newBuilderForType(
com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
Builder builder = new Builder(parent);
return builder;
}
/**
* Protobuf type {@code com.example.grpc.ClientRequest}
*/
public static final class Builder extends
com.google.protobuf.GeneratedMessageV3.Builder<Builder> implements
// @@protoc_insertion_point(builder_implements:com.example.grpc.ClientRequest)
com.example.grpc.BidirectionalServiceOuterClass.ClientRequestOrBuilder {
public static final com.google.protobuf.Descriptors.Descriptor
getDescriptor() {
return com.example.grpc.BidirectionalServiceOuterClass.internal_static_com_example_grpc_ClientRequest_descriptor;
}
@java.lang.Override
protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internalGetFieldAccessorTable() {
return com.example.grpc.BidirectionalServiceOuterClass.internal_static_com_example_grpc_ClientRequest_fieldAccessorTable
.ensureFieldAccessorsInitialized(
com.example.grpc.BidirectionalServiceOuterClass.ClientRequest.class, com.example.grpc.BidirectionalServiceOuterClass.ClientRequest.Builder.class);
}
// Construct using com.example.grpc.BidirectionalServiceOuterClass.ClientRequest.newBuilder()
private Builder() {
maybeForceBuilderInitialization();
}
private Builder(
com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
super(parent);
maybeForceBuilderInitialization();
}
private void maybeForceBuilderInitialization() {
if (com.google.protobuf.GeneratedMessageV3
.alwaysUseFieldBuilders) {
}
}
@java.lang.Override
public Builder clear() {
super.clear();
stringRequest_ = "";
return this;
}
@java.lang.Override
public com.google.protobuf.Descriptors.Descriptor
getDescriptorForType() {
return com.example.grpc.BidirectionalServiceOuterClass.internal_static_com_example_grpc_ClientRequest_descriptor;
}
@java.lang.Override
public com.example.grpc.BidirectionalServiceOuterClass.ClientRequest getDefaultInstanceForType() {
return com.example.grpc.BidirectionalServiceOuterClass.ClientRequest.getDefaultInstance();
}
@java.lang.Override
public com.example.grpc.BidirectionalServiceOuterClass.ClientRequest build() {
com.example.grpc.BidirectionalServiceOuterClass.ClientRequest result = buildPartial();
if (!result.isInitialized()) {
throw newUninitializedMessageException(result);
}
return result;
}
@java.lang.Override
public com.example.grpc.BidirectionalServiceOuterClass.ClientRequest buildPartial() {
com.example.grpc.BidirectionalServiceOuterClass.ClientRequest result = new com.example.grpc.BidirectionalServiceOuterClass.ClientRequest(this);
result.stringRequest_ = stringRequest_;
onBuilt();
return result;
}
@java.lang.Override
public Builder clone() {
return super.clone();
}
@java.lang.Override
public Builder setField(
com.google.protobuf.Descriptors.FieldDescriptor field,
java.lang.Object value) {
return super.setField(field, value);
}
@java.lang.Override
public Builder clearField(
com.google.protobuf.Descriptors.FieldDescriptor field) {
return super.clearField(field);
}
@java.lang.Override
public Builder clearOneof(
com.google.protobuf.Descriptors.OneofDescriptor oneof) {
return super.clearOneof(oneof);
}
@java.lang.Override
public Builder setRepeatedField(
com.google.protobuf.Descriptors.FieldDescriptor field,
int index, java.lang.Object value) {
return super.setRepeatedField(field, index, value);
}
@java.lang.Override
public Builder addRepeatedField(
com.google.protobuf.Descriptors.FieldDescriptor field,
java.lang.Object value) {
return super.addRepeatedField(field, value);
}
@java.lang.Override
public Builder mergeFrom(com.google.protobuf.Message other) {
if (other instanceof com.example.grpc.BidirectionalServiceOuterClass.ClientRequest) {
return mergeFrom((com.example.grpc.BidirectionalServiceOuterClass.ClientRequest)other);
} else {
super.mergeFrom(other);
return this;
}
}
public Builder mergeFrom(com.example.grpc.BidirectionalServiceOuterClass.ClientRequest other) {
if (other == com.example.grpc.BidirectionalServiceOuterClass.ClientRequest.getDefaultInstance()) return this;
if (!other.getStringRequest().isEmpty()) {
stringRequest_ = other.stringRequest_;
onChanged();
}
this.mergeUnknownFields(other.unknownFields);
onChanged();
return this;
}
@java.lang.Override
public final boolean isInitialized() {
return true;
}
@java.lang.Override
public Builder mergeFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
com.example.grpc.BidirectionalServiceOuterClass.ClientRequest parsedMessage = null;
try {
parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
parsedMessage = (com.example.grpc.BidirectionalServiceOuterClass.ClientRequest) e.getUnfinishedMessage();
throw e.unwrapIOException();
} finally {
if (parsedMessage != null) {
mergeFrom(parsedMessage);
}
}
return this;
}
private java.lang.Object stringRequest_ = "";
/**
* <code>string stringRequest = 1;</code>
* @return The stringRequest.
*/
public java.lang.String getStringRequest() {
java.lang.Object ref = stringRequest_;
if (!(ref instanceof java.lang.String)) {
com.google.protobuf.ByteString bs =
(com.google.protobuf.ByteString) ref;
java.lang.String s = bs.toStringUtf8();
stringRequest_ = s;
return s;
} else {
return (java.lang.String) ref;
}
}
/**
* <code>string stringRequest = 1;</code>
* @return The bytes for stringRequest.
*/
public com.google.protobuf.ByteString
getStringRequestBytes() {
java.lang.Object ref = stringRequest_;
if (ref instanceof String) {
com.google.protobuf.ByteString b =
com.google.protobuf.ByteString.copyFromUtf8(
(java.lang.String) ref);
stringRequest_ = b;
return b;
} else {
return (com.google.protobuf.ByteString) ref;
}
}
/**
* <code>string stringRequest = 1;</code>
* @param value The stringRequest to set.
* @return This builder for chaining.
*/
public Builder setStringRequest(
java.lang.String value) {
if (value == null) {
throw new NullPointerException();
}
stringRequest_ = value;
onChanged();
return this;
}
/**
* <code>string stringRequest = 1;</code>
* @return This builder for chaining.
*/
public Builder clearStringRequest() {
stringRequest_ = getDefaultInstance().getStringRequest();
onChanged();
return this;
}
/**
* <code>string stringRequest = 1;</code>
* @param value The bytes for stringRequest to set.
* @return This builder for chaining.
*/
public Builder setStringRequestBytes(
com.google.protobuf.ByteString value) {
if (value == null) {
throw new NullPointerException();
}
checkByteStringIsUtf8(value);
stringRequest_ = value;
onChanged();
return this;
}
@java.lang.Override
public final Builder setUnknownFields(
final com.google.protobuf.UnknownFieldSet unknownFields) {
return super.setUnknownFields(unknownFields);
}
@java.lang.Override
public final Builder mergeUnknownFields(
final com.google.protobuf.UnknownFieldSet unknownFields) {
return super.mergeUnknownFields(unknownFields);
}
// @@protoc_insertion_point(builder_scope:com.example.grpc.ClientRequest)
}
// @@protoc_insertion_point(class_scope:com.example.grpc.ClientRequest)
private static final com.example.grpc.BidirectionalServiceOuterClass.ClientRequest DEFAULT_INSTANCE;
static {
DEFAULT_INSTANCE = new com.example.grpc.BidirectionalServiceOuterClass.ClientRequest();
}
public static com.example.grpc.BidirectionalServiceOuterClass.ClientRequest getDefaultInstance() {
return DEFAULT_INSTANCE;
}
private static final com.google.protobuf.Parser<ClientRequest>
PARSER = new com.google.protobuf.AbstractParser<ClientRequest>() {
@java.lang.Override
public ClientRequest parsePartialFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return new ClientRequest(input, extensionRegistry);
}
};
public static com.google.protobuf.Parser<ClientRequest> parser() {
return PARSER;
}
@java.lang.Override
public com.google.protobuf.Parser<ClientRequest> getParserForType() {
return PARSER;
}
@java.lang.Override
public com.example.grpc.BidirectionalServiceOuterClass.ClientRequest getDefaultInstanceForType() {
return DEFAULT_INSTANCE;
}
}
public interface ServerResponseOrBuilder extends
// @@protoc_insertion_point(interface_extends:com.example.grpc.ServerResponse)
com.google.protobuf.MessageOrBuilder {
/**
* <code>string stringResponse = 1;</code>
* @return The stringResponse.
*/
java.lang.String getStringResponse();
/**
* <code>string stringResponse = 1;</code>
* @return The bytes for stringResponse.
*/
com.google.protobuf.ByteString
getStringResponseBytes();
}
/**
* Protobuf type {@code com.example.grpc.ServerResponse}
*/
public static final class ServerResponse extends
com.google.protobuf.GeneratedMessageV3 implements
// @@protoc_insertion_point(message_implements:com.example.grpc.ServerResponse)
ServerResponseOrBuilder {
private static final long serialVersionUID = 0L;
// Use ServerResponse.newBuilder() to construct.
private ServerResponse(com.google.protobuf.GeneratedMessageV3.Builder<?> builder) {
super(builder);
}
private ServerResponse() {
stringResponse_ = "";
}
@java.lang.Override
@SuppressWarnings({"unused"})
protected java.lang.Object newInstance(
UnusedPrivateParameter unused) {
return new ServerResponse();
}
@java.lang.Override
public final com.google.protobuf.UnknownFieldSet
getUnknownFields() {
return this.unknownFields;
}
private ServerResponse(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
this();
if (extensionRegistry == null) {
throw new java.lang.NullPointerException();
}
com.google.protobuf.UnknownFieldSet.Builder unknownFields =
com.google.protobuf.UnknownFieldSet.newBuilder();
try {
boolean done = false;
while (!done) {
int tag = input.readTag();
switch (tag) {
case 0:
done = true;
break;
case 10: {
java.lang.String s = input.readStringRequireUtf8();
stringResponse_ = s;
break;
}
default: {
if (!parseUnknownField(
input, unknownFields, extensionRegistry, tag)) {
done = true;
}
break;
}
}
}
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
throw e.setUnfinishedMessage(this);
} catch (java.io.IOException e) {
throw new com.google.protobuf.InvalidProtocolBufferException(
e).setUnfinishedMessage(this);
} finally {
this.unknownFields = unknownFields.build();
makeExtensionsImmutable();
}
}
public static final com.google.protobuf.Descriptors.Descriptor
getDescriptor() {
return com.example.grpc.BidirectionalServiceOuterClass.internal_static_com_example_grpc_ServerResponse_descriptor;
}
@java.lang.Override
protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internalGetFieldAccessorTable() {
return com.example.grpc.BidirectionalServiceOuterClass.internal_static_com_example_grpc_ServerResponse_fieldAccessorTable
.ensureFieldAccessorsInitialized(
com.example.grpc.BidirectionalServiceOuterClass.ServerResponse.class, com.example.grpc.BidirectionalServiceOuterClass.ServerResponse.Builder.class);
}
public static final int STRINGRESPONSE_FIELD_NUMBER = 1;
private volatile java.lang.Object stringResponse_;
/**
* <code>string stringResponse = 1;</code>
* @return The stringResponse.
*/
public java.lang.String getStringResponse() {
java.lang.Object ref = stringResponse_;
if (ref instanceof java.lang.String) {
return (java.lang.String) ref;
} else {
com.google.protobuf.ByteString bs =
(com.google.protobuf.ByteString) ref;
java.lang.String s = bs.toStringUtf8();
stringResponse_ = s;
return s;
}
}
/**
* <code>string stringResponse = 1;</code>
* @return The bytes for stringResponse.
*/
public com.google.protobuf.ByteString
getStringResponseBytes() {
java.lang.Object ref = stringResponse_;
if (ref instanceof java.lang.String) {
com.google.protobuf.ByteString b =
com.google.protobuf.ByteString.copyFromUtf8(
(java.lang.String) ref);
stringResponse_ = b;
return b;
} else {
return (com.google.protobuf.ByteString) ref;
}
}
private byte memoizedIsInitialized = -1;
@java.lang.Override
public final boolean isInitialized() {
byte isInitialized = memoizedIsInitialized;
if (isInitialized == 1) return true;
if (isInitialized == 0) return false;
memoizedIsInitialized = 1;
return true;
}
@java.lang.Override
public void writeTo(com.google.protobuf.CodedOutputStream output)
throws java.io.IOException {
if (!getStringResponseBytes().isEmpty()) {
com.google.protobuf.GeneratedMessageV3.writeString(output, 1, stringResponse_);
}
unknownFields.writeTo(output);
}
@java.lang.Override
public int getSerializedSize() {
int size = memoizedSize;
if (size != -1) return size;
size = 0;
if (!getStringResponseBytes().isEmpty()) {
size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, stringResponse_);
}
size += unknownFields.getSerializedSize();
memoizedSize = size;
return size;
}
@java.lang.Override
public boolean equals(final java.lang.Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof com.example.grpc.BidirectionalServiceOuterClass.ServerResponse)) {
return super.equals(obj);
}
com.example.grpc.BidirectionalServiceOuterClass.ServerResponse other = (com.example.grpc.BidirectionalServiceOuterClass.ServerResponse) obj;
if (!getStringResponse()
.equals(other.getStringResponse())) return false;
if (!unknownFields.equals(other.unknownFields)) return false;
return true;
}
@java.lang.Override
public int hashCode() {
if (memoizedHashCode != 0) {
return memoizedHashCode;
}
int hash = 41;
hash = (19 * hash) + getDescriptor().hashCode();
hash = (37 * hash) + STRINGRESPONSE_FIELD_NUMBER;
hash = (53 * hash) + getStringResponse().hashCode();
hash = (29 * hash) + unknownFields.hashCode();
memoizedHashCode = hash;
return hash;
}
public static com.example.grpc.BidirectionalServiceOuterClass.ServerResponse parseFrom(
java.nio.ByteBuffer data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static com.example.grpc.BidirectionalServiceOuterClass.ServerResponse parseFrom(
java.nio.ByteBuffer data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static com.example.grpc.BidirectionalServiceOuterClass.ServerResponse parseFrom(
com.google.protobuf.ByteString data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static com.example.grpc.BidirectionalServiceOuterClass.ServerResponse parseFrom(
com.google.protobuf.ByteString data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static com.example.grpc.BidirectionalServiceOuterClass.ServerResponse parseFrom(byte[] data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static com.example.grpc.BidirectionalServiceOuterClass.ServerResponse parseFrom(
byte[] data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static com.example.grpc.BidirectionalServiceOuterClass.ServerResponse parseFrom(java.io.InputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input);
}
public static com.example.grpc.BidirectionalServiceOuterClass.ServerResponse parseFrom(
java.io.InputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input, extensionRegistry);
}
public static com.example.grpc.BidirectionalServiceOuterClass.ServerResponse parseDelimitedFrom(java.io.InputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseDelimitedWithIOException(PARSER, input);
}
public static com.example.grpc.BidirectionalServiceOuterClass.ServerResponse parseDelimitedFrom(
java.io.InputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseDelimitedWithIOException(PARSER, input, extensionRegistry);
}
public static com.example.grpc.BidirectionalServiceOuterClass.ServerResponse parseFrom(
com.google.protobuf.CodedInputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input);
}
public static com.example.grpc.BidirectionalServiceOuterClass.ServerResponse parseFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input, extensionRegistry);
}
@java.lang.Override
public Builder newBuilderForType() { return newBuilder(); }
public static Builder newBuilder() {
return DEFAULT_INSTANCE.toBuilder();
}
public static Builder newBuilder(com.example.grpc.BidirectionalServiceOuterClass.ServerResponse prototype) {
return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype);
}
@java.lang.Override
public Builder toBuilder() {
return this == DEFAULT_INSTANCE
? new Builder() : new Builder().mergeFrom(this);
}
@java.lang.Override
protected Builder newBuilderForType(
com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
Builder builder = new Builder(parent);
return builder;
}
/**
* Protobuf type {@code com.example.grpc.ServerResponse}
*/
public static final class Builder extends
com.google.protobuf.GeneratedMessageV3.Builder<Builder> implements
// @@protoc_insertion_point(builder_implements:com.example.grpc.ServerResponse)
com.example.grpc.BidirectionalServiceOuterClass.ServerResponseOrBuilder {
public static final com.google.protobuf.Descriptors.Descriptor
getDescriptor() {
return com.example.grpc.BidirectionalServiceOuterClass.internal_static_com_example_grpc_ServerResponse_descriptor;
}
@java.lang.Override
protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internalGetFieldAccessorTable() {
return com.example.grpc.BidirectionalServiceOuterClass.internal_static_com_example_grpc_ServerResponse_fieldAccessorTable
.ensureFieldAccessorsInitialized(
com.example.grpc.BidirectionalServiceOuterClass.ServerResponse.class, com.example.grpc.BidirectionalServiceOuterClass.ServerResponse.Builder.class);
}
// Construct using com.example.grpc.BidirectionalServiceOuterClass.ServerResponse.newBuilder()
private Builder() {
maybeForceBuilderInitialization();
}
private Builder(
com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
super(parent);
maybeForceBuilderInitialization();
}
private void maybeForceBuilderInitialization() {
if (com.google.protobuf.GeneratedMessageV3
.alwaysUseFieldBuilders) {
}
}
@java.lang.Override
public Builder clear() {
super.clear();
stringResponse_ = "";
return this;
}
@java.lang.Override
public com.google.protobuf.Descriptors.Descriptor
getDescriptorForType() {
return com.example.grpc.BidirectionalServiceOuterClass.internal_static_com_example_grpc_ServerResponse_descriptor;
}
@java.lang.Override
public com.example.grpc.BidirectionalServiceOuterClass.ServerResponse getDefaultInstanceForType() {
return com.example.grpc.BidirectionalServiceOuterClass.ServerResponse.getDefaultInstance();
}
@java.lang.Override
public com.example.grpc.BidirectionalServiceOuterClass.ServerResponse build() {
com.example.grpc.BidirectionalServiceOuterClass.ServerResponse result = buildPartial();
if (!result.isInitialized()) {
throw newUninitializedMessageException(result);
}
return result;
}
@java.lang.Override
public com.example.grpc.BidirectionalServiceOuterClass.ServerResponse buildPartial() {
com.example.grpc.BidirectionalServiceOuterClass.ServerResponse result = new com.example.grpc.BidirectionalServiceOuterClass.ServerResponse(this);
result.stringResponse_ = stringResponse_;
onBuilt();
return result;
}
@java.lang.Override
public Builder clone() {
return super.clone();
}
@java.lang.Override
public Builder setField(
com.google.protobuf.Descriptors.FieldDescriptor field,
java.lang.Object value) {
return super.setField(field, value);
}
@java.lang.Override
public Builder clearField(
com.google.protobuf.Descriptors.FieldDescriptor field) {
return super.clearField(field);
}
@java.lang.Override
public Builder clearOneof(
com.google.protobuf.Descriptors.OneofDescriptor oneof) {
return super.clearOneof(oneof);
}
@java.lang.Override
public Builder setRepeatedField(
com.google.protobuf.Descriptors.FieldDescriptor field,
int index, java.lang.Object value) {
return super.setRepeatedField(field, index, value);
}
@java.lang.Override
public Builder addRepeatedField(
com.google.protobuf.Descriptors.FieldDescriptor field,
java.lang.Object value) {
return super.addRepeatedField(field, value);
}
@java.lang.Override
public Builder mergeFrom(com.google.protobuf.Message other) {
if (other instanceof com.example.grpc.BidirectionalServiceOuterClass.ServerResponse) {
return mergeFrom((com.example.grpc.BidirectionalServiceOuterClass.ServerResponse)other);
} else {
super.mergeFrom(other);
return this;
}
}
public Builder mergeFrom(com.example.grpc.BidirectionalServiceOuterClass.ServerResponse other) {
if (other == com.example.grpc.BidirectionalServiceOuterClass.ServerResponse.getDefaultInstance()) return this;
if (!other.getStringResponse().isEmpty()) {
stringResponse_ = other.stringResponse_;
onChanged();
}
this.mergeUnknownFields(other.unknownFields);
onChanged();
return this;
}
@java.lang.Override
public final boolean isInitialized() {
return true;
}
@java.lang.Override
public Builder mergeFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
com.example.grpc.BidirectionalServiceOuterClass.ServerResponse parsedMessage = null;
try {
parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
parsedMessage = (com.example.grpc.BidirectionalServiceOuterClass.ServerResponse) e.getUnfinishedMessage();
throw e.unwrapIOException();
} finally {
if (parsedMessage != null) {
mergeFrom(parsedMessage);
}
}
return this;
}
private java.lang.Object stringResponse_ = "";
/**
* <code>string stringResponse = 1;</code>
* @return The stringResponse.
*/
public java.lang.String getStringResponse() {
java.lang.Object ref = stringResponse_;
if (!(ref instanceof java.lang.String)) {
com.google.protobuf.ByteString bs =
(com.google.protobuf.ByteString) ref;
java.lang.String s = bs.toStringUtf8();
stringResponse_ = s;
return s;
} else {
return (java.lang.String) ref;
}
}
/**
* <code>string stringResponse = 1;</code>
* @return The bytes for stringResponse.
*/
public com.google.protobuf.ByteString
getStringResponseBytes() {
java.lang.Object ref = stringResponse_;
if (ref instanceof String) {
com.google.protobuf.ByteString b =
com.google.protobuf.ByteString.copyFromUtf8(
(java.lang.String) ref);
stringResponse_ = b;
return b;
} else {
return (com.google.protobuf.ByteString) ref;
}
}
/**
* <code>string stringResponse = 1;</code>
* @param value The stringResponse to set.
* @return This builder for chaining.
*/
public Builder setStringResponse(
java.lang.String value) {
if (value == null) {
throw new NullPointerException();
}
stringResponse_ = value;
onChanged();
return this;
}
/**
* <code>string stringResponse = 1;</code>
* @return This builder for chaining.
*/
public Builder clearStringResponse() {
stringResponse_ = getDefaultInstance().getStringResponse();
onChanged();
return this;
}
/**
* <code>string stringResponse = 1;</code>
* @param value The bytes for stringResponse to set.
* @return This builder for chaining.
*/
public Builder setStringResponseBytes(
com.google.protobuf.ByteString value) {
if (value == null) {
throw new NullPointerException();
}
checkByteStringIsUtf8(value);
stringResponse_ = value;
onChanged();
return this;
}
@java.lang.Override
public final Builder setUnknownFields(
final com.google.protobuf.UnknownFieldSet unknownFields) {
return super.setUnknownFields(unknownFields);
}
@java.lang.Override
public final Builder mergeUnknownFields(
final com.google.protobuf.UnknownFieldSet unknownFields) {
return super.mergeUnknownFields(unknownFields);
}
// @@protoc_insertion_point(builder_scope:com.example.grpc.ServerResponse)
}
// @@protoc_insertion_point(class_scope:com.example.grpc.ServerResponse)
private static final com.example.grpc.BidirectionalServiceOuterClass.ServerResponse DEFAULT_INSTANCE;
static {
DEFAULT_INSTANCE = new com.example.grpc.BidirectionalServiceOuterClass.ServerResponse();
}
public static com.example.grpc.BidirectionalServiceOuterClass.ServerResponse getDefaultInstance() {
return DEFAULT_INSTANCE;
}
private static final com.google.protobuf.Parser<ServerResponse>
PARSER = new com.google.protobuf.AbstractParser<ServerResponse>() {
@java.lang.Override
public ServerResponse parsePartialFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return new ServerResponse(input, extensionRegistry);
}
};
public static com.google.protobuf.Parser<ServerResponse> parser() {
return PARSER;
}
@java.lang.Override
public com.google.protobuf.Parser<ServerResponse> getParserForType() {
return PARSER;
}
@java.lang.Override
public com.example.grpc.BidirectionalServiceOuterClass.ServerResponse getDefaultInstanceForType() {
return DEFAULT_INSTANCE;
}
}
private static final com.google.protobuf.Descriptors.Descriptor
internal_static_com_example_grpc_ClientRequest_descriptor;
private static final
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internal_static_com_example_grpc_ClientRequest_fieldAccessorTable;
private static final com.google.protobuf.Descriptors.Descriptor
internal_static_com_example_grpc_ServerResponse_descriptor;
private static final
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internal_static_com_example_grpc_ServerResponse_fieldAccessorTable;
public static com.google.protobuf.Descriptors.FileDescriptor
getDescriptor() {
return descriptor;
}
private static com.google.protobuf.Descriptors.FileDescriptor
descriptor;
static {
java.lang.String[] descriptorData = {
"\n\032BidirectionalService.proto\022\020com.exampl" +
"e.grpc\"&\n\rClientRequest\022\025\n\rstringRequest" +
"\030\001 \001(\t\"(\n\016ServerResponse\022\026\n\016stringRespon" +
"se\030\001 \001(\t2n\n\024BidirectionalService\022V\n\rbidi" +
"rectional\022\037.com.example.grpc.ClientReque" +
"st\032 .com.example.grpc.ServerResponse(\0010\001" +
"b\006proto3"
};
descriptor = com.google.protobuf.Descriptors.FileDescriptor
.internalBuildGeneratedFileFrom(descriptorData,
new com.google.protobuf.Descriptors.FileDescriptor[] {
});
internal_static_com_example_grpc_ClientRequest_descriptor =
getDescriptor().getMessageTypes().get(0);
internal_static_com_example_grpc_ClientRequest_fieldAccessorTable = new
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable(
internal_static_com_example_grpc_ClientRequest_descriptor,
new java.lang.String[] { "StringRequest", });
internal_static_com_example_grpc_ServerResponse_descriptor =
getDescriptor().getMessageTypes().get(1);
internal_static_com_example_grpc_ServerResponse_fieldAccessorTable = new
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable(
internal_static_com_example_grpc_ServerResponse_descriptor,
new java.lang.String[] { "StringResponse", });
}
// @@protoc_insertion_point(outer_class_scope)
}
...@@ -19,23 +19,11 @@ public final class GreetingServiceOuterClass { ...@@ -19,23 +19,11 @@ public final class GreetingServiceOuterClass {
com.google.protobuf.MessageOrBuilder { com.google.protobuf.MessageOrBuilder {
/** /**
* <pre>
* Each message attribute is strongly typed.
* You also must assign a "tag" number.
* Each tag number is unique within the message.
* </pre>
*
* <code>string name = 1;</code> * <code>string name = 1;</code>
* @return The name. * @return The name.
*/ */
java.lang.String getName(); java.lang.String getName();
/** /**
* <pre>
* Each message attribute is strongly typed.
* You also must assign a "tag" number.
* Each tag number is unique within the message.
* </pre>
*
* <code>string name = 1;</code> * <code>string name = 1;</code>
* @return The bytes for name. * @return The bytes for name.
*/ */
...@@ -43,39 +31,23 @@ public final class GreetingServiceOuterClass { ...@@ -43,39 +31,23 @@ public final class GreetingServiceOuterClass {
getNameBytes(); getNameBytes();
/** /**
* <pre>
* This defines a strongly typed list of String
* </pre>
*
* <code>repeated string hobbies = 2;</code> * <code>repeated string hobbies = 2;</code>
* @return A list containing the hobbies. * @return A list containing the hobbies.
*/ */
java.util.List<java.lang.String> java.util.List<java.lang.String>
getHobbiesList(); getHobbiesList();
/** /**
* <pre>
* This defines a strongly typed list of String
* </pre>
*
* <code>repeated string hobbies = 2;</code> * <code>repeated string hobbies = 2;</code>
* @return The count of hobbies. * @return The count of hobbies.
*/ */
int getHobbiesCount(); int getHobbiesCount();
/** /**
* <pre>
* This defines a strongly typed list of String
* </pre>
*
* <code>repeated string hobbies = 2;</code> * <code>repeated string hobbies = 2;</code>
* @param index The index of the element to return. * @param index The index of the element to return.
* @return The hobbies at the given index. * @return The hobbies at the given index.
*/ */
java.lang.String getHobbies(int index); java.lang.String getHobbies(int index);
/** /**
* <pre>
* This defines a strongly typed list of String
* </pre>
*
* <code>repeated string hobbies = 2;</code> * <code>repeated string hobbies = 2;</code>
* @param index The index of the value to return. * @param index The index of the value to return.
* @return The bytes of the hobbies at the given index. * @return The bytes of the hobbies at the given index.
...@@ -188,12 +160,6 @@ public final class GreetingServiceOuterClass { ...@@ -188,12 +160,6 @@ public final class GreetingServiceOuterClass {
public static final int NAME_FIELD_NUMBER = 1; public static final int NAME_FIELD_NUMBER = 1;
private volatile java.lang.Object name_; private volatile java.lang.Object name_;
/** /**
* <pre>
* Each message attribute is strongly typed.
* You also must assign a "tag" number.
* Each tag number is unique within the message.
* </pre>
*
* <code>string name = 1;</code> * <code>string name = 1;</code>
* @return The name. * @return The name.
*/ */
...@@ -210,12 +176,6 @@ public final class GreetingServiceOuterClass { ...@@ -210,12 +176,6 @@ public final class GreetingServiceOuterClass {
} }
} }
/** /**
* <pre>
* Each message attribute is strongly typed.
* You also must assign a "tag" number.
* Each tag number is unique within the message.
* </pre>
*
* <code>string name = 1;</code> * <code>string name = 1;</code>
* @return The bytes for name. * @return The bytes for name.
*/ */
...@@ -236,10 +196,6 @@ public final class GreetingServiceOuterClass { ...@@ -236,10 +196,6 @@ public final class GreetingServiceOuterClass {
public static final int HOBBIES_FIELD_NUMBER = 2; public static final int HOBBIES_FIELD_NUMBER = 2;
private com.google.protobuf.LazyStringList hobbies_; private com.google.protobuf.LazyStringList hobbies_;
/** /**
* <pre>
* This defines a strongly typed list of String
* </pre>
*
* <code>repeated string hobbies = 2;</code> * <code>repeated string hobbies = 2;</code>
* @return A list containing the hobbies. * @return A list containing the hobbies.
*/ */
...@@ -248,10 +204,6 @@ public final class GreetingServiceOuterClass { ...@@ -248,10 +204,6 @@ public final class GreetingServiceOuterClass {
return hobbies_; return hobbies_;
} }
/** /**
* <pre>
* This defines a strongly typed list of String
* </pre>
*
* <code>repeated string hobbies = 2;</code> * <code>repeated string hobbies = 2;</code>
* @return The count of hobbies. * @return The count of hobbies.
*/ */
...@@ -259,10 +211,6 @@ public final class GreetingServiceOuterClass { ...@@ -259,10 +211,6 @@ public final class GreetingServiceOuterClass {
return hobbies_.size(); return hobbies_.size();
} }
/** /**
* <pre>
* This defines a strongly typed list of String
* </pre>
*
* <code>repeated string hobbies = 2;</code> * <code>repeated string hobbies = 2;</code>
* @param index The index of the element to return. * @param index The index of the element to return.
* @return The hobbies at the given index. * @return The hobbies at the given index.
...@@ -271,10 +219,6 @@ public final class GreetingServiceOuterClass { ...@@ -271,10 +219,6 @@ public final class GreetingServiceOuterClass {
return hobbies_.get(index); return hobbies_.get(index);
} }
/** /**
* <pre>
* This defines a strongly typed list of String
* </pre>
*
* <code>repeated string hobbies = 2;</code> * <code>repeated string hobbies = 2;</code>
* @param index The index of the value to return. * @param index The index of the value to return.
* @return The bytes of the hobbies at the given index. * @return The bytes of the hobbies at the given index.
...@@ -628,12 +572,6 @@ public final class GreetingServiceOuterClass { ...@@ -628,12 +572,6 @@ public final class GreetingServiceOuterClass {
private java.lang.Object name_ = ""; private java.lang.Object name_ = "";
/** /**
* <pre>
* Each message attribute is strongly typed.
* You also must assign a "tag" number.
* Each tag number is unique within the message.
* </pre>
*
* <code>string name = 1;</code> * <code>string name = 1;</code>
* @return The name. * @return The name.
*/ */
...@@ -650,12 +588,6 @@ public final class GreetingServiceOuterClass { ...@@ -650,12 +588,6 @@ public final class GreetingServiceOuterClass {
} }
} }
/** /**
* <pre>
* Each message attribute is strongly typed.
* You also must assign a "tag" number.
* Each tag number is unique within the message.
* </pre>
*
* <code>string name = 1;</code> * <code>string name = 1;</code>
* @return The bytes for name. * @return The bytes for name.
*/ */
...@@ -673,12 +605,6 @@ public final class GreetingServiceOuterClass { ...@@ -673,12 +605,6 @@ public final class GreetingServiceOuterClass {
} }
} }
/** /**
* <pre>
* Each message attribute is strongly typed.
* You also must assign a "tag" number.
* Each tag number is unique within the message.
* </pre>
*
* <code>string name = 1;</code> * <code>string name = 1;</code>
* @param value The name to set. * @param value The name to set.
* @return This builder for chaining. * @return This builder for chaining.
...@@ -694,12 +620,6 @@ public final class GreetingServiceOuterClass { ...@@ -694,12 +620,6 @@ public final class GreetingServiceOuterClass {
return this; return this;
} }
/** /**
* <pre>
* Each message attribute is strongly typed.
* You also must assign a "tag" number.
* Each tag number is unique within the message.
* </pre>
*
* <code>string name = 1;</code> * <code>string name = 1;</code>
* @return This builder for chaining. * @return This builder for chaining.
*/ */
...@@ -710,12 +630,6 @@ public final class GreetingServiceOuterClass { ...@@ -710,12 +630,6 @@ public final class GreetingServiceOuterClass {
return this; return this;
} }
/** /**
* <pre>
* Each message attribute is strongly typed.
* You also must assign a "tag" number.
* Each tag number is unique within the message.
* </pre>
*
* <code>string name = 1;</code> * <code>string name = 1;</code>
* @param value The bytes for name to set. * @param value The bytes for name to set.
* @return This builder for chaining. * @return This builder for chaining.
...@@ -740,10 +654,6 @@ public final class GreetingServiceOuterClass { ...@@ -740,10 +654,6 @@ public final class GreetingServiceOuterClass {
} }
} }
/** /**
* <pre>
* This defines a strongly typed list of String
* </pre>
*
* <code>repeated string hobbies = 2;</code> * <code>repeated string hobbies = 2;</code>
* @return A list containing the hobbies. * @return A list containing the hobbies.
*/ */
...@@ -752,10 +662,6 @@ public final class GreetingServiceOuterClass { ...@@ -752,10 +662,6 @@ public final class GreetingServiceOuterClass {
return hobbies_.getUnmodifiableView(); return hobbies_.getUnmodifiableView();
} }
/** /**
* <pre>
* This defines a strongly typed list of String
* </pre>
*
* <code>repeated string hobbies = 2;</code> * <code>repeated string hobbies = 2;</code>
* @return The count of hobbies. * @return The count of hobbies.
*/ */
...@@ -763,10 +669,6 @@ public final class GreetingServiceOuterClass { ...@@ -763,10 +669,6 @@ public final class GreetingServiceOuterClass {
return hobbies_.size(); return hobbies_.size();
} }
/** /**
* <pre>
* This defines a strongly typed list of String
* </pre>
*
* <code>repeated string hobbies = 2;</code> * <code>repeated string hobbies = 2;</code>
* @param index The index of the element to return. * @param index The index of the element to return.
* @return The hobbies at the given index. * @return The hobbies at the given index.
...@@ -775,10 +677,6 @@ public final class GreetingServiceOuterClass { ...@@ -775,10 +677,6 @@ public final class GreetingServiceOuterClass {
return hobbies_.get(index); return hobbies_.get(index);
} }
/** /**
* <pre>
* This defines a strongly typed list of String
* </pre>
*
* <code>repeated string hobbies = 2;</code> * <code>repeated string hobbies = 2;</code>
* @param index The index of the value to return. * @param index The index of the value to return.
* @return The bytes of the hobbies at the given index. * @return The bytes of the hobbies at the given index.
...@@ -788,10 +686,6 @@ public final class GreetingServiceOuterClass { ...@@ -788,10 +686,6 @@ public final class GreetingServiceOuterClass {
return hobbies_.getByteString(index); return hobbies_.getByteString(index);
} }
/** /**
* <pre>
* This defines a strongly typed list of String
* </pre>
*
* <code>repeated string hobbies = 2;</code> * <code>repeated string hobbies = 2;</code>
* @param index The index to set the value at. * @param index The index to set the value at.
* @param value The hobbies to set. * @param value The hobbies to set.
...@@ -808,10 +702,6 @@ public final class GreetingServiceOuterClass { ...@@ -808,10 +702,6 @@ public final class GreetingServiceOuterClass {
return this; return this;
} }
/** /**
* <pre>
* This defines a strongly typed list of String
* </pre>
*
* <code>repeated string hobbies = 2;</code> * <code>repeated string hobbies = 2;</code>
* @param value The hobbies to add. * @param value The hobbies to add.
* @return This builder for chaining. * @return This builder for chaining.
...@@ -827,10 +717,6 @@ public final class GreetingServiceOuterClass { ...@@ -827,10 +717,6 @@ public final class GreetingServiceOuterClass {
return this; return this;
} }
/** /**
* <pre>
* This defines a strongly typed list of String
* </pre>
*
* <code>repeated string hobbies = 2;</code> * <code>repeated string hobbies = 2;</code>
* @param values The hobbies to add. * @param values The hobbies to add.
* @return This builder for chaining. * @return This builder for chaining.
...@@ -844,10 +730,6 @@ public final class GreetingServiceOuterClass { ...@@ -844,10 +730,6 @@ public final class GreetingServiceOuterClass {
return this; return this;
} }
/** /**
* <pre>
* This defines a strongly typed list of String
* </pre>
*
* <code>repeated string hobbies = 2;</code> * <code>repeated string hobbies = 2;</code>
* @return This builder for chaining. * @return This builder for chaining.
*/ */
...@@ -858,10 +740,6 @@ public final class GreetingServiceOuterClass { ...@@ -858,10 +740,6 @@ public final class GreetingServiceOuterClass {
return this; return this;
} }
/** /**
* <pre>
* This defines a strongly typed list of String
* </pre>
*
* <code>repeated string hobbies = 2;</code> * <code>repeated string hobbies = 2;</code>
* @param value The bytes of the hobbies to add. * @param value The bytes of the hobbies to add.
* @return This builder for chaining. * @return This builder for chaining.
......
syntax = "proto3";
package com.example.grpc;
message ClientRequest {
string stringRequest = 1;
}
message ServerResponse {
string stringResponse = 1;
}
service BidirectionalService {
rpc bidirectional(stream ClientRequest) returns (stream ServerResponse);
}
...@@ -3,17 +3,8 @@ package com.example.grpc; ...@@ -3,17 +3,8 @@ package com.example.grpc;
// Request payload // Request payload
message HelloRequest { message HelloRequest {
// Each message attribute is strongly typed.
// You also must assign a "tag" number.
// Each tag number is unique within the message.
string name = 1; string name = 1;
// This defines a strongly typed list of String
repeated string hobbies = 2; repeated string hobbies = 2;
// There are many more basics types, like Enum, Map
// See https://developers.google.com/protocol-buffers/docs/proto3
// for more information.
} }
message HelloResponse { message HelloResponse {
......
...@@ -10,6 +10,9 @@ com/example/chat/ChatServiceOuterClass.java ...@@ -10,6 +10,9 @@ com/example/chat/ChatServiceOuterClass.java
chat/ChatClient.java chat/ChatClient.java
chat.ChatClient chat.ChatClient
chat.ChatClient$1 chat.ChatClient$1
bidirectional/BidirectionalServiceImpl.java
bidirectional.BidirectionalServiceImpl
bidirectional.BidirectionalServiceImpl$1
chat/ChatServiceImpl.java chat/ChatServiceImpl.java
chat.ChatServiceImpl chat.ChatServiceImpl
chat.ChatServiceImpl$1 chat.ChatServiceImpl$1
...@@ -26,6 +29,17 @@ com/example/grpc/GreetingServiceGrpc.java ...@@ -26,6 +29,17 @@ com/example/grpc/GreetingServiceGrpc.java
com.example.grpc.GreetingServiceGrpc$GreetingServiceMethodDescriptorSupplier com.example.grpc.GreetingServiceGrpc$GreetingServiceMethodDescriptorSupplier
com.example.grpc.GreetingServiceGrpc$GreetingServiceStub com.example.grpc.GreetingServiceGrpc$GreetingServiceStub
com.example.grpc.GreetingServiceGrpc$MethodHandlers com.example.grpc.GreetingServiceGrpc$MethodHandlers
com/example/grpc/BidirectionalServiceGrpc.java
com.example.grpc.BidirectionalServiceGrpc
com.example.grpc.BidirectionalServiceGrpc$1
com.example.grpc.BidirectionalServiceGrpc$BidirectionalServiceBaseDescriptorSupplier
com.example.grpc.BidirectionalServiceGrpc$BidirectionalServiceBlockingStub
com.example.grpc.BidirectionalServiceGrpc$BidirectionalServiceFileDescriptorSupplier
com.example.grpc.BidirectionalServiceGrpc$BidirectionalServiceFutureStub
com.example.grpc.BidirectionalServiceGrpc$BidirectionalServiceImplBase
com.example.grpc.BidirectionalServiceGrpc$BidirectionalServiceMethodDescriptorSupplier
com.example.grpc.BidirectionalServiceGrpc$BidirectionalServiceStub
com.example.grpc.BidirectionalServiceGrpc$MethodHandlers
com/example/grpc/GreetingServiceOuterClass.java com/example/grpc/GreetingServiceOuterClass.java
com.example.grpc.GreetingServiceOuterClass com.example.grpc.GreetingServiceOuterClass
com.example.grpc.GreetingServiceOuterClass$1 com.example.grpc.GreetingServiceOuterClass$1
...@@ -37,6 +51,8 @@ com/example/grpc/GreetingServiceOuterClass.java ...@@ -37,6 +51,8 @@ com/example/grpc/GreetingServiceOuterClass.java
com.example.grpc.GreetingServiceOuterClass$HelloResponse$1 com.example.grpc.GreetingServiceOuterClass$HelloResponse$1
com.example.grpc.GreetingServiceOuterClass$HelloResponse$Builder com.example.grpc.GreetingServiceOuterClass$HelloResponse$Builder
com.example.grpc.GreetingServiceOuterClass$HelloResponseOrBuilder com.example.grpc.GreetingServiceOuterClass$HelloResponseOrBuilder
bidirectional/Server.java
bidirectional.Server
com/example/chat/ChatServiceGrpc.java com/example/chat/ChatServiceGrpc.java
com.example.chat.ChatServiceGrpc com.example.chat.ChatServiceGrpc
com.example.chat.ChatServiceGrpc$1 com.example.chat.ChatServiceGrpc$1
...@@ -48,6 +64,9 @@ com/example/chat/ChatServiceGrpc.java ...@@ -48,6 +64,9 @@ com/example/chat/ChatServiceGrpc.java
com.example.chat.ChatServiceGrpc$ChatServiceMethodDescriptorSupplier com.example.chat.ChatServiceGrpc$ChatServiceMethodDescriptorSupplier
com.example.chat.ChatServiceGrpc$ChatServiceStub com.example.chat.ChatServiceGrpc$ChatServiceStub
com.example.chat.ChatServiceGrpc$MethodHandlers com.example.chat.ChatServiceGrpc$MethodHandlers
bidirectional/Client.java
bidirectional.Client
bidirectional.Client$1
grpchelloserver/App.java grpchelloserver/App.java
grpchelloserver.App grpchelloserver.App
it/ewlab/actor/ActorOuterClass.java it/ewlab/actor/ActorOuterClass.java
...@@ -63,10 +82,21 @@ it/ewlab/actor/ActorOuterClass.java ...@@ -63,10 +82,21 @@ it/ewlab/actor/ActorOuterClass.java
it.ewlab.actor.ActorOuterClass$Actor$Sex it.ewlab.actor.ActorOuterClass$Actor$Sex
it.ewlab.actor.ActorOuterClass$Actor$Sex$1 it.ewlab.actor.ActorOuterClass$Actor$Sex$1
it.ewlab.actor.ActorOuterClass$ActorOrBuilder it.ewlab.actor.ActorOuterClass$ActorOrBuilder
com/example/grpc/BidirectionalServiceOuterClass.java
com.example.grpc.BidirectionalServiceOuterClass
com.example.grpc.BidirectionalServiceOuterClass$1
com.example.grpc.BidirectionalServiceOuterClass$ClientRequest
com.example.grpc.BidirectionalServiceOuterClass$ClientRequest$1
com.example.grpc.BidirectionalServiceOuterClass$ClientRequest$Builder
com.example.grpc.BidirectionalServiceOuterClass$ClientRequestOrBuilder
com.example.grpc.BidirectionalServiceOuterClass$ServerResponse
com.example.grpc.BidirectionalServiceOuterClass$ServerResponse$1
com.example.grpc.BidirectionalServiceOuterClass$ServerResponse$Builder
com.example.grpc.BidirectionalServiceOuterClass$ServerResponseOrBuilder
grpchelloserver/GreetingServiceImpl.java grpchelloserver/GreetingServiceImpl.java
grpchelloserver.GreetingServiceImpl grpchelloserver.GreetingServiceImpl
actor/Server.java
actor.Server
grpchelloserver/GreetingServiceClient.java grpchelloserver/GreetingServiceClient.java
grpchelloserver.GreetingServiceClient grpchelloserver.GreetingServiceClient
grpchelloserver.GreetingServiceClient$1 grpchelloserver.GreetingServiceClient$1
actor/Server.java
actor.Server
...@@ -10,6 +10,7 @@ public class Server { ...@@ -10,6 +10,7 @@ public class Server {
public static void main(String[] args) throws IOException { public static void main(String[] args) throws IOException {
System.out.println("The server is running...\n");
ServerSocket serverSocket = new ServerSocket(9999); ServerSocket serverSocket = new ServerSocket(9999);
......
package bidirectional;
import com.example.grpc.BidirectionalServiceGrpc.*;
import com.example.grpc.BidirectionalServiceOuterClass.*;
import io.grpc.stub.StreamObserver;
public class BidirectionalServiceImpl extends BidirectionalServiceImplBase {
@Override
public StreamObserver<ClientRequest> bidirectional(StreamObserver<ServerResponse> responseObserver){
//it returns the stream that will be used by the clients to send messages. The client will write on this stream
return new StreamObserver<ClientRequest>() {
//receiving a message from the client
public void onNext(ClientRequest clientRequest) {
String clientStringRequest = clientRequest.getStringRequest();
System.out.println("[FROM CLIENT] " + clientStringRequest);
// sending the response to the client
System.out.println("Sending the response to the client...\n");
responseObserver.onNext(ServerResponse.newBuilder().setStringResponse("I've received this message: '" + clientStringRequest + "'").build());
}
public void onError(Throwable throwable) {
}
public void onCompleted() {
}
};
}
}
package bidirectional;
import com.example.grpc.BidirectionalServiceGrpc.*;
import com.example.grpc.BidirectionalServiceGrpc;
import com.example.grpc.BidirectionalServiceOuterClass.*;
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
import io.grpc.stub.StreamObserver;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
public class Client {
public final static String IP = "localhost";
public final static int PORT = 8888;
public static void main(String[] args) throws IOException {
//opening a connection with server
final ManagedChannel channel = ManagedChannelBuilder.forTarget(IP+":"+PORT).usePlaintext().build();
//creating the asynchronous stub
BidirectionalServiceStub stub = BidirectionalServiceGrpc.newStub(channel);
//the stub returns a stream to communicate with the server.
//the argument is the stream of messages which are transmitted by the server.
StreamObserver<ClientRequest> serverStream = stub.bidirectional(new StreamObserver<ServerResponse>() {
//remember: all the methods here are CALLBACKS which are handled in an asynchronous manner.
//we define what to do when a message from the server arrives (just print the message)
public void onNext(ServerResponse serverResponse) {
System.out.println("[FROM SERVER] " + serverResponse.getStringResponse());
}
public void onError(Throwable throwable) {
}
public void onCompleted() {
}
});
String msg = "First request from the client";
System.out.println("Sending the message '" + msg + "' to the server...");
serverStream.onNext(ClientRequest.newBuilder().setStringRequest(msg).build());
msg = "Second request from the client";
System.out.println("Sending the message '" + msg + "' to the server...");
serverStream.onNext(ClientRequest.newBuilder().setStringRequest(msg).build());
msg = "Third request from the client";
System.out.println("Sending the message '" + msg + "' to the server...");
serverStream.onNext(ClientRequest.newBuilder().setStringRequest(msg).build());
try {
//you need this. otherwise the method will terminate before that answers from the server are received
channel.awaitTermination(10, TimeUnit.SECONDS);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
package bidirectional;
import io.grpc.ServerBuilder;
import java.io.IOException;
public class Server {
public static void main( String[] args ) {
try {
io.grpc.Server server = ServerBuilder.forPort(8888).addService(new BidirectionalServiceImpl()).build();
server.start();
System.out.println("Server started!\n");
server.awaitTermination();
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
syntax = "proto3";
package com.example.grpc;
message ClientRequest {
string stringRequest = 1;
}
message ServerResponse {
string stringResponse = 1;
}
service BidirectionalService {
rpc bidirectional(stream ClientRequest) returns (stream ServerResponse);
}
...@@ -3,17 +3,8 @@ package com.example.grpc; ...@@ -3,17 +3,8 @@ package com.example.grpc;
// Request payload // Request payload
message HelloRequest { message HelloRequest {
// Each message attribute is strongly typed.
// You also must assign a "tag" number.
// Each tag number is unique within the message.
string name = 1; string name = 1;
// This defines a strongly typed list of String
repeated string hobbies = 2; repeated string hobbies = 2;
// There are many more basics types, like Enum, Map
// See https://developers.google.com/protocol-buffers/docs/proto3
// for more information.
} }
message HelloResponse { message HelloResponse {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment