Search in sources :

Example 1 with DataChannel

use of org.apache.ratis.statemachine.StateMachine.DataChannel in project incubator-ratis by apache.

the class DataStreamManagement method writeTo.

static long writeTo(ByteBuf buf, WriteOption[] options, DataStream stream) {
    final DataChannel channel = stream.getDataChannel();
    long byteWritten = 0;
    for (ByteBuffer buffer : buf.nioBuffers()) {
        try {
            byteWritten += channel.write(buffer);
        } catch (Throwable t) {
            throw new CompletionException(t);
        }
    }
    if (WriteOption.containsOption(options, StandardWriteOption.SYNC)) {
        try {
            channel.force(false);
        } catch (IOException e) {
            throw new CompletionException(e);
        }
    }
    if (WriteOption.containsOption(options, StandardWriteOption.CLOSE)) {
        close(stream);
    }
    return byteWritten;
}
Also used : DataChannel(org.apache.ratis.statemachine.StateMachine.DataChannel) CompletionException(java.util.concurrent.CompletionException) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer) DataStreamReplyByteBuffer(org.apache.ratis.datastream.impl.DataStreamReplyByteBuffer)

Aggregations

IOException (java.io.IOException)1 ByteBuffer (java.nio.ByteBuffer)1 CompletionException (java.util.concurrent.CompletionException)1 DataStreamReplyByteBuffer (org.apache.ratis.datastream.impl.DataStreamReplyByteBuffer)1 DataChannel (org.apache.ratis.statemachine.StateMachine.DataChannel)1