Package org.eclipse.jetty.io
Class ArrayByteBufferPool
- java.lang.Object
-
- org.eclipse.jetty.io.AbstractByteBufferPool
-
- org.eclipse.jetty.io.ArrayByteBufferPool
-
- All Implemented Interfaces:
ByteBufferPool
@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.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.eclipse.jetty.io.ByteBufferPool
ByteBufferPool.Bucket, ByteBufferPool.Lease
-
-
Field Summary
Fields Modifier and Type Field Description private ByteBufferPool.Bucket[]
_direct
private ByteBufferPool.Bucket[]
_indirect
private int
_minCapacity
private static Logger
LOG
-
Constructor Summary
Constructors Constructor 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.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.nio.ByteBuffer
acquire(int size, boolean direct)
Requests aByteBuffer
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 aByteBuffer
, usually obtained withByteBufferPool.acquire(int, boolean)
(but not necessarily), making it available for recycling and reuse.-
Methods inherited from class org.eclipse.jetty.io.AbstractByteBufferPool
decrementMemory, getCapacityFactor, getDirectMemory, getHeapMemory, getMaxQueueLength, getMemory, incrementMemory, releaseExcessMemory
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.eclipse.jetty.io.ByteBufferPool
newByteBuffer, remove
-
-
-
-
Field Detail
-
LOG
private static final Logger LOG
-
_minCapacity
private final int _minCapacity
-
_direct
private final ByteBufferPool.Bucket[] _direct
-
_indirect
private final ByteBufferPool.Bucket[] _indirect
-
-
Constructor Detail
-
ArrayByteBufferPool
public ArrayByteBufferPool()
Creates a new ArrayByteBufferPool with a default configuration.
-
ArrayByteBufferPool
public ArrayByteBufferPool(int minCapacity, int factor, int maxCapacity)
Creates a new ArrayByteBufferPool with the given configuration.- Parameters:
minCapacity
- the minimum ByteBuffer capacityfactor
- the capacity factormaxCapacity
- the maximum ByteBuffer capacity
-
ArrayByteBufferPool
public ArrayByteBufferPool(int minCapacity, int factor, int maxCapacity, int maxQueueLength)
Creates a new ArrayByteBufferPool with the given configuration.- Parameters:
minCapacity
- the minimum ByteBuffer capacityfactor
- the capacity factormaxCapacity
- the maximum ByteBuffer capacitymaxQueueLength
- the maximum ByteBuffer queue length
-
ArrayByteBufferPool
public ArrayByteBufferPool(int minCapacity, int factor, int maxCapacity, int maxQueueLength, long maxHeapMemory, long maxDirectMemory)
Creates a new ArrayByteBufferPool with the given configuration.- Parameters:
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 bytes
-
-
Method Detail
-
acquire
public java.nio.ByteBuffer acquire(int size, boolean direct)
Description copied from interface: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.
- Parameters:
size
- the size of the bufferdirect
- whether the buffer must be direct or not- Returns:
- the requested buffer
- See Also:
ByteBufferPool.release(ByteBuffer)
-
release
public void release(java.nio.ByteBuffer buffer)
Description copied from interface:ByteBufferPool
Returns a
ByteBuffer
, usually obtained withByteBufferPool.acquire(int, boolean)
(but not necessarily), making it available for recycling and reuse.- Parameters:
buffer
- the buffer to return- See Also:
ByteBufferPool.acquire(int, boolean)
-
newBucket
private ByteBufferPool.Bucket newBucket(int key)
-
clear
public void clear()
- Overrides:
clear
in classAbstractByteBufferPool
-
clearOldestBucket
private void clearOldestBucket(boolean direct)
-
bucketFor
private int bucketFor(int capacity)
-
bucketFor
private ByteBufferPool.Bucket bucketFor(int capacity, boolean direct, java.util.function.IntFunction<ByteBufferPool.Bucket> newBucket)
-
getDirectByteBufferCount
@ManagedAttribute("The number of pooled direct ByteBuffers") public long getDirectByteBufferCount()
-
getHeapByteBufferCount
@ManagedAttribute("The number of pooled heap ByteBuffers") public long getHeapByteBufferCount()
-
getByteBufferCount
private long getByteBufferCount(boolean direct)
-
bucketsFor
ByteBufferPool.Bucket[] bucketsFor(boolean direct)
-
-