java.lang.Object
org.eclipse.jetty.io.ArrayByteBufferPool
- All Implemented Interfaces:
ByteBufferPool,org.eclipse.jetty.util.component.Dumpable
- Direct Known Subclasses:
LogarithmicArrayByteBufferPool
@ManagedObject
public class ArrayByteBufferPool
extends Object
implements org.eclipse.jetty.util.component.Dumpable
A ByteBuffer pool where ByteBuffers are held in queues that are held in array elements.
Given a capacity factor of 4096, the first array element holds a bucket of ByteBuffers
each of capacity 4096, the second array element holds a bucket of ByteBuffers each of capacity
8192, and so on.
The maxHeapMemory and maxDirectMemory default heuristic is to use Runtime.maxMemory()
divided by 4.
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from interface org.eclipse.jetty.io.ByteBufferPool
ByteBufferPool.LeaseNested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Dumpable
org.eclipse.jetty.util.component.Dumpable.DumpableContainer -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intFields inherited from interface org.eclipse.jetty.util.component.Dumpable
KEY -
Constructor Summary
ConstructorsConstructorDescriptionCreates 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 maxBucketSize, long maxHeapMemory, long maxDirectMemory) Creates a new ArrayByteBufferPool with the given configuration.ArrayByteBufferPool(int minCapacity, int factor, int maxCapacity, int maxBucketSize, long maxHeapMemory, long maxDirectMemory, long retainedHeapMemory, long retainedDirectMemory) Creates a new ArrayByteBufferPool with the given configuration. -
Method Summary
Modifier and TypeMethodDescriptionacquire(int size, boolean direct) Requests aByteBufferof the given size.Get this pool as aRetainableByteBufferPool, which supports reference counting of the buffers and possibly a more efficient lookup mechanism based on thePoolclass.protected intbucketFor(int capacity) protected org.eclipse.jetty.io.AbstractByteBufferPool.BucketbucketFor(int capacity, boolean direct) protected intcapacityFor(int bucket) voidclear()protected voiddecrementMemory(ByteBuffer buffer) Deprecated.voiddump(Appendable out, String indent) protected intlonglonglonglongprotected intprotected intlonglonglonggetMemory(boolean direct) protected voidincrementMemory(ByteBuffer buffer) Deprecated.booleanprotected RetainableByteBufferPoolnewRetainableByteBufferPool(int factor, int maxCapacity, int maxBucketSize, long retainedHeapMemory, long retainedDirectMemory) voidrelease(ByteBuffer buffer) Returns aByteBuffer, usually obtained withByteBufferPool.acquire(int, boolean)(but not necessarily), making it available for recycling and reuse.protected voidreleaseExcessMemory(boolean direct, Consumer<Boolean> clearFn) protected voidreleaseMemory(boolean direct) voidsetDetailedDump(boolean detailedDump) toString()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.eclipse.jetty.io.ByteBufferPool
newByteBuffer, removeMethods inherited from interface org.eclipse.jetty.util.component.Dumpable
dump, dumpSelf
-
Field Details
-
DEFAULT_FACTOR
public static final int DEFAULT_FACTOR- See Also:
-
DEFAULT_MAX_CAPACITY_BY_FACTOR
public static final int DEFAULT_MAX_CAPACITY_BY_FACTOR- See Also:
-
-
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 maxQueueLength) 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 capacitymaxQueueLength- the maximum ByteBuffer queue length
-
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 ByteBuffer queue length in aAbstractByteBufferPool.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
public ArrayByteBufferPool(int minCapacity, int factor, int maxCapacity, int maxBucketSize, long maxHeapMemory, long maxDirectMemory, long retainedHeapMemory, long retainedDirectMemory) Creates a new ArrayByteBufferPool with the given configuration.- Parameters:
minCapacity- the minimum ByteBuffer capacityfactor- the capacity factormaxCapacity- the maximum ByteBuffer capacitymaxBucketSize- the maximum ByteBuffer queue length in aAbstractByteBufferPool.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 heuristicretainedHeapMemory- the max heap memory in bytes, -2 for no retained memory, -1 for unlimited retained memory or 0 to use default heuristicretainedDirectMemory- the max direct memory in bytes, -2 for no retained memory, -1 for unlimited retained memory or 0 to use default heuristic
-
-
Method Details
-
newRetainableByteBufferPool
protected RetainableByteBufferPool newRetainableByteBufferPool(int factor, int maxCapacity, int maxBucketSize, long retainedHeapMemory, long retainedDirectMemory) -
acquire
Description copied from interface:ByteBufferPoolRequests a
ByteBufferof the given size.The returned buffer may have a bigger capacity than the size being requested.
- Specified by:
acquirein interfaceByteBufferPool- Parameters:
size- the size of the bufferdirect- whether the buffer must be direct or not- Returns:
- a buffer with at least the requested capacity, with position and limit set to 0.
- See Also:
-
release
Description copied from interface:ByteBufferPoolReturns a
ByteBuffer, usually obtained withByteBufferPool.acquire(int, boolean)(but not necessarily), making it available for recycling and reuse.- Specified by:
releasein interfaceByteBufferPool- Parameters:
buffer- the buffer to return- See Also:
-
clear
public void clear() -
releaseMemory
protected void releaseMemory(boolean direct) -
bucketFor
protected int bucketFor(int capacity) -
capacityFor
protected int capacityFor(int bucket) -
bucketFor
protected org.eclipse.jetty.io.AbstractByteBufferPool.Bucket bucketFor(int capacity, boolean direct) -
getDirectByteBufferCount
@ManagedAttribute("The number of pooled direct ByteBuffers") public long getDirectByteBufferCount() -
getHeapByteBufferCount
@ManagedAttribute("The number of pooled heap ByteBuffers") public long getHeapByteBufferCount() -
isDetailedDump
public boolean isDetailedDump() -
setDetailedDump
public void setDetailedDump(boolean detailedDump) -
dump
- Specified by:
dumpin interfaceorg.eclipse.jetty.util.component.Dumpable- Throws:
IOException
-
toString
-
asRetainableByteBufferPool
Description copied from interface:ByteBufferPoolGet this pool as aRetainableByteBufferPool, which supports reference counting of the buffers and possibly a more efficient lookup mechanism based on thePoolclass.- Specified by:
asRetainableByteBufferPoolin interfaceByteBufferPool- Returns:
- This pool as a RetainableByteBufferPool. The same instance is always returned by multiple calls to this method.
-
getCapacityFactor
protected int getCapacityFactor() -
getMaxCapacity
protected int getMaxCapacity() -
getMaxBucketSize
protected int getMaxBucketSize() -
decrementMemory
Deprecated. -
incrementMemory
Deprecated. -
releaseExcessMemory
-
getDirectMemory
@ManagedAttribute("The bytes retained by direct ByteBuffers") public long getDirectMemory() -
getHeapMemory
@ManagedAttribute("The bytes retained by heap ByteBuffers") public long getHeapMemory() -
getMaxDirectMemory
@ManagedAttribute("The max num of bytes that can be retained from direct ByteBuffers") public long getMaxDirectMemory() -
getMaxHeapMemory
@ManagedAttribute("The max num of bytes that can be retained from heap ByteBuffers") public long getMaxHeapMemory() -
getMemory
public long getMemory(boolean direct)
-