use of org.apache.ratis.shaded.proto.RaftProtos.RaftClientReplyProto in project incubator-ratis by apache.
the class GrpcClientRpc method sendRequest.
private CompletableFuture<RaftClientReply> sendRequest(RaftClientRequest request, RaftClientProtocolClient proxy) throws IOException {
final RaftClientRequestProto requestProto = toRaftClientRequestProto(request);
final CompletableFuture<RaftClientReplyProto> replyFuture = new CompletableFuture<>();
// create a new grpc stream for each non-async call.
final StreamObserver<RaftClientRequestProto> requestObserver = proxy.appendWithTimeout(new StreamObserver<RaftClientReplyProto>() {
@Override
public void onNext(RaftClientReplyProto value) {
replyFuture.complete(value);
}
@Override
public void onError(Throwable t) {
replyFuture.completeExceptionally(RaftGrpcUtil.unwrapIOException(t));
}
@Override
public void onCompleted() {
if (!replyFuture.isDone()) {
replyFuture.completeExceptionally(new IOException(clientId + ": Stream completed but no reply for request " + request));
}
}
});
requestObserver.onNext(requestProto);
requestObserver.onCompleted();
return replyFuture.thenApply(ClientProtoUtils::toRaftClientReply);
}
Aggregations