Interface ByteBufferPool
- All Known Implementing Classes:
ArrayByteBufferPool
,ArrayByteBufferPool.Quadratic
,ArrayByteBufferPool.Tracking
,ByteBufferPool.NonPooling
,ByteBufferPool.Sized
,ByteBufferPool.Wrapper
A pool for RetainableByteBuffer
instances.
RetainableByteBuffer
that are acquired
must be released by calling Retainable.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.Wrapper
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic class
Accumulates a sequence ofRetainableByteBuffer
that are typically created during the generation of protocol bytes.static class
AByteBufferPool
that does not pool itsRetainableByteBuffer
s.static class
A ByteBufferPool with an additional no-argsByteBufferPool.Sized.acquire()
method to obtain a buffer of a preconfigured specific size and type.static class
A wrapper forByteBufferPool
instances. -
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionacquire
(int size, boolean direct) Acquires aRetainableByteBuffer
from this pool.void
clear()
Removes allnon-retained
pooled instances from this pool.default boolean
removeAndRelease
(RetainableByteBuffer buffer) Deprecated.This API is experimental and may be removed in future releases
-
Field Details
-
NON_POOLING
-
SIZED_NON_POOLING
-
-
Method Details
-
acquire
Acquires a
RetainableByteBuffer
from this pool.- Parameters:
size
- The size of the buffer. The returned buffer will have at least this capacity.direct
- true if a direct memory buffer is needed, false otherwise.- Returns:
- a
RetainableByteBuffer
with position and limit set to 0.
-
removeAndRelease
Deprecated.This API is experimental and may be removed in future releasesRelease
the buffer in a way that will remove it from any pool that it may be in. If the buffer is not in a pool, calling this method is equivalent to callingRetainable.release()
. Calling this method satisfies any contract that requires a call toRetainable.release()
.- Returns:
true
if a call toRetainable.release()
would have returnedtrue
.- See Also:
-
clear
void clear()Removes all
non-retained
pooled instances from this pool.
-