public class AsyncStreamingOutputPlus extends AsyncChannelOutputPlus
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.Modifier and Type | Class and Description |
---|---|
static interface |
AsyncStreamingOutputPlus.BufferSupplier |
static interface |
AsyncStreamingOutputPlus.Write |
AsyncChannelOutputPlus.FlushException
buffer
Constructor and Description |
---|
AsyncStreamingOutputPlus(io.netty.channel.Channel channel) |
Modifier and Type | Method and Description |
---|---|
void |
discard()
Discard any buffered data, and the buffers that contain it.
|
protected void |
doFlush(int count) |
long |
position()
Returns the current position of the underlying target like a file-pointer
or the position withing a buffer.
|
long |
writeFileToChannel(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. |
int |
writeToChannel(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.
|
beginFlush, close, flush, flushed, flushedToNetwork, newDefaultChannel, parkUntilFlushed, releaseSpace
order, write, write, write, write, writeBoolean, writeByte, writeBytes, writeChar, writeChars, writeDouble, writeFloat, writeInt, writeLong, writeShort, writeUTF
retrieveTemporaryBuffer
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
hasPosition, write, writeUnsignedVInt, writeVInt
public AsyncStreamingOutputPlus(io.netty.channel.Channel channel)
protected void doFlush(int count) throws java.io.IOException
doFlush
in class AsyncChannelOutputPlus
java.io.IOException
public long position()
DataOutputPlus
DataOutputPlus.hasPosition()
.position
in interface DataOutputPlus
position
in class AsyncChannelOutputPlus
public int writeToChannel(AsyncStreamingOutputPlus.Write write, StreamManager.StreamRateLimiter limiter) throws java.io.IOException
Any exception thrown by the Write will be propagated to the caller, after any buffer is cleaned up.
java.io.IOException
public long writeFileToChannel(java.nio.channels.FileChannel file, StreamManager.StreamRateLimiter limiter) throws java.io.IOException
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.
java.io.IOException
public void discard()
AsyncChannelOutputPlus.close()
if we terminate exceptionally.discard
in class AsyncChannelOutputPlus
Copyright © 2009-2021 The Apache Software Foundation