amaliujia commented on code in PR #1481:
URL: https://github.com/apache/ratis/pull/1481#discussion_r3450340076
##########
ratis-client/src/main/java/org/apache/ratis/client/impl/DataStreamClientImpl.java:
##########
@@ -236,6 +244,114 @@ private CompletableFuture<DataStreamReply>
sendForward(DataStreamReply writeRepl
}
}
+ public final class DataStreamInputImpl implements DataStreamInput {
+ private final RaftClientRequest header;
+ private final CompletableFuture<DataStreamReply> replyFuture;
+ private final Queue<DataStreamReply> replies = new ArrayDeque<>();
+ private final Queue<CompletableFuture<DataStreamReply>> pendingReads = new
ArrayDeque<>();
+ private Throwable readException;
+ private boolean endOfStream;
+ private boolean closed;
+
+ private DataStreamInputImpl(RaftClientRequest request) {
+ this.header = request;
+ final ByteBuffer buffer =
ClientProtoUtils.toRaftClientRequestProtoByteBuffer(header);
+ final DataStreamRequestHeader h = new
DataStreamRequestHeader(header.getClientId(), Type.STREAM_HEADER,
+ header.getCallId(), 0, buffer.remaining(),
StandardWriteOption.FLUSH, StandardWriteOption.CLOSE);
+ this.replyFuture = dataStreamClientRpc.streamAsync(new
DataStreamRequestByteBuffer(h, buffer),
+ reply -> receive(reply.copy()));
+ replyFuture.whenComplete((reply, exception) -> {
+ if (exception != null) {
+ failReads(exception);
+ } else {
+ markEndOfStream();
+ }
Review Comment:
It reads much better, thanks!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]