- java.lang.Object
-
- io.netty5.channel.ChannelOutboundBuffer
-
public final class ChannelOutboundBuffer extends Object
(Transport implementors only) an internal data structure used byAbstractChannel
to store its pending outbound write requests.All methods must be called by a transport implementation from an I/O thread, except the following ones:
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
ChannelOutboundBuffer.MessageProcessor<T extends Exception>
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addFlush()
Add a flush to thisChannelOutboundBuffer
.void
addMessage(Object msg, int size, Promise<Void> promise)
Add given message to thisChannelOutboundBuffer
.Object
current()
Return the current message to write ornull
if nothing was flushed before and so is ready to be written.long
currentProgress()
Return the current message flush progress.<T extends Exception>
voidforEachFlushedMessage(ChannelOutboundBuffer.MessageProcessor<T> processor)
CallChannelOutboundBuffer.MessageProcessor.processMessage(Object)
for each flushed message in thisChannelOutboundBuffer
untilChannelOutboundBuffer.MessageProcessor.processMessage(Object)
returnsfalse
or there are no more flushed messages to process.boolean
isEmpty()
int
nioBufferCount()
Returns the number ofByteBuffer
that can be written out of theByteBuffer
array that was obtained vianioBuffers()
.ByteBuffer[]
nioBuffers()
Returns an array of direct NIO buffers if the currently pending messages are made ofBuffer
only.ByteBuffer[]
nioBuffers(int maxCount, long maxBytes)
Returns an array of direct NIO buffers if the currently pending messages are made ofBuffer
only.long
nioBufferSize()
Returns the number of bytes that can be written out of theByteBuffer
array that was obtained vianioBuffers()
.void
progress(long amount)
Notify thePromise
of the current message about writing progress.boolean
remove()
Will remove the current message, mark itsPromise
as success and returntrue
.boolean
remove(Throwable cause)
void
removeBytes(long writtenBytes)
Removes the fully written entries and update the reader index of the partially written entry.int
size()
Returns the number of flushed messages in thisChannelOutboundBuffer
.long
totalPendingWriteBytes()
-
-
-
Method Detail
-
addMessage
public void addMessage(Object msg, int size, Promise<Void> promise)
Add given message to thisChannelOutboundBuffer
. The givenPromise
will be notified once the message was written.
-
addFlush
public void addFlush()
Add a flush to thisChannelOutboundBuffer
. This means all previous added messages are marked as flushed and so you will be able to handle them.
-
current
public Object current()
Return the current message to write ornull
if nothing was flushed before and so is ready to be written.
-
currentProgress
public long currentProgress()
Return the current message flush progress.- Returns:
0
if nothing was flushed before for the current message or there is no current message
-
progress
public void progress(long amount)
Notify thePromise
of the current message about writing progress.
-
remove
public boolean remove()
Will remove the current message, mark itsPromise
as success and returntrue
. If no flushed message exists at the time this method is called it will returnfalse
to signal that no more messages are ready to be handled.
-
remove
public boolean remove(Throwable cause)
-
removeBytes
public void removeBytes(long writtenBytes)
-
nioBuffers
public ByteBuffer[] nioBuffers()
Returns an array of direct NIO buffers if the currently pending messages are made ofBuffer
only.nioBufferCount()
andnioBufferSize()
will return the number of NIO buffers in the returned array and the total number of readable bytes of the NIO buffers respectively.Note that the returned array is reused and thus should not escape
AbstractChannel.doWrite(ChannelOutboundBuffer)
.
-
nioBuffers
public ByteBuffer[] nioBuffers(int maxCount, long maxBytes)
Returns an array of direct NIO buffers if the currently pending messages are made ofBuffer
only.nioBufferCount()
andnioBufferSize()
will return the number of NIO buffers in the returned array and the total number of readable bytes of the NIO buffers respectively.Note that the returned array is reused and thus should not escape
AbstractChannel.doWrite(ChannelOutboundBuffer)
.- Parameters:
maxCount
- The maximum amount of buffers that will be added to the return value.maxBytes
- A hint toward the maximum number of bytes to include as part of the return value. Note that this value maybe exceeded because we make a best effort to include at least 1ByteBuffer
in the return value to ensure write progress is made.
-
nioBufferCount
public int nioBufferCount()
Returns the number ofByteBuffer
that can be written out of theByteBuffer
array that was obtained vianioBuffers()
. This method MUST be called afternioBuffers()
was called.
-
nioBufferSize
public long nioBufferSize()
Returns the number of bytes that can be written out of theByteBuffer
array that was obtained vianioBuffers()
. This method MUST be called afternioBuffers()
was called.
-
size
public int size()
Returns the number of flushed messages in thisChannelOutboundBuffer
.
-
isEmpty
public boolean isEmpty()
-
totalPendingWriteBytes
public long totalPendingWriteBytes()
-
forEachFlushedMessage
public <T extends Exception> void forEachFlushedMessage(ChannelOutboundBuffer.MessageProcessor<T> processor) throws T extends Exception
CallChannelOutboundBuffer.MessageProcessor.processMessage(Object)
for each flushed message in thisChannelOutboundBuffer
untilChannelOutboundBuffer.MessageProcessor.processMessage(Object)
returnsfalse
or there are no more flushed messages to process.- Throws:
T extends Exception
-
-