Package org.eclipse.jetty.io
Interface ByteBufferPool
- All Known Implementing Classes:
ArrayByteBufferPool,ArrayByteBufferPool.Tracking,LeakTrackingByteBufferPool,LogarithmicArrayByteBufferPool,MappedByteBufferPool,MappedByteBufferPool.Tagged,NullByteBufferPool
public interface ByteBufferPool
A ByteBuffer pool.
Acquired buffers may be released but they do not need to;
if they are released, they may be recycled and reused, otherwise they will be garbage
collected as usual.
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionacquire(int size, boolean direct) Requests aByteBufferof the given size.Get this pool as aRetainableByteBufferPool, which supports reference counting of the buffers and possibly a more efficient lookup mechanism based on thePoolclass.default ByteBuffernewByteBuffer(int capacity, boolean direct) Creates a new ByteBuffer of the given capacity and the given directness.voidrelease(ByteBuffer buffer) Returns aByteBuffer, usually obtained withacquire(int, boolean)(but not necessarily), making it available for recycling and reuse.default voidremove(ByteBuffer buffer) Removes aByteBufferthat was previously obtained withacquire(int, boolean).
-
Method Details
-
acquire
Requests a
ByteBufferof the given size.The returned buffer may have a bigger capacity than the size being requested.
- Parameters:
size- the size of the bufferdirect- whether the buffer must be direct or not- Returns:
- a buffer with at least the requested capacity, with position and limit set to 0.
- See Also:
-
release
Returns a
ByteBuffer, usually obtained withacquire(int, boolean)(but not necessarily), making it available for recycling and reuse.- Parameters:
buffer- the buffer to return- See Also:
-
remove
Removes a
ByteBufferthat was previously obtained withacquire(int, boolean).The buffer will not be available for further reuse.
- Parameters:
buffer- the buffer to remove- See Also:
-
newByteBuffer
Creates a new ByteBuffer of the given capacity and the given directness.
- Parameters:
capacity- the ByteBuffer capacitydirect- the ByteBuffer directness- Returns:
- a newly allocated ByteBuffer
-
asRetainableByteBufferPool
RetainableByteBufferPool asRetainableByteBufferPool()Get this pool as aRetainableByteBufferPool, which supports reference counting of the buffers and possibly a more efficient lookup mechanism based on thePoolclass.- Returns:
- This pool as a RetainableByteBufferPool. The same instance is always returned by multiple calls to this method.
-