Class ArrayByteBufferPool
java.lang.Object
org.eclipse.jetty.io.AbstractByteBufferPool
org.eclipse.jetty.io.ArrayByteBufferPool
- All Implemented Interfaces:
ByteBufferPool, Dumpable
- Direct Known Subclasses:
LogarithmicArrayByteBufferPool
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 ByteBufferPool
ByteBufferPool.Bucket, ByteBufferPool.LeaseNested classes/interfaces inherited from interface Dumpable
Dumpable.DumpableContainer -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanprivate final ByteBufferPool.Bucket[]private final ByteBufferPool.Bucket[]private final intprivate final intprivate static final Logger -
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 maxQueueLength, long maxHeapMemory, long maxDirectMemory) Creates a new ArrayByteBufferPool with the given configuration. -
Method Summary
Modifier and TypeMethodDescriptionacquire(int size, boolean direct) Requests aByteBufferof the given size.protected intbucketFor(int capacity) private ByteBufferPool.BucketbucketFor(int capacity, boolean direct) (package private) ByteBufferPool.Bucket[]bucketsFor(boolean direct) protected intcapacityFor(int bucket) voidclear()voiddump(Appendable out, String indent) Dump this object (and children) into an Appendable using the provided indent after any new lines.private longgetByteBufferCount(boolean direct) longlongbooleanprivate ByteBufferPool.BucketnewBucket(int key, boolean direct) voidrelease(ByteBuffer buffer) Returns aByteBuffer, usually obtained withByteBufferPool.acquire(int, boolean)(but not necessarily), making it available for recycling and reuse.protected voidreleaseMemory(boolean direct) voidsetDetailedDump(boolean detailedDump) toString()Methods inherited from class AbstractByteBufferPool
decrementMemory, getCapacityFactor, getDirectMemory, getHeapMemory, getMaxDirectMemory, getMaxHeapMemory, getMaxQueueLength, getMemory, incrementMemory, releaseExcessMemory, updateMemoryMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface ByteBufferPool
newByteBuffer, remove
-
Field Details
-
LOG
-
_maxCapacity
private final int _maxCapacity -
_minCapacity
private final int _minCapacity -
_direct
-
_indirect
-
_detailedDump
private boolean _detailedDump
-
-
Constructor Details
-
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 bytes, -1 for unlimited memory or 0 to use default heuristic.maxDirectMemory- the max direct memory in bytes, -1 for unlimited memory or 0 to use default heuristic.
-
-
Method Details
-
acquire
Description copied from interface:ByteBufferPoolRequests a
ByteBufferof 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.
- Specified by:
acquirein interfaceByteBufferPool- Parameters:
size- the size of the bufferdirect- whether the buffer must be direct or not- Returns:
- the requested buffer
- 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:
-
newBucket
-
clear
public void clear()- Overrides:
clearin classAbstractByteBufferPool
-
releaseMemory
protected void releaseMemory(boolean direct) -
bucketFor
protected int bucketFor(int capacity) -
capacityFor
protected int capacityFor(int bucket) -
bucketFor
-
getDirectByteBufferCount
-
getHeapByteBufferCount
-
getByteBufferCount
private long getByteBufferCount(boolean direct) -
bucketsFor
-
isDetailedDump
public boolean isDetailedDump() -
setDetailedDump
public void setDetailedDump(boolean detailedDump) -
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
-