Package io.netty.channel
Class AbstractCoalescingBufferQueue10294
- java.lang.Object
-
- io.netty.channel.AbstractCoalescingBufferQueue10294
-
@UnstableApi public abstract class AbstractCoalescingBufferQueue10294 extends java.lang.Object
Forked from Netty's AbstractCoalescingBufferQueue (4.1.42) Includes fix to guard readableBytes from re-entry. https://github.com/netty/netty/pull/10294
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractCoalescingBufferQueue10294(io.netty.channel.Channel channel, int initSize)
Create a new instance.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
add(io.netty.buffer.ByteBuf buf)
Add a buffer to the end of the queue.void
add(io.netty.buffer.ByteBuf buf, io.netty.channel.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.void
add(io.netty.buffer.ByteBuf buf, io.netty.channel.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.void
addFirst(io.netty.buffer.ByteBuf buf, io.netty.channel.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.protected abstract io.netty.buffer.ByteBuf
compose(io.netty.buffer.ByteBufAllocator alloc, io.netty.buffer.ByteBuf cumulation, io.netty.buffer.ByteBuf next)
Calculate the result ofcurrent + next
.protected io.netty.buffer.ByteBuf
composeFirst(io.netty.buffer.ByteBufAllocator allocator, io.netty.buffer.ByteBuf first)
Calculate the firstByteBuf
which will be used in subsequent calls tocompose(ByteBufAllocator, ByteBuf, ByteBuf)
.protected io.netty.buffer.ByteBuf
composeIntoComposite(io.netty.buffer.ByteBufAllocator alloc, io.netty.buffer.ByteBuf cumulation, io.netty.buffer.ByteBuf next)
Composecumulation
andnext
into a newCompositeByteBuf
.protected io.netty.buffer.ByteBuf
copyAndCompose(io.netty.buffer.ByteBufAllocator alloc, io.netty.buffer.ByteBuf cumulation, io.netty.buffer.ByteBuf next)
Composecumulation
andnext
into a newByteBufAllocator.ioBuffer()
.void
copyTo(AbstractCoalescingBufferQueue10294 dest)
Copy all pending entries in this queue into the destination queue.boolean
isEmpty()
Are there pending buffers in the queue.int
readableBytes()
The number of readable bytes.void
releaseAndFailAll(io.netty.channel.ChannelOutboundInvoker invoker, java.lang.Throwable cause)
Release all buffers in the queue and complete all listeners and promises.io.netty.buffer.ByteBuf
remove(io.netty.buffer.ByteBufAllocator alloc, int bytes, io.netty.channel.ChannelPromise aggregatePromise)
Remove aByteBuf
from the queue with the specified number of bytes.protected abstract io.netty.buffer.ByteBuf
removeEmptyValue()
The value to return whenremove(ByteBufAllocator, int, ChannelPromise)
is called but the queue is empty.io.netty.buffer.ByteBuf
removeFirst(io.netty.channel.ChannelPromise aggregatePromise)
Remove the firstByteBuf
from the queue.protected int
size()
Get the number of elements in this queue added via one of theadd(ByteBuf)
methods.void
writeAndRemoveAll(io.netty.channel.ChannelHandlerContext ctx)
Writes all remaining elements in this queue.
-
-
-
Constructor Detail
-
AbstractCoalescingBufferQueue10294
protected AbstractCoalescingBufferQueue10294(io.netty.channel.Channel channel, int initSize)
Create a new instance.- Parameters:
channel
- theChannel
which will have theChannel.isWritable()
reflect the amount of queued buffers ornull
if there is no writability state updated.initSize
- the initial size of the underlying queue.
-
-
Method Detail
-
addFirst
public final void addFirst(io.netty.buffer.ByteBuf buf, io.netty.channel.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
- to add to the head of the queuepromise
- to complete when all the bytes have been consumed and written, can be void.
-
add
public final void add(io.netty.buffer.ByteBuf buf)
Add a buffer to the end of the queue.
-
add
public final void add(io.netty.buffer.ByteBuf buf, io.netty.channel.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
- to add to the tail of the queuepromise
- to complete when all the bytes have been consumed and written, can be void.
-
add
public final void add(io.netty.buffer.ByteBuf buf, io.netty.channel.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
- to add to the tail of the queuelistener
- to notify when all the bytes have been consumed and written, can benull
.
-
removeFirst
public final io.netty.buffer.ByteBuf removeFirst(io.netty.channel.ChannelPromise aggregatePromise)
Remove the firstByteBuf
from the queue.- Parameters:
aggregatePromise
- used to aggregate the promises and listeners for the returned buffer.- Returns:
- the first
ByteBuf
from the queue.
-
remove
public final io.netty.buffer.ByteBuf remove(io.netty.buffer.ByteBufAllocator alloc, int bytes, io.netty.channel.ChannelPromise aggregatePromise)
Remove aByteBuf
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 aggregateChannelPromise
completes.- Parameters:
alloc
- The allocator used if a newByteBuf
is generated during the aggregation process.bytes
- the maximum number of readable bytes in the returnedByteBuf
, ifbytes
is greater thanreadableBytes
then a buffer of lengthreadableBytes
is returned.aggregatePromise
- used to aggregate the promises and listeners for the constituent buffers.- Returns:
- a
ByteBuf
composed of the enqueued buffers.
-
readableBytes
public final int readableBytes()
The number of readable bytes.
-
isEmpty
public final boolean isEmpty()
Are there pending buffers in the queue.
-
releaseAndFailAll
public final void releaseAndFailAll(io.netty.channel.ChannelOutboundInvoker invoker, java.lang.Throwable cause)
Release all buffers in the queue and complete all listeners and promises.
-
copyTo
public final void copyTo(AbstractCoalescingBufferQueue10294 dest)
Copy all pending entries in this queue into the destination queue.- Parameters:
dest
- to copy pending buffers to.
-
writeAndRemoveAll
public final void writeAndRemoveAll(io.netty.channel.ChannelHandlerContext ctx)
Writes all remaining elements in this queue.- Parameters:
ctx
- The context to write all elements to.
-
compose
protected abstract io.netty.buffer.ByteBuf compose(io.netty.buffer.ByteBufAllocator alloc, io.netty.buffer.ByteBuf cumulation, io.netty.buffer.ByteBuf next)
Calculate the result ofcurrent + next
.
-
composeIntoComposite
protected final io.netty.buffer.ByteBuf composeIntoComposite(io.netty.buffer.ByteBufAllocator alloc, io.netty.buffer.ByteBuf cumulation, io.netty.buffer.ByteBuf next)
Composecumulation
andnext
into a newCompositeByteBuf
.
-
copyAndCompose
protected final io.netty.buffer.ByteBuf copyAndCompose(io.netty.buffer.ByteBufAllocator alloc, io.netty.buffer.ByteBuf cumulation, io.netty.buffer.ByteBuf next)
Composecumulation
andnext
into a newByteBufAllocator.ioBuffer()
.- Parameters:
alloc
- The allocator to use to allocate the new buffer.cumulation
- The current cumulation.next
- The next buffer.- Returns:
- The result of
cumulation + next
.
-
composeFirst
protected io.netty.buffer.ByteBuf composeFirst(io.netty.buffer.ByteBufAllocator allocator, io.netty.buffer.ByteBuf first)
Calculate the firstByteBuf
which will be used in subsequent calls tocompose(ByteBufAllocator, ByteBuf, ByteBuf)
.
-
removeEmptyValue
protected abstract io.netty.buffer.ByteBuf removeEmptyValue()
The value to return whenremove(ByteBufAllocator, int, ChannelPromise)
is called but the queue is empty.- Returns:
- the
ByteBuf
which represents an empty queue.
-
size
protected final int size()
Get the number of elements in this queue added via one of theadd(ByteBuf)
methods.- Returns:
- the number of elements in this queue.
-
-