Package org.apache.cassandra.net
Class AsyncStreamingOutputPlus
- java.lang.Object
-
- java.io.OutputStream
-
- org.apache.cassandra.io.util.DataOutputStreamPlus
-
- org.apache.cassandra.io.util.BufferedDataOutputStreamPlus
-
- org.apache.cassandra.net.AsyncChannelOutputPlus
-
- org.apache.cassandra.net.AsyncStreamingOutputPlus
-
- All Implemented Interfaces:
java.io.Closeable,java.io.DataOutput,java.io.Flushable,java.lang.AutoCloseable,DataOutputPlus
public class AsyncStreamingOutputPlus extends AsyncChannelOutputPlus
ADataOutputStreamPlusthat writes ASYNCHRONOUSLY to a Netty Channel. The close() and flush() methods synchronously wait for pending writes, and will propagate any exceptions encountered in writing them to the wire. The correctness of this class depends on the ChannelPromise we create against a Channel always being completed, which appears to be a guarantee provided by Netty so long as the event loop is running.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceAsyncStreamingOutputPlus.BufferSupplierstatic interfaceAsyncStreamingOutputPlus.Write-
Nested classes/interfaces inherited from class org.apache.cassandra.net.AsyncChannelOutputPlus
AsyncChannelOutputPlus.FlushException
-
-
Field Summary
-
Fields inherited from class org.apache.cassandra.io.util.BufferedDataOutputStreamPlus
buffer
-
-
Constructor Summary
Constructors Constructor Description AsyncStreamingOutputPlus(io.netty.channel.Channel channel)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddiscard()Discard any buffered data, and the buffers that contain it.protected voiddoFlush(int count)longposition()Returns the current position of the underlying target like a file-pointer or the position withing a buffer.longwriteFileToChannel(java.nio.channels.FileChannel file, StreamManager.StreamRateLimiter limiter)Writes all data in file channel to stream:
* For zero-copy-streaming, 1MiB at a time, with at most 2MiB in flight at once.intwriteToChannel(AsyncStreamingOutputPlus.Write write, StreamManager.StreamRateLimiter limiter)Provide a lambda that can request a buffer of suitable size, then fill the buffer and have that buffer written and flushed to the underlying channel, without having to handle buffer allocation, lifetime or cleanup, including in case of exceptions.-
Methods inherited from class org.apache.cassandra.net.AsyncChannelOutputPlus
beginFlush, close, flush, flushed, flushedToNetwork, newDefaultChannel, parkUntilFlushed, releaseSpace
-
Methods inherited from class org.apache.cassandra.io.util.BufferedDataOutputStreamPlus
order, write, write, write, write, writeBoolean, writeByte, writeBytes, writeChar, writeChars, writeDouble, writeFloat, writeInt, writeLong, writeShort, writeUTF
-
Methods inherited from class org.apache.cassandra.io.util.DataOutputStreamPlus
retrieveTemporaryBuffer
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.cassandra.io.util.DataOutputPlus
hasPosition, write, writeUnsignedVInt, writeVInt
-
-
-
-
Method Detail
-
doFlush
protected void doFlush(int count) throws java.io.IOException- Specified by:
doFlushin classAsyncChannelOutputPlus- Throws:
java.io.IOException
-
position
public long position()
Description copied from interface:DataOutputPlusReturns the current position of the underlying target like a file-pointer or the position withing a buffer. Not every implementation may support this functionality. Whether or not this functionality is supported can be checked via theDataOutputPlus.hasPosition().- Specified by:
positionin interfaceDataOutputPlus- Specified by:
positionin classAsyncChannelOutputPlus
-
writeToChannel
public int writeToChannel(AsyncStreamingOutputPlus.Write write, StreamManager.StreamRateLimiter limiter) throws java.io.IOException
Provide a lambda that can request a buffer of suitable size, then fill the buffer and have that buffer written and flushed to the underlying channel, without having to handle buffer allocation, lifetime or cleanup, including in case of exceptions.Any exception thrown by the Write will be propagated to the caller, after any buffer is cleaned up.
- Throws:
java.io.IOException
-
writeFileToChannel
public long writeFileToChannel(java.nio.channels.FileChannel file, StreamManager.StreamRateLimiter limiter) throws java.io.IOExceptionWrites all data in file channel to stream:
* For zero-copy-streaming, 1MiB at a time, with at most 2MiB in flight at once.
* For streaming with SSL, 64kb at a time, with at most 32+64kb (default low water mark + batch size) in flight.
This method takes ownership of the provided
FileChannel.WARNING: this method blocks only for permission to write to the netty channel; it exits before the
FileRegion(zero-copy) orByteBuffer(ssl) is flushed to the network.- Throws:
java.io.IOException
-
discard
public void discard()
Discard any buffered data, and the buffers that contain it. May be invoked instead ofAsyncChannelOutputPlus.close()if we terminate exceptionally.- Specified by:
discardin classAsyncChannelOutputPlus
-
-