szetszwo commented on code in PR #1492: URL: https://github.com/apache/ratis/pull/1492#discussion_r3478011846
########## ratis-client/src/main/java/org/apache/ratis/client/api/DataStreamReadChunk.java: ########## @@ -0,0 +1,26 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ratis.client.api; + +import java.nio.ByteBuffer; + +/* A chunk returned from the streaming read API. */ +public interface DataStreamReadChunk { + ByteBuffer[] nioBuffers(); +} Review Comment: @amaliujia , thanks for working on this! It is a good idea to have methods to get ByteBuffer. Let's add it to `DataStreamPacket` instead of having a new interface: ```diff diff --git a/ratis-common/src/main/java/org/apache/ratis/datastream/impl/DataStreamPacketByteBuf.java b/ratis-common/src/main/java/org/apache/ratis/datastream/impl/DataStreamPacketByteBuf.java index e6ceeb93d..a6ac94130 100644 --- a/ratis-common/src/main/java/org/apache/ratis/datastream/impl/DataStreamPacketByteBuf.java +++ b/ratis-common/src/main/java/org/apache/ratis/datastream/impl/DataStreamPacketByteBuf.java @@ -23,6 +23,7 @@ import org.apache.ratis.protocol.ClientId; import org.apache.ratis.thirdparty.io.netty.buffer.ByteBuf; import org.apache.ratis.thirdparty.io.netty.buffer.Unpooled; +import java.nio.ByteBuffer; import java.util.concurrent.atomic.AtomicReference; /** @@ -56,6 +57,16 @@ public class DataStreamPacketByteBuf extends DataStreamPacketImpl { return getBuf().slice(); } + @Override + public ByteBuffer nioBuffer() { + return getBuf().nioBuffer(); + } + + @Override + public ByteBuffer[] nioBuffers() { + return getBuf().nioBuffers(); + } + public final void release() { final ByteBuf got = buf.getAndSet(null); if (got != null) { diff --git a/ratis-common/src/main/java/org/apache/ratis/datastream/impl/DataStreamPacketByteBuffer.java b/ratis-common/src/main/java/org/apache/ratis/datastream/impl/DataStreamPacketByteBuffer.java index b8d7b48a7..a7d6f49d9 100644 --- a/ratis-common/src/main/java/org/apache/ratis/datastream/impl/DataStreamPacketByteBuffer.java +++ b/ratis-common/src/main/java/org/apache/ratis/datastream/impl/DataStreamPacketByteBuffer.java @@ -44,4 +44,14 @@ public abstract class DataStreamPacketByteBuffer extends DataStreamPacketImpl { public ByteBuffer slice() { return buffer.slice(); } + + @Override + public ByteBuffer nioBuffer() { + return slice(); + } + + @Override + public ByteBuffer[] nioBuffers() { + return new ByteBuffer[]{slice()}; + } } diff --git a/ratis-common/src/main/java/org/apache/ratis/protocol/DataStreamPacket.java b/ratis-common/src/main/java/org/apache/ratis/protocol/DataStreamPacket.java index caebb9e9b..95c5e6211 100644 --- a/ratis-common/src/main/java/org/apache/ratis/protocol/DataStreamPacket.java +++ b/ratis-common/src/main/java/org/apache/ratis/protocol/DataStreamPacket.java @@ -20,6 +20,8 @@ package org.apache.ratis.protocol; import org.apache.ratis.proto.RaftProtos.DataStreamPacketHeaderProto.Type; +import java.nio.ByteBuffer; + public interface DataStreamPacket { ClientId getClientId(); @@ -30,4 +32,12 @@ public interface DataStreamPacket { long getStreamOffset(); long getDataLength(); + + default ByteBuffer nioBuffer() { + throw new UnsupportedOperationException(); + } + + default ByteBuffer[] nioBuffers() { + throw new UnsupportedOperationException(); + } } \ No newline at end of file ``` -- 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]
