Package org.eclipse.jetty.io
Class ArrayByteBufferPool
- java.lang.Object
-
- org.eclipse.jetty.io.ArrayByteBufferPool
-
- All Implemented Interfaces:
ByteBufferPool
,Dumpable
- Direct Known Subclasses:
LogarithmicArrayByteBufferPool
@ManagedObject public class ArrayByteBufferPool extends java.lang.Object implements Dumpable
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
-
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Dumpable
Dumpable.DumpableContainer
-
-
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 Deprecated Methods Modifier and Type Method Description java.nio.ByteBuffer
acquire(int size, boolean direct)
Requests aByteBuffer
of the given size.protected int
bucketFor(int capacity)
protected int
capacityFor(int bucket)
void
clear()
protected void
decrementMemory(java.nio.ByteBuffer buffer)
Deprecated.void
dump(java.lang.Appendable out, java.lang.String indent)
Dump this object (and children) into an Appendable using the provided indent after any new lines.protected int
getCapacityFactor()
long
getDirectByteBufferCount()
long
getDirectMemory()
long
getHeapByteBufferCount()
long
getHeapMemory()
long
getMaxDirectMemory()
long
getMaxHeapMemory()
protected int
getMaxQueueLength()
long
getMemory(boolean direct)
protected void
incrementMemory(java.nio.ByteBuffer buffer)
Deprecated.boolean
isDetailedDump()
void
release(java.nio.ByteBuffer buffer)
Returns aByteBuffer
, usually obtained withByteBufferPool.acquire(int, boolean)
(but not necessarily), making it available for recycling and reuse.protected void
releaseExcessMemory(boolean direct, java.util.function.Consumer<java.lang.Boolean> clearFn)
protected void
releaseMemory(boolean direct)
void
setDetailedDump(boolean detailedDump)
java.lang.String
toString()
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.eclipse.jetty.io.ByteBufferPool
newByteBuffer, remove
-
-
-
-
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 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 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.
- Specified by:
acquire
in interfaceByteBufferPool
- 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.- Specified by:
release
in interfaceByteBufferPool
- Parameters:
buffer
- the buffer to return- See Also:
ByteBufferPool.acquire(int, boolean)
-
clear
public void clear()
-
releaseMemory
protected void releaseMemory(boolean direct)
-
bucketFor
protected int bucketFor(int capacity)
-
capacityFor
protected int capacityFor(int bucket)
-
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
public void dump(java.lang.Appendable out, java.lang.String indent) throws java.io.IOException
Description copied from interface:Dumpable
Dump 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.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
getCapacityFactor
protected int getCapacityFactor()
-
getMaxQueueLength
protected int getMaxQueueLength()
-
decrementMemory
@Deprecated protected void decrementMemory(java.nio.ByteBuffer buffer)
Deprecated.
-
incrementMemory
@Deprecated protected void incrementMemory(java.nio.ByteBuffer buffer)
Deprecated.
-
releaseExcessMemory
protected void releaseExcessMemory(boolean direct, java.util.function.Consumer<java.lang.Boolean> clearFn)
-
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)
-
-