Class ArrayByteBufferPool
java.lang.Object
org.eclipse.jetty.io.ArrayByteBufferPool
- All Implemented Interfaces:
ByteBufferPool, Dumpable
- Direct Known Subclasses:
ArrayByteBufferPool.Quadratic, ArrayByteBufferPool.Tracking, ArrayByteBufferPool.WithBucketCapacities
A RetainableByteBuffer pool where RetainableByteBuffers are held in Pools that are
held in array elements.
Given a capacity factor of 1024, the first array element holds a Pool of RetainableByteBuffers
each of capacity 1024, the second array element holds a Pool of RetainableByteBuffers each of capacity
2048, and so on with capacities 3072, 4096, 5120, etc.
The maxHeapMemory and maxDirectMemory default heuristic is to use Runtime.maxMemory()
divided by 8.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classA variant of theArrayByteBufferPoolthat uses buckets of buffers that increase in size by a power of 2 (e.g. 1k, 2k, 4k, 8k, etc.).static classA variant ofArrayByteBufferPoolthat tracks buffer acquires/releases, useful to identify buffer leaks.static classA variant of theArrayByteBufferPoolthat uses a predefined set of buckets of buffers.Nested classes/interfaces inherited from interface ByteBufferPool
ByteBufferPool.Accumulator, ByteBufferPool.NonPooling, ByteBufferPool.Sized, ByteBufferPool.WrapperNested classes/interfaces inherited from interface Dumpable
Dumpable.DumpableContainer, Dumpable.DumpAppendable -
Field Summary
Fields inherited from interface ByteBufferPool
NON_POOLING, SIZED_NON_POOLING -
Constructor Summary
ConstructorsModifierConstructorDescriptionCreates 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 maxBucketSize) Creates a new ArrayByteBufferPool with the given configuration.ArrayByteBufferPool(int minCapacity, int factor, int maxCapacity, int maxBucketSize, long maxHeapMemory, long maxDirectMemory) Creates a new ArrayByteBufferPool with the given configuration.protectedArrayByteBufferPool(int minCapacity, int factor, int maxCapacity, int maxBucketSize, long maxHeapMemory, long maxDirectMemory, IntUnaryOperator bucketIndexFor, IntUnaryOperator bucketCapacityFor) Creates a new ArrayByteBufferPool with the given configuration. -
Method Summary
Modifier and TypeMethodDescriptionacquire(int size, boolean direct) Acquires aRetainableByteBufferfrom this pool.voidclear()Removes allnon-retainedpooled instances from this pool.voiddump(Appendable out, String indent) Dump this object (and children) into an Appendable using the provided indent after any new lines.longlonglonglonglonglonglonglongintintlongbooleanpoolFor(int capacity, boolean direct) voidsetStatisticsEnabled(boolean enabled) toString()
-
Constructor Details
-
ArrayByteBufferPool
public ArrayByteBufferPool()Creates a new ArrayByteBufferPool with a default configuration. BothmaxHeapMemoryandmaxDirectMemorydefault to 0 to use default heuristic. -
ArrayByteBufferPool
public ArrayByteBufferPool(int minCapacity, int factor, int maxCapacity) Creates a new ArrayByteBufferPool with the given configuration. BothmaxHeapMemoryandmaxDirectMemorydefault to 0 to use default heuristic.- Parameters:
minCapacity- the minimum ByteBuffer capacityfactor- the capacity factormaxCapacity- the maximum ByteBuffer capacity
-
ArrayByteBufferPool
public ArrayByteBufferPool(int minCapacity, int factor, int maxCapacity, int maxBucketSize) Creates a new ArrayByteBufferPool with the given configuration. BothmaxHeapMemoryandmaxDirectMemorydefault to 0 to use default heuristic.- Parameters:
minCapacity- the minimum ByteBuffer capacityfactor- the capacity factormaxCapacity- the maximum ByteBuffer capacitymaxBucketSize- the maximum number of ByteBuffers for each bucket
-
ArrayByteBufferPool
public ArrayByteBufferPool(int minCapacity, int factor, int maxCapacity, int maxBucketSize, long maxHeapMemory, long maxDirectMemory) Creates a new ArrayByteBufferPool with the given configuration.- Parameters:
minCapacity- the minimum ByteBuffer capacityfactor- the capacity factormaxCapacity- the maximum ByteBuffer capacitymaxBucketSize- the maximum number of ByteBuffers for each bucketmaxHeapMemory- the max heap memory in bytes, -1 for unlimited memory or 0 to use default heuristicmaxDirectMemory- the max direct memory in bytes, -1 for unlimited memory or 0 to use default heuristic
-
ArrayByteBufferPool
protected ArrayByteBufferPool(int minCapacity, int factor, int maxCapacity, int maxBucketSize, long maxHeapMemory, long maxDirectMemory, IntUnaryOperator bucketIndexFor, IntUnaryOperator bucketCapacityFor) Creates a new ArrayByteBufferPool with the given configuration.- Parameters:
minCapacity- the minimum ByteBuffer capacityfactor- the capacity factormaxCapacity- the maximum ByteBuffer capacitymaxBucketSize- the maximum number of ByteBuffers for each bucketmaxHeapMemory- the max heap memory in bytes, -1 for unlimited memory or 0 to use default heuristicmaxDirectMemory- the max direct memory in bytes, -1 for unlimited memory or 0 to use default heuristicbucketIndexFor- aIntUnaryOperatorthat takes a capacity and returns a bucket indexbucketCapacityFor- aIntUnaryOperatorthat takes a bucket index and returns a capacity
-
-
Method Details
-
getReserved
@ManagedAttribute("The current number of allocated bytes reserved to be added to the pool once released") public long getReserved() -
isStatisticsEnabled
-
setStatisticsEnabled
public void setStatisticsEnabled(boolean enabled) -
getMinCapacity
-
getMaxCapacity
-
acquire
Description copied from interface:ByteBufferPoolAcquires a
RetainableByteBufferfrom this pool.- Specified by:
acquirein interfaceByteBufferPool- Parameters:
size- The size of the buffer. The returned buffer will have at least this capacity.direct- true if a direct memory buffer is needed, false otherwise.- Returns:
- a
RetainableByteBufferwith position and limit set to 0.
-
poolFor
-
getDirectByteBufferCount
-
getHeapByteBufferCount
-
getAvailableDirectByteBufferCount
@ManagedAttribute("The number of pooled direct ByteBuffers that are available") public long getAvailableDirectByteBufferCount() -
getAvailableHeapByteBufferCount
@ManagedAttribute("The number of pooled heap ByteBuffers that are available") public long getAvailableHeapByteBufferCount() -
getDirectMemory
-
getHeapMemory
-
getAvailableDirectMemory
@ManagedAttribute("The available bytes retained by direct ByteBuffers") public long getAvailableDirectMemory() -
getAvailableHeapMemory
@ManagedAttribute("The available bytes retained by heap ByteBuffers") public long getAvailableHeapMemory() -
getHeapBucketsStatistics
@ManagedAttribute("The heap buckets statistics") public List<Map<String,Object>> getHeapBucketsStatistics() -
getDirectBucketsStatistics
@ManagedAttribute("The direct buckets statistics") public List<Map<String,Object>> getDirectBucketsStatistics() -
getNoBucketDirectAcquires
@ManagedAttribute("The acquires for direct non-pooled bucket capacities") public Map<Integer,Long> getNoBucketDirectAcquires() -
getNoBucketHeapAcquires
@ManagedAttribute("The acquires for heap non-pooled bucket capacities") public Map<Integer,Long> getNoBucketHeapAcquires() -
clear
Description copied from interface:ByteBufferPoolRemoves all
non-retainedpooled instances from this pool.- Specified by:
clearin interfaceByteBufferPool
-
dump
Description copied from interface:DumpableDump this object (and children) into an Appendable using the provided indent after any new lines. The indent should not be applied to the first object dumped.- Specified by:
dumpin interfaceDumpable- Parameters:
out- The appendable to dump toindent- The indent to apply after any new lines.- Throws:
IOException- if unable to write to Appendable
-
toString
-