Class AsyncStreamingOutputPlus

  • All Implemented Interfaces:
    java.io.Closeable, java.io.DataOutput, java.io.Flushable, java.lang.AutoCloseable, DataOutputPlus, StreamingDataOutputPlus

    public class AsyncStreamingOutputPlus
    extends AsyncChannelOutputPlus
    implements StreamingDataOutputPlus
    A DataOutputStreamPlus that 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.
    • Constructor Detail

      • AsyncStreamingOutputPlus

        public AsyncStreamingOutputPlus​(io.netty.channel.Channel channel)
    • Method Detail

      • doFlush

        protected void doFlush​(int count)
                        throws java.io.IOException
        Specified by:
        doFlush in class AsyncChannelOutputPlus
        Throws:
        java.io.IOException
      • writeToChannel

        public int writeToChannel​(StreamingDataOutputPlus.Write write,
                                  StreamingDataOutputPlus.RateLimiter 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.

        Specified by:
        writeToChannel in interface StreamingDataOutputPlus
        Throws:
        java.io.IOException
      • writeFileToChannel

        public long writeFileToChannel​(java.nio.channels.FileChannel file,
                                       StreamingDataOutputPlus.RateLimiter limiter)
                                throws java.io.IOException
        Writes 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, 64KiB at a time, with at most 32+64KiB (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) or ByteBuffer(ssl) is flushed to the network.

        Specified by:
        writeFileToChannel in interface StreamingDataOutputPlus
        Throws:
        java.io.IOException