public final class ChannelOutboundBuffer extends Object
AbstractChannel
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:
Modifier and Type | Class and Description |
---|---|
static interface |
ChannelOutboundBuffer.MessageProcessor |
Modifier and Type | Method and Description |
---|---|
void |
addFlush()
Add a flush to this
ChannelOutboundBuffer . |
void |
addMessage(Object msg,
int size,
ChannelPromise promise)
Add given message to this
ChannelOutboundBuffer . |
Object |
current()
Return the current message to write or
null if nothing was flushed before and so is ready to be written. |
void |
forEachFlushedMessage(ChannelOutboundBuffer.MessageProcessor processor)
Call
ChannelOutboundBuffer.MessageProcessor.processMessage(Object) for each flushed message
in this ChannelOutboundBuffer until ChannelOutboundBuffer.MessageProcessor.processMessage(Object)
returns false or there are no more flushed messages to process. |
boolean |
getUserDefinedWritability(int index)
Returns
true if and only if the user-defined writability flag at the specified index is set to
true . |
boolean |
isEmpty()
|
boolean |
isWritable()
Returns
true if and only if the total number of pending bytes did
not exceed the write watermark of the Channel and
no user-defined writability flag has been set to
false . |
int |
nioBufferCount()
Returns the number of
ByteBuffer that can be written out of the ByteBuffer array that was
obtained via nioBuffers() . |
ByteBuffer[] |
nioBuffers()
Returns an array of direct NIO buffers if the currently pending messages are made of
ByteBuf only. |
long |
nioBufferSize()
Returns the number of bytes that can be written out of the
ByteBuffer array that was
obtained via nioBuffers() . |
void |
progress(long amount)
Notify the
ChannelPromise of the current message about writing progress. |
void |
recycle()
Deprecated.
|
boolean |
remove()
Will remove the current message, mark its
ChannelPromise as success and return true . |
boolean |
remove(Throwable cause)
Will remove the current message, mark its
ChannelPromise as failure using the given Throwable
and return true . |
void |
removeBytes(long writtenBytes)
Removes the fully written entries and update the reader index of the partially written entry.
|
void |
setUserDefinedWritability(int index,
boolean writable)
Sets a user-defined writability flag at the specified index.
|
int |
size()
Returns the number of flushed messages in this
ChannelOutboundBuffer . |
long |
totalPendingWriteBytes() |
public void addMessage(Object msg, int size, ChannelPromise promise)
ChannelOutboundBuffer
. The given ChannelPromise
will be notified once
the message was written.public void addFlush()
ChannelOutboundBuffer
. This means all previous added messages are marked as flushed
and so you will be able to handle them.public Object current()
null
if nothing was flushed before and so is ready to be written.public void progress(long amount)
ChannelPromise
of the current message about writing progress.public boolean remove()
ChannelPromise
as success and return true
. If no
flushed message exists at the time this method is called it will return false
to signal that no more
messages are ready to be handled.public boolean remove(Throwable cause)
ChannelPromise
as failure using the given Throwable
and return true
. If no flushed message exists at the time this method is called it will return
false
to signal that no more messages are ready to be handled.public void removeBytes(long writtenBytes)
ByteBuf
.public ByteBuffer[] nioBuffers()
ByteBuf
only.
nioBufferCount()
and nioBufferSize()
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)
.
Refer to NioSocketChannel.doWrite(ChannelOutboundBuffer)
for an example.
public int nioBufferCount()
ByteBuffer
that can be written out of the ByteBuffer
array that was
obtained via nioBuffers()
. This method MUST be called after nioBuffers()
was called.public long nioBufferSize()
ByteBuffer
array that was
obtained via nioBuffers()
. This method MUST be called after nioBuffers()
was called.public boolean isWritable()
true
if and only if the total number of pending bytes did
not exceed the write watermark of the Channel
and
no user-defined writability flag has been set to
false
.public boolean getUserDefinedWritability(int index)
true
if and only if the user-defined writability flag at the specified index is set to
true
.public void setUserDefinedWritability(int index, boolean writable)
public int size()
ChannelOutboundBuffer
.public boolean isEmpty()
@Deprecated public void recycle()
public long totalPendingWriteBytes()
public void forEachFlushedMessage(ChannelOutboundBuffer.MessageProcessor processor) throws Exception
ChannelOutboundBuffer.MessageProcessor.processMessage(Object)
for each flushed message
in this ChannelOutboundBuffer
until ChannelOutboundBuffer.MessageProcessor.processMessage(Object)
returns false
or there are no more flushed messages to process.Exception
Copyright © 2008–2015 The Netty Project. All rights reserved.