public abstract class AsyncChannelOutputPlus extends BufferedDataOutputStreamPlus
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.
There are two logical threads accessing the state in this class: the eventLoop of the channel, and the writer
(the writer thread may change, so long as only one utilises the class at any time).
Each thread has exclusive write access to certain state in the class, with the other thread only viewing the state,
simplifying concurrency considerations.Modifier and Type | Class and Description |
---|---|
static class |
AsyncChannelOutputPlus.FlushException |
buffer
Constructor and Description |
---|
AsyncChannelOutputPlus(io.netty.channel.Channel channel) |
Modifier and Type | Method and Description |
---|---|
protected io.netty.channel.ChannelPromise |
beginFlush(int byteCount,
int lowWaterMark,
int highWaterMark)
Create a ChannelPromise for a flush of the given size.
|
void |
close()
Flush any remaining writes, and release any buffers.
|
abstract void |
discard()
Discard any buffered data, and the buffers that contain it.
|
protected abstract void |
doFlush(int count) |
void |
flush()
Perform an asynchronous flush, then waits until all outstanding flushes have completed
|
long |
flushed() |
long |
flushedToNetwork() |
protected java.nio.channels.WritableByteChannel |
newDefaultChannel() |
protected void |
parkUntilFlushed(long wakeUpWhenFlushed,
long signalWhenFlushed)
Utility method for waitUntilFlushed, which actually parks the current thread until the necessary
number of bytes have been flushed
This may only be invoked by the writer thread, never by the eventLoop.
|
abstract long |
position()
Returns the current position of the underlying target like a file-pointer
or the position withing a buffer.
|
protected void |
releaseSpace(long bytesFlushed)
Update our flushed count, and signal any waiters.
|
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 AsyncChannelOutputPlus(io.netty.channel.Channel channel)
protected io.netty.channel.ChannelPromise beginFlush(int byteCount, int lowWaterMark, int highWaterMark) throws java.io.IOException
This method will not return until the write is permitted by the provided watermarks and in flight bytes, and on its completion will mark the requested bytes flushed.
If this method returns normally, the ChannelPromise MUST be writtenAndFlushed, or else completed exceptionally.
java.io.IOException
protected void parkUntilFlushed(long wakeUpWhenFlushed, long signalWhenFlushed)
protected void releaseSpace(long bytesFlushed)
protected abstract void doFlush(int count) throws java.io.IOException
doFlush
in class BufferedDataOutputStreamPlus
java.io.IOException
public abstract long position()
DataOutputPlus
DataOutputPlus.hasPosition()
.public long flushed()
public long flushedToNetwork()
public void flush() throws java.io.IOException
flush
in interface java.io.Flushable
flush
in class BufferedDataOutputStreamPlus
java.io.IOException
- if any flush failspublic void close() throws java.io.IOException
flushFailed
, which will propagate them to the producer thread no later than its
final invocation to close()
or flush()
(that must not be followed by any further writes).close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in class BufferedDataOutputStreamPlus
java.io.IOException
public abstract void discard()
close()
if we terminate exceptionally.protected java.nio.channels.WritableByteChannel newDefaultChannel()
newDefaultChannel
in class DataOutputStreamPlus
Copyright © 2009-2021 The Apache Software Foundation