@ManagedObject public class ArrayByteBufferPool extends AbstractByteBufferPool
A ByteBuffer pool where ByteBuffers are held in queues that are held in array elements.
Given a capacity factor of 1024, the first array element holds a queue of ByteBuffers
each of capacity 1024, the second array element holds a queue of ByteBuffers each of capacity
2048, and so on.
ByteBufferPool.Bucket, ByteBufferPool.Lease| Modifier and Type | Field and Description |
|---|---|
private ByteBufferPool.Bucket[] |
_direct |
private ByteBufferPool.Bucket[] |
_indirect |
private int |
_minCapacity |
| Constructor and Description |
|---|
ArrayByteBufferPool()
Creates a new ArrayByteBufferPool with a default configuration.
|
ArrayByteBufferPool(int minCapacity,
int factor,
int maxCapacity)
Creates a new ArrayByteBufferPool with the given configuration.
|
ArrayByteBufferPool(int minCapacity,
int factor,
int maxCapacity,
int maxQueueLength)
Creates a new ArrayByteBufferPool with the given configuration.
|
ArrayByteBufferPool(int minCapacity,
int factor,
int maxCapacity,
int maxQueueLength,
long maxHeapMemory,
long maxDirectMemory)
Creates a new ArrayByteBufferPool with the given configuration.
|
| Modifier and Type | Method and Description |
|---|---|
java.nio.ByteBuffer |
acquire(int size,
boolean direct)
Requests a
ByteBuffer of the given size. |
private int |
bucketFor(int capacity) |
private ByteBufferPool.Bucket |
bucketFor(int capacity,
boolean direct,
java.util.function.IntFunction<ByteBufferPool.Bucket> newBucket) |
(package private) ByteBufferPool.Bucket[] |
bucketsFor(boolean direct) |
void |
clear() |
private void |
clearOldestBucket(boolean direct) |
private long |
getByteBufferCount(boolean direct) |
long |
getDirectByteBufferCount() |
long |
getHeapByteBufferCount() |
private ByteBufferPool.Bucket |
newBucket(int key) |
void |
release(java.nio.ByteBuffer buffer)
Returns a
ByteBuffer, usually obtained with ByteBufferPool.acquire(int, boolean)
(but not necessarily), making it available for recycling and reuse. |
decrementMemory, getCapacityFactor, getDirectMemory, getHeapMemory, getMaxQueueLength, getMemory, incrementMemory, releaseExcessMemoryclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitnewByteBufferprivate final int _minCapacity
private final ByteBufferPool.Bucket[] _direct
private final ByteBufferPool.Bucket[] _indirect
public ArrayByteBufferPool()
public ArrayByteBufferPool(int minCapacity,
int factor,
int maxCapacity)
minCapacity - the minimum ByteBuffer capacityfactor - the capacity factormaxCapacity - the maximum ByteBuffer capacitypublic ArrayByteBufferPool(int minCapacity,
int factor,
int maxCapacity,
int maxQueueLength)
minCapacity - the minimum ByteBuffer capacityfactor - the capacity factormaxCapacity - the maximum ByteBuffer capacitymaxQueueLength - the maximum ByteBuffer queue lengthpublic ArrayByteBufferPool(int minCapacity,
int factor,
int maxCapacity,
int maxQueueLength,
long maxHeapMemory,
long maxDirectMemory)
minCapacity - the minimum ByteBuffer capacityfactor - the capacity factormaxCapacity - the maximum ByteBuffer capacitymaxQueueLength - the maximum ByteBuffer queue lengthmaxHeapMemory - the max heap memory in bytesmaxDirectMemory - the max direct memory in bytespublic java.nio.ByteBuffer acquire(int size,
boolean direct)
ByteBufferPoolRequests a ByteBuffer of the given size.
The returned buffer may have a bigger capacity than the size being requested but it will have the limit set to the given size.
size - the size of the bufferdirect - whether the buffer must be direct or notByteBufferPool.release(ByteBuffer)public void release(java.nio.ByteBuffer buffer)
ByteBufferPoolReturns a ByteBuffer, usually obtained with ByteBufferPool.acquire(int, boolean)
(but not necessarily), making it available for recycling and reuse.
buffer - the buffer to returnByteBufferPool.acquire(int, boolean)private ByteBufferPool.Bucket newBucket(int key)
public void clear()
clear in class AbstractByteBufferPoolprivate void clearOldestBucket(boolean direct)
private int bucketFor(int capacity)
private ByteBufferPool.Bucket bucketFor(int capacity, boolean direct, java.util.function.IntFunction<ByteBufferPool.Bucket> newBucket)
@ManagedAttribute(value="The number of pooled direct ByteBuffers") public long getDirectByteBufferCount()
@ManagedAttribute(value="The number of pooled heap ByteBuffers") public long getHeapByteBufferCount()
private long getByteBufferCount(boolean direct)
ByteBufferPool.Bucket[] bucketsFor(boolean direct)