java.lang.Object
org.eclipse.jetty.io.ArrayByteBufferPool
- All Implemented Interfaces:
ByteBufferPool,org.eclipse.jetty.util.component.Dumpable
- Direct Known Subclasses:
ArrayByteBufferPool.Quadratic,ArrayByteBufferPool.Tracking
@ManagedObject
public class ArrayByteBufferPool
extends Object
implements ByteBufferPool, org.eclipse.jetty.util.component.Dumpable
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.static classA variant ofArrayByteBufferPoolthat tracks buffer acquires/releases, useful to identify buffer leaks.Nested classes/interfaces inherited from interface org.eclipse.jetty.io.ByteBufferPool
ByteBufferPool.Accumulator, ByteBufferPool.NonPooling, ByteBufferPool.WrapperNested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Dumpable
org.eclipse.jetty.util.component.Dumpable.DumpableContainer -
Field Summary
Fields inherited from interface org.eclipse.jetty.io.ByteBufferPool
NON_POOLINGFields inherited from interface org.eclipse.jetty.util.component.Dumpable
KEY -
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 bucketCapacity) 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) longlonglonglonglonglonglonglongintintbooleanorg.eclipse.jetty.util.Pool<RetainableByteBuffer> poolFor(int capacity, boolean direct) voidsetStatisticsEnabled(boolean enabled) toString()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.eclipse.jetty.util.component.Dumpable
dump, dumpSelf
-
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 bucketCapacity) 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 indexbucketCapacity- aIntUnaryOperatorthat takes a bucket index and returns a capacity
-
-
Method Details
-
isStatisticsEnabled
@ManagedAttribute("Whether statistics are enabled") public boolean isStatisticsEnabled() -
setStatisticsEnabled
public void setStatisticsEnabled(boolean enabled) -
getMinCapacity
@ManagedAttribute("The minimum pooled buffer capacity") public int getMinCapacity() -
getMaxCapacity
@ManagedAttribute("The maximum pooled buffer capacity") public int 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
@ManagedAttribute("The number of pooled direct ByteBuffers") public long getDirectByteBufferCount() -
getHeapByteBufferCount
@ManagedAttribute("The number of pooled heap ByteBuffers") public long 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
@ManagedAttribute("The bytes retained by direct ByteBuffers") public long getDirectMemory() -
getHeapMemory
@ManagedAttribute("The bytes retained by heap ByteBuffers") public long getHeapMemory() -
getAvailableDirectMemory
public long getAvailableDirectMemory() -
getAvailableHeapMemory
public long getAvailableHeapMemory() -
clear
@ManagedOperation(value="Clears this ByteBufferPool", impact="ACTION") public void clear()Description copied from interface:ByteBufferPoolRemoves all
non-retainedpooled instances from this pool.- Specified by:
clearin interfaceByteBufferPool
-
dump
- Specified by:
dumpin interfaceorg.eclipse.jetty.util.component.Dumpable- Throws:
IOException
-
toString
-