Top Description Inners Fields Constructors Methods
io.netty.channel

public final Class ChannelOutboundBuffer

extends Object
Class Inheritance
Imports
io.netty.buffer.AbstractReferenceCountedByteBuf, .ByteBuf, .ByteBufHolder, .Unpooled, io.netty.channel.socket.nio.NioSocketChannel, io.netty.util.Recycler.EnhancedHandle, .ReferenceCountUtil, io.netty.util.concurrent.FastThreadLocal, io.netty.util.internal.InternalThreadLocalMap, .ObjectPool, .ObjectPool.Handle, .ObjectPool.ObjectCreator, .ObjectUtil, .PromiseNotificationUtil, .SystemPropertyUtil, io.netty.util.internal.logging.InternalLogger, .InternalLoggerFactory, java.nio.ByteBuffer, java.nio.channels.ClosedChannelException, java.util.Arrays, java.util.concurrent.atomic.AtomicIntegerFieldUpdater, .AtomicLongFieldUpdater

(Transport implementors only) an internal data structure used by 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:

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
public static interface

Field Summary

Modifier and TypeField and Description
private final Channel
pack-priv static final int
private volatile Runnable
private int
private ChannelOutboundBuffer.Entry
private boolean
private static final InternalLogger
private static final FastThreadLocal<ByteBuffer[]>
private int
private long
private ChannelOutboundBuffer.Entry
private static final AtomicLongFieldUpdater<ChannelOutboundBuffer>
private volatile long
private ChannelOutboundBuffer.Entry
private volatile int
private static final AtomicIntegerFieldUpdater<ChannelOutboundBuffer>

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
addFlush()

Add a flush to this ChannelOutboundBuffer.

public void
addMessage(Object msg, int size, ChannelPromise promise)

Add given message to this ChannelOutboundBuffer.

public long
bytesBeforeUnwritable()

Get how many bytes can be written until isWritable() returns false.

public long
bytesBeforeWritable()

Get how many bytes must be drained from the underlying buffer until isWritable() returns true.

private void
private void
pack-priv void
close(final Throwable cause, final boolean allowChannelOpen)

pack-priv void
public Object
current()

Return the current message to write or null if nothing was flushed before and so is ready to be written.

public long

Returns:

0 if nothing was flushed before for the current message or there is no current message
currentProgress
()

Return the current message flush progress.

pack-priv void
decrementPendingOutboundBytes(long size)

Decrement the pending bytes which will be written at some point.

private void
decrementPendingOutboundBytes(long size, boolean invokeLater, boolean notifyWritability)

private static ByteBuffer[]
expandNioBufferArray(ByteBuffer[] array, int neededSpace, int size)

pack-priv void
failFlushed(Throwable cause, boolean notify)

private void
fireChannelWritabilityChanged(boolean invokeLater)

public void
forEachFlushedMessage(ChannelOutboundBuffer.MessageProcessor processor)

Call MessageProcessor#processMessage(Object) for each flushed message in this ChannelOutboundBuffer until MessageProcessor#processMessage(Object) returns false or there are no more flushed messages to process.

public boolean
getUserDefinedWritability(int index)

Returns true if and only if the user-defined writability flag at the specified index is set to true.

pack-priv void
incrementPendingOutboundBytes(long size)

Increment the pending bytes which will be written at some point.

private void
incrementPendingOutboundBytes(long size, boolean invokeLater)

public boolean
isEmpty()

Returns true if there are flushed messages in this ChannelOutboundBuffer or false otherwise.

private boolean
public 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.

public int
nioBufferCount()

Returns the number of ByteBuffer that can be written out of the ByteBuffer array that was obtained via nioBuffers().

public ByteBuffer[]
nioBuffers()

Returns an array of direct NIO buffers if the currently pending messages are made of ByteBuf only.

public ByteBuffer[]
nioBuffers(int
The maximum amount of buffers that will be added to the return value.
maxCount
,
long
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 1 ByteBuffer in the return value to ensure write progress is made.
maxBytes
)

Returns an array of direct NIO buffers if the currently pending messages are made of ByteBuf only.

private static int
nioBuffers(ChannelOutboundBuffer.Entry entry, ByteBuf buf, ByteBuffer[] nioBuffers, int nioBufferCount, int maxCount)

public long
nioBufferSize()

Returns the number of bytes that can be written out of the ByteBuffer array that was obtained via nioBuffers().

public void
progress(long amount)

Notify the ChannelPromise of the current message about writing progress.

public void
recycle()

Deprecated
public boolean
remove()

Will remove the current message, mark its ChannelPromise as success and return true.

public boolean
remove(Throwable cause)

Will remove the current message, mark its ChannelPromise as failure using the given Throwable and return true.

private boolean
remove0(Throwable cause, boolean notifyWritability)

public void
removeBytes(long writtenBytes)

Removes the fully written entries and update the reader index of the partially written entry.

private void
private static void
private static void
private void
setUnwritable(boolean invokeLater)

public void
setUserDefinedWritability(int index, boolean writable)

Sets a user-defined writability flag at the specified index.

private void
private void
setWritable(boolean invokeLater)

public int
size()

Returns the number of flushed messages in this ChannelOutboundBuffer.

private static long
public long
private static int
writabilityMask(int index)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

channelback to summary
private final Channel channel
CHANNEL_OUTBOUND_BUFFER_ENTRY_OVERHEADback to summary
pack-priv static final int CHANNEL_OUTBOUND_BUFFER_ENTRY_OVERHEAD
fireChannelWritabilityChangedTaskback to summary
private volatile Runnable fireChannelWritabilityChangedTask
flushedback to summary
private int flushed
flushedEntryback to summary
private ChannelOutboundBuffer.Entry flushedEntry
inFailback to summary
private boolean inFail
loggerback to summary
private static final InternalLogger logger
NIO_BUFFERSback to summary
private static final FastThreadLocal<ByteBuffer[]> NIO_BUFFERS
nioBufferCountback to summary
private int nioBufferCount
nioBufferSizeback to summary
private long nioBufferSize
tailEntryback to summary
private ChannelOutboundBuffer.Entry tailEntry
TOTAL_PENDING_SIZE_UPDATERback to summary
private static final AtomicLongFieldUpdater<ChannelOutboundBuffer> TOTAL_PENDING_SIZE_UPDATER
totalPendingSizeback to summary
private volatile long totalPendingSize
Annotations
@SuppressWarnings:UnusedDeclaration
unflushedEntryback to summary
private ChannelOutboundBuffer.Entry unflushedEntry
unwritableback to summary
private volatile int unwritable
Annotations
@SuppressWarnings:UnusedDeclaration
UNWRITABLE_UPDATERback to summary
private static final AtomicIntegerFieldUpdater<ChannelOutboundBuffer> UNWRITABLE_UPDATER

Constructor Detail

ChannelOutboundBufferback to summary
pack-priv ChannelOutboundBuffer(AbstractChannel channel)

Method Detail

addFlushback to summary
public void addFlush()

Add a flush to this ChannelOutboundBuffer. This means all previous added messages are marked as flushed and so you will be able to handle them.

addMessageback to summary
public void addMessage(Object msg, int size, ChannelPromise promise)

Add given message to this ChannelOutboundBuffer. The given ChannelPromise will be notified once the message was written.

bytesBeforeUnwritableback to summary
public long bytesBeforeUnwritable()

Get how many bytes can be written until isWritable() returns false. This quantity will always be non-negative. If isWritable() is false then 0.

bytesBeforeWritableback to summary
public long bytesBeforeWritable()

Get how many bytes must be drained from the underlying buffer until isWritable() returns true. This quantity will always be non-negative. If isWritable() is true then 0.

clearNioBuffersback to summary
private void clearNioBuffers()
clearUserDefinedWritabilityback to summary
private void clearUserDefinedWritability(int index)
closeback to summary
pack-priv void close(final Throwable cause, final boolean allowChannelOpen)
closeback to summary
pack-priv void close(ClosedChannelException cause)
currentback to summary
public Object current()

Return the current message to write or null if nothing was flushed before and so is ready to be written.

currentProgressback to summary
public long currentProgress()

Return the current message flush progress.

Returns:long

0 if nothing was flushed before for the current message or there is no current message

decrementPendingOutboundBytesback to summary
pack-priv void decrementPendingOutboundBytes(long size)

Decrement the pending bytes which will be written at some point. This method is thread-safe!

decrementPendingOutboundBytesback to summary
private void decrementPendingOutboundBytes(long size, boolean invokeLater, boolean notifyWritability)
expandNioBufferArrayback to summary
private static ByteBuffer[] expandNioBufferArray(ByteBuffer[] array, int neededSpace, int size)
failFlushedback to summary
pack-priv void failFlushed(Throwable cause, boolean notify)
fireChannelWritabilityChangedback to summary
private void fireChannelWritabilityChanged(boolean invokeLater)
forEachFlushedMessageback to summary
public void forEachFlushedMessage(ChannelOutboundBuffer.MessageProcessor processor) throws Exception

Call MessageProcessor#processMessage(Object) for each flushed message in this ChannelOutboundBuffer until MessageProcessor#processMessage(Object) returns false or there are no more flushed messages to process.

getUserDefinedWritabilityback to summary
public boolean getUserDefinedWritability(int index)

Returns true if and only if the user-defined writability flag at the specified index is set to true.

incrementPendingOutboundBytesback to summary
pack-priv void incrementPendingOutboundBytes(long size)

Increment the pending bytes which will be written at some point. This method is thread-safe!

incrementPendingOutboundBytesback to summary
private void incrementPendingOutboundBytes(long size, boolean invokeLater)
isEmptyback to summary
public boolean isEmpty()

Returns true if there are flushed messages in this ChannelOutboundBuffer or false otherwise.

isFlushedEntryback to summary
private boolean isFlushedEntry(ChannelOutboundBuffer.Entry e)
isWritableback to summary
public 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.

nioBufferCountback to summary
public int nioBufferCount()

Returns the number of ByteBuffer that can be written out of the ByteBuffer array that was obtained via nioBuffers(). This method MUST be called after nioBuffers() was called.

nioBuffersback to summary
public ByteBuffer[] nioBuffers()

Returns an array of direct NIO buffers if the currently pending messages are made of 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.

nioBuffersback to summary
public ByteBuffer[] nioBuffers(int maxCount, long maxBytes)

Returns an array of direct NIO buffers if the currently pending messages are made of 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.

Parameters
maxCount:int

The maximum amount of buffers that will be added to the return value.

maxBytes:long

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 1 ByteBuffer in the return value to ensure write progress is made.

nioBuffersback to summary
private static int nioBuffers(ChannelOutboundBuffer.Entry entry, ByteBuf buf, ByteBuffer[] nioBuffers, int nioBufferCount, int maxCount)
nioBufferSizeback to summary
public long nioBufferSize()

Returns the number of bytes that can be written out of the ByteBuffer array that was obtained via nioBuffers(). This method MUST be called after nioBuffers() was called.

progressback to summary
public void progress(long amount)

Notify the ChannelPromise of the current message about writing progress.

recycleback to summary
public void recycle()

Deprecated

Annotations
@Deprecated
removeback to summary
public boolean remove()

Will remove the current message, mark its 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.

removeback to summary
public boolean remove(Throwable cause)

Will remove the current message, mark its 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.

remove0back to summary
private boolean remove0(Throwable cause, boolean notifyWritability)
removeBytesback to summary
public void removeBytes(long writtenBytes)

Removes the fully written entries and update the reader index of the partially written entry. This operation assumes all messages in this buffer is ByteBuf.

removeEntryback to summary
private void removeEntry(ChannelOutboundBuffer.Entry e)
safeFailback to summary
private static void safeFail(ChannelPromise promise, Throwable cause)
safeSuccessback to summary
private static void safeSuccess(ChannelPromise promise)
setUnwritableback to summary
private void setUnwritable(boolean invokeLater)
setUserDefinedWritabilityback to summary
public void setUserDefinedWritability(int index, boolean writable)

Sets a user-defined writability flag at the specified index.

setUserDefinedWritabilityback to summary
private void setUserDefinedWritability(int index)
setWritableback to summary
private void setWritable(boolean invokeLater)
sizeback to summary
public int size()

Returns the number of flushed messages in this ChannelOutboundBuffer.

totalback to summary
private static long total(Object msg)
totalPendingWriteBytesback to summary
public long totalPendingWriteBytes()
writabilityMaskback to summary
private static int writabilityMask(int index)
io.netty.channel back to summary

pack-priv final Class ChannelOutboundBuffer.Entry

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv ByteBuffer
pack-priv ByteBuffer[]
pack-priv boolean
pack-priv int
private final Recycler.EnhancedHandle<ChannelOutboundBuffer.Entry>
pack-priv Object
pack-priv ChannelOutboundBuffer.Entry
pack-priv int
pack-priv long
pack-priv ChannelPromise
private static final ObjectPool<ChannelOutboundBuffer.Entry>
pack-priv long

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
pack-priv int
pack-priv static ChannelOutboundBuffer.Entry
newInstance(Object msg, int size, long total, ChannelPromise promise)

pack-priv void
pack-priv ChannelOutboundBuffer.Entry
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

bufback to summary
pack-priv ByteBuffer buf
bufsback to summary
pack-priv ByteBuffer[] bufs
cancelledback to summary
pack-priv boolean cancelled
countback to summary
pack-priv int count
handleback to summary
private final Recycler.EnhancedHandle<ChannelOutboundBuffer.Entry> handle
msgback to summary
pack-priv Object msg
nextback to summary
pack-priv ChannelOutboundBuffer.Entry next
pendingSizeback to summary
pack-priv int pendingSize
progressback to summary
pack-priv long progress
promiseback to summary
pack-priv ChannelPromise promise
RECYCLERback to summary
private static final ObjectPool<ChannelOutboundBuffer.Entry> RECYCLER
totalback to summary
pack-priv long total

Constructor Detail

Entryback to summary
private Entry(ObjectPool.Handle<ChannelOutboundBuffer.Entry> handle)

Method Detail

cancelback to summary
pack-priv int cancel()
newInstanceback to summary
pack-priv static ChannelOutboundBuffer.Entry newInstance(Object msg, int size, long total, ChannelPromise promise)
unguardedRecycleback to summary
pack-priv void unguardedRecycle()
unguardedRecycleAndGetNextback to summary
pack-priv ChannelOutboundBuffer.Entry unguardedRecycleAndGetNext()
io.netty.channel back to summary

public Interface ChannelOutboundBuffer.MessageProcessor


Method Summary

Modifier and TypeMethod and Description
public boolean
processMessage(Object msg)

Will be called for each flushed message until it either there are no more flushed messages or this method returns false.

Method Detail

processMessageback to summary
public boolean processMessage(Object msg) throws Exception

Will be called for each flushed message until it either there are no more flushed messages or this method returns false.