Top Fields Constructors Methods
io.netty.channel

public abstract Class AbstractCoalescingBufferQueue

extends Object
Class Inheritance
Known Direct Subclasses
io.netty.channel.CoalescingBufferQueue
Annotations
@UnstableApi
Imports
io.netty.buffer.ByteBuf, .ByteBufAllocator, .CompositeByteBuf, io.netty.util.internal.UnstableApi, io.netty.util.internal.logging.InternalLogger, .InternalLoggerFactory, java.util.ArrayDeque

Field Summary

Modifier and TypeField and Description
private final ArrayDeque<Object>
private static final InternalLogger
private int
private final PendingBytesTracker

Constructor Summary

AccessConstructor and Description
protected
AbstractCoalescingBufferQueue(Channel
the Channel which will have the Channel#isWritable() reflect the amount of queued buffers or null if there is no writability state updated.
channel
,
int
the initial size of the underlying queue.
initSize
)

Create a new instance.

Method Summary

Modifier and TypeMethod and Description
public final void
add(ByteBuf buf)

Add a buffer to the end of the queue.

public final void
add(ByteBuf
to add to the tail of the queue
buf
,
ChannelPromise
to complete when all the bytes have been consumed and written, can be void.
promise
)

Add a buffer to the end of the queue and associate a promise with it that should be completed when all the buffer's bytes have been consumed from the queue and written.

public final void
add(ByteBuf
to add to the tail of the queue
buf
,
ChannelFutureListener
to notify when all the bytes have been consumed and written, can be null.
listener
)

Add a buffer to the end of the queue and associate a listener with it that should be completed when all the buffers bytes have been consumed from the queue and written.

public final void
addFirst(ByteBuf
to add to the head of the queue
buf
,
ChannelPromise
to complete when all the bytes have been consumed and written, can be void.
promise
)

Add a buffer to the front of the queue and associate a promise with it that should be completed when all the buffer's bytes have been consumed from the queue and written.

private void
protected abstract ByteBuf
compose(ByteBufAllocator alloc, ByteBuf cumulation, ByteBuf next)

Calculate the result of current + next.

protected ByteBuf
composeFirst(ByteBufAllocator allocator, ByteBuf first)

Calculate the first ByteBuf which will be used in subsequent calls to compose(ByteBufAllocator, ByteBuf, ByteBuf).

protected final ByteBuf
composeIntoComposite(ByteBufAllocator alloc, ByteBuf cumulation, ByteBuf next)

Compose cumulation and next into a new CompositeByteBuf.

protected final ByteBuf

Returns:

The result of cumulation + next.
copyAndCompose
(ByteBufAllocator
The allocator to use to allocate the new buffer.
alloc
,
ByteBuf
The current cumulation.
cumulation
,
ByteBuf
The next buffer.
next
)

Compose cumulation and next into a new ByteBufAllocator#ioBuffer().

public final void
copyTo(AbstractCoalescingBufferQueue
to copy pending buffers to.
dest
)

Copy all pending entries in this queue into the destination queue.

private void
decrementReadableBytes(int decrement)

private void
incrementReadableBytes(int increment)

public final boolean
isEmpty()

Are there pending buffers in the queue.

public final int
readableBytes()

The number of readable bytes.

private void
public final void
releaseAndFailAll(ChannelOutboundInvoker invoker, Throwable cause)

Release all buffers in the queue and complete all listeners and promises.

public final ByteBuf

Returns:

a ByteBuf composed of the enqueued buffers.
remove
(ByteBufAllocator
The allocator used if a new ByteBuf is generated during the aggregation process.
alloc
,
int
the maximum number of readable bytes in the returned ByteBuf, if bytes is greater than readableBytes then a buffer of length readableBytes is returned.
bytes
,
ChannelPromise
used to aggregate the promises and listeners for the constituent buffers.
aggregatePromise
)

Remove a ByteBuf from the queue with the specified number of bytes.

protected abstract ByteBuf

Returns:

the ByteBuf which represents an empty queue.
removeEmptyValue
()

The value to return when remove(ByteBufAllocator, int, ChannelPromise) is called but the queue is empty.

public final ByteBuf

Returns:

the first ByteBuf from the queue.
removeFirst
(ChannelPromise
used to aggregate the promises and listeners for the returned buffer.
aggregatePromise
)

Remove the first ByteBuf from the queue.

protected final int

Returns:

the number of elements in this queue.
size
()

Get the number of elements in this queue added via one of the add(ByteBuf) methods.

private static ChannelFutureListener
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
public final void
writeAndRemoveAll(ChannelHandlerContext
The context to write all elements to.
ctx
)

Writes all remaining elements in this queue.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

bufAndListenerPairsback to summary
private final ArrayDeque<Object> bufAndListenerPairs
loggerback to summary
private static final InternalLogger logger
readableBytesback to summary
private int readableBytes
trackerback to summary
private final PendingBytesTracker tracker

Constructor Detail

AbstractCoalescingBufferQueueback to summary
protected AbstractCoalescingBufferQueue(Channel channel, int initSize)

Create a new instance.

Parameters
channel:Channel

the Channel which will have the Channel#isWritable() reflect the amount of queued buffers or null if there is no writability state updated.

initSize:int

the initial size of the underlying queue.

Method Detail

addback to summary
public final void add(ByteBuf buf)

Add a buffer to the end of the queue.

addback to summary
public final void add(ByteBuf buf, ChannelPromise promise)

Add a buffer to the end of the queue and associate a promise with it that should be completed when all the buffer's bytes have been consumed from the queue and written.

Parameters
buf:ByteBuf

to add to the tail of the queue

promise:ChannelPromise

to complete when all the bytes have been consumed and written, can be void.

addback to summary
public final void add(ByteBuf buf, ChannelFutureListener listener)

Add a buffer to the end of the queue and associate a listener with it that should be completed when all the buffers bytes have been consumed from the queue and written.

Parameters
buf:ByteBuf

to add to the tail of the queue

listener:ChannelFutureListener

to notify when all the bytes have been consumed and written, can be null.

addFirstback to summary
public final void addFirst(ByteBuf buf, ChannelPromise promise)

Add a buffer to the front of the queue and associate a promise with it that should be completed when all the buffer's bytes have been consumed from the queue and written.

Parameters
buf:ByteBuf

to add to the head of the queue

promise:ChannelPromise

to complete when all the bytes have been consumed and written, can be void.

addFirstback to summary
private void addFirst(ByteBuf buf, ChannelFutureListener listener)
composeback to summary
protected abstract ByteBuf compose(ByteBufAllocator alloc, ByteBuf cumulation, ByteBuf next)

Calculate the result of current + next.

composeFirstback to summary
protected ByteBuf composeFirst(ByteBufAllocator allocator, ByteBuf first)

Calculate the first ByteBuf which will be used in subsequent calls to compose(ByteBufAllocator, ByteBuf, ByteBuf).

composeIntoCompositeback to summary
protected final ByteBuf composeIntoComposite(ByteBufAllocator alloc, ByteBuf cumulation, ByteBuf next)

Compose cumulation and next into a new CompositeByteBuf.

copyAndComposeback to summary
protected final ByteBuf copyAndCompose(ByteBufAllocator alloc, ByteBuf cumulation, ByteBuf next)

Compose cumulation and next into a new ByteBufAllocator#ioBuffer().

Parameters
alloc:ByteBufAllocator

The allocator to use to allocate the new buffer.

cumulation:ByteBuf

The current cumulation.

next:ByteBuf

The next buffer.

Returns:ByteBuf

The result of cumulation + next.

copyToback to summary
public final void copyTo(AbstractCoalescingBufferQueue dest)

Copy all pending entries in this queue into the destination queue.

Parameters
dest:AbstractCoalescingBufferQueue

to copy pending buffers to.

decrementReadableBytesback to summary
private void decrementReadableBytes(int decrement)
incrementReadableBytesback to summary
private void incrementReadableBytes(int increment)
isEmptyback to summary
public final boolean isEmpty()

Are there pending buffers in the queue.

readableBytesback to summary
public final int readableBytes()

The number of readable bytes.

releaseAndCompleteAllback to summary
private void releaseAndCompleteAll(ChannelFuture future)
releaseAndFailAllback to summary
public final void releaseAndFailAll(ChannelOutboundInvoker invoker, Throwable cause)

Release all buffers in the queue and complete all listeners and promises.

removeback to summary
public final ByteBuf remove(ByteBufAllocator alloc, int bytes, ChannelPromise aggregatePromise)

Remove a ByteBuf from the queue with the specified number of bytes. Any added buffer who's bytes are fully consumed during removal will have it's promise completed when the passed aggregate ChannelPromise completes.

Parameters
alloc:ByteBufAllocator

The allocator used if a new ByteBuf is generated during the aggregation process.

bytes:int

the maximum number of readable bytes in the returned ByteBuf, if bytes is greater than readableBytes then a buffer of length readableBytes is returned.

aggregatePromise:ChannelPromise

used to aggregate the promises and listeners for the constituent buffers.

Returns:ByteBuf

a ByteBuf composed of the enqueued buffers.

removeEmptyValueback to summary
protected abstract ByteBuf removeEmptyValue()

The value to return when remove(ByteBufAllocator, int, ChannelPromise) is called but the queue is empty.

Returns:ByteBuf

the ByteBuf which represents an empty queue.

removeFirstback to summary
public final ByteBuf removeFirst(ChannelPromise aggregatePromise)

Remove the first ByteBuf from the queue.

Parameters
aggregatePromise:ChannelPromise

used to aggregate the promises and listeners for the returned buffer.

Returns:ByteBuf

the first ByteBuf from the queue.

sizeback to summary
protected final int size()

Get the number of elements in this queue added via one of the add(ByteBuf) methods.

Returns:int

the number of elements in this queue.

toChannelFutureListenerback to summary
private static ChannelFutureListener toChannelFutureListener(ChannelPromise promise)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object

Annotations
@Override
writeAndRemoveAllback to summary
public final void writeAndRemoveAll(ChannelHandlerContext ctx)

Writes all remaining elements in this queue.

Parameters
ctx:ChannelHandlerContext

The context to write all elements to.