A pool for RetainableByteBuffer instances.
RetainableByteBuffer that are acquired
must be released by calling RetainableByteBuffer#release()
otherwise the memory they hold will be leaked.
API NOTE
This interface does not have a symmetric release(RetainableByteBuffer)
method, because it will be confusing to use due to the fact that the acquired instance
is-a Retainable.
Imagine this (hypothetical) code sequence:
RetainableByteBuffer buffer = pool.acquire(size, direct);
buffer.retain();
pool.release(buffer);
The hypothetical call to release(RetainableByteBuffer) would appear to
release the buffer to the pool, but in fact the buffer is retained one more time
(and therefore still in use) and not really released to the pool.
For this reason there is no release(RetainableByteBuffer) method.
Therefore, in order to track acquire/release counts both the pool and the
buffer returned by acquire(int, boolean) must be wrapped, see
RetainableByteBuffer.
| Modifier and Type | Class and Description |
|---|---|
| public static class | ByteBufferPool.
Accumulates a sequence of |
| public static class | ByteBufferPool.
A |
| public static class | ByteBufferPool.
A wrapper for |
| Modifier and Type | Method and Description |
|---|---|
| public RetainableByteBuffer | Returns: aRetainableByteBuffer with position and limit set to 0.The size of the buffer. The returned buffer will have at least this capacity. size, boolean true if a direct memory buffer is needed, false otherwise. direct)Acquires a |
| public void |
| acquire | back to summary |
|---|---|
| public RetainableByteBuffer acquire(int size, boolean direct) Acquires a
| |
| clear | back to summary |
|---|---|
| public void clear() Removes all | |
Accumulates a sequence of RetainableByteBuffer that
are typically created during the generation of protocol bytes.
RetainableByteBuffers can be either
appended to the sequence,
or inserted at a
specific position in the sequence, and then
released when they are consumed.
| Modifier and Type | Field and Description |
|---|---|
| private final List | |
| private final List |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | |
| public List | |
| public int | |
| public long | |
| public void | |
| public void |
| buffers | back to summary |
|---|---|
| private final List<RetainableByteBuffer> buffers | |
| byteBuffers | back to summary |
|---|---|
| private final List<ByteBuffer> byteBuffers | |
| Accumulator | back to summary |
|---|---|
| public Accumulator() | |
| append | back to summary |
|---|---|
| public void append(RetainableByteBuffer buffer) | |
| getByteBuffers | back to summary |
|---|---|
| public List | |
| getSize | back to summary |
|---|---|
| public int getSize() | |
| getTotalLength | back to summary |
|---|---|
| public long getTotalLength() | |
| insert | back to summary |
|---|---|
| public void insert(int index, RetainableByteBuffer buffer) | |
| release | back to summary |
|---|---|
| public void release() | |
A ByteBufferPool that does not pool its
RetainableByteBuffers.
The returned RetainableByteBuffers are reference
counted.
RetainableByteBuffers returned by this class
are suitable to be wrapped in other Retainable
implementations that may delegate calls to
Retainable#retain().
| Modifier and Type | Class and Description |
|---|---|
| private static class |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public RetainableByteBuffer | acquire(int
The size of the buffer. The returned buffer will have at least this capacity. size, boolean true if a direct memory buffer is needed, false otherwise. direct)Implements org. Acquires a |
| public void | clear()
Implements org. Removes all |
| NonPooling | back to summary |
|---|---|
| public NonPooling() | |
| acquire | back to summary |
|---|---|
| public RetainableByteBuffer acquire(int size, boolean direct) Implements org. Doc from org. Acquires a
| |
| clear | back to summary |
|---|---|
| public void clear() Implements org. Doc from org. Removes all
| |
| Access | Constructor and Description |
|---|---|
| private |
| Buffer | back to summary |
|---|---|
| private Buffer(ByteBuffer byteBuffer) | |
A wrapper for ByteBufferPool instances.
| Modifier and Type | Field and Description |
|---|---|
| private final ByteBufferPool |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public RetainableByteBuffer | acquire(int
The size of the buffer. The returned buffer will have at least this capacity. size, boolean true if a direct memory buffer is needed, false otherwise. direct)Implements org. Acquires a |
| public void | clear()
Implements org. Removes all |
| public ByteBufferPool |
| wrapped | back to summary |
|---|---|
| private final ByteBufferPool wrapped | |
| Wrapper | back to summary |
|---|---|
| public Wrapper(ByteBufferPool wrapped) | |
| acquire | back to summary |
|---|---|
| public RetainableByteBuffer acquire(int size, boolean direct) Implements org. Doc from org. Acquires a
| |
| clear | back to summary |
|---|---|
| public void clear() Implements org. Doc from org. Removes all
| |
| getWrapped | back to summary |
|---|---|
| public ByteBufferPool getWrapped() | |