@ManagedObject public class ArrayByteBufferPool extends java.lang.Object
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| 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. |
void |
clear() |
protected void |
decrementMemory(java.nio.ByteBuffer buffer) |
protected int |
getCapacityFactor() |
long |
getDirectByteBufferCount() |
long |
getDirectMemory() |
long |
getHeapByteBufferCount() |
long |
getHeapMemory() |
protected int |
getMaxQueueLength() |
long |
getMemory(boolean direct) |
protected void |
incrementMemory(java.nio.ByteBuffer buffer) |
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. |
protected void |
releaseExcessMemory(boolean direct,
java.util.function.Consumer<java.lang.Boolean> clearFn) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitnewByteBufferpublic 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)public void clear()
@ManagedAttribute(value="The number of pooled direct ByteBuffers") public long getDirectByteBufferCount()
@ManagedAttribute(value="The number of pooled heap ByteBuffers") public long getHeapByteBufferCount()
protected int getCapacityFactor()
protected int getMaxQueueLength()
protected void decrementMemory(java.nio.ByteBuffer buffer)
protected void incrementMemory(java.nio.ByteBuffer buffer)
protected void releaseExcessMemory(boolean direct,
java.util.function.Consumer<java.lang.Boolean> clearFn)
@ManagedAttribute(value="The bytes retained by direct ByteBuffers") public long getDirectMemory()
@ManagedAttribute(value="The bytes retained by heap ByteBuffers") public long getHeapMemory()
public long getMemory(boolean direct)
Copyright © 1995–2022 Webtide. All rights reserved.