@ManagedObject public class MappedByteBufferPool extends AbstractByteBufferPool
A ByteBuffer pool where ByteBuffers are held in queues that are held in a Map.
Given a capacity factor
of 1024, the Map entry with key 1
holds a
queue of ByteBuffers each of capacity 1024, the Map entry with key 2
holds a
queue of ByteBuffers each of capacity 2048, and so on.
Modifier and Type | Class and Description |
---|---|
static class |
MappedByteBufferPool.Tagged |
ByteBufferPool.Bucket, ByteBufferPool.Lease
Modifier and Type | Field and Description |
---|---|
private java.util.concurrent.ConcurrentMap<java.lang.Integer,ByteBufferPool.Bucket> |
_directBuffers |
private java.util.concurrent.ConcurrentMap<java.lang.Integer,ByteBufferPool.Bucket> |
_heapBuffers |
private java.util.function.Function<java.lang.Integer,ByteBufferPool.Bucket> |
_newBucket |
Constructor and Description |
---|
MappedByteBufferPool()
Creates a new MappedByteBufferPool with a default configuration.
|
MappedByteBufferPool(int factor)
Creates a new MappedByteBufferPool with the given capacity factor.
|
MappedByteBufferPool(int factor,
int maxQueueLength)
Creates a new MappedByteBufferPool with the given configuration.
|
MappedByteBufferPool(int factor,
int maxQueueLength,
java.util.function.Function<java.lang.Integer,ByteBufferPool.Bucket> newBucket)
Creates a new MappedByteBufferPool with the given configuration.
|
MappedByteBufferPool(int factor,
int maxQueueLength,
java.util.function.Function<java.lang.Integer,ByteBufferPool.Bucket> newBucket,
long maxHeapMemory,
long maxDirectMemory)
Creates a new MappedByteBufferPool 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 size) |
(package private) java.util.concurrent.ConcurrentMap<java.lang.Integer,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, releaseExcessMemory
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
newByteBuffer
private final java.util.concurrent.ConcurrentMap<java.lang.Integer,ByteBufferPool.Bucket> _directBuffers
private final java.util.concurrent.ConcurrentMap<java.lang.Integer,ByteBufferPool.Bucket> _heapBuffers
private final java.util.function.Function<java.lang.Integer,ByteBufferPool.Bucket> _newBucket
public MappedByteBufferPool()
public MappedByteBufferPool(int factor)
factor
- the capacity factorpublic MappedByteBufferPool(int factor, int maxQueueLength)
factor
- the capacity factormaxQueueLength
- the maximum ByteBuffer queue lengthpublic MappedByteBufferPool(int factor, int maxQueueLength, java.util.function.Function<java.lang.Integer,ByteBufferPool.Bucket> newBucket)
factor
- the capacity factormaxQueueLength
- the maximum ByteBuffer queue lengthnewBucket
- the function that creates a Bucketpublic MappedByteBufferPool(int factor, int maxQueueLength, java.util.function.Function<java.lang.Integer,ByteBufferPool.Bucket> newBucket, long maxHeapMemory, long maxDirectMemory)
factor
- the capacity factormaxQueueLength
- the maximum ByteBuffer queue lengthnewBucket
- the function that creates a BucketmaxHeapMemory
- the max heap memory in bytesmaxDirectMemory
- the max direct memory in bytesprivate ByteBufferPool.Bucket newBucket(int key)
public java.nio.ByteBuffer acquire(int size, boolean direct)
ByteBufferPool
Requests 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)
ByteBufferPool
Returns 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()
clear
in class AbstractByteBufferPool
private void clearOldestBucket(boolean direct)
private int bucketFor(int size)
@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)
java.util.concurrent.ConcurrentMap<java.lang.Integer,ByteBufferPool.Bucket> bucketsFor(boolean direct)