Package org.eclipse.jetty.io
Class ArrayByteBufferPool
java.lang.Object
org.eclipse.jetty.io.ArrayByteBufferPool
- All Implemented Interfaces:
ByteBufferPool
,Dumpable
- Direct Known Subclasses:
ArrayByteBufferPool.Quadratic
,ArrayByteBufferPool.Tracking
A RetainableByteBuffer
pool where RetainableByteBuffers are held in Pool
s 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
Modifier and TypeClassDescriptionstatic class
A variant of theArrayByteBufferPool
that uses buckets of buffers that increase in size by a power of 2 (e.g.static class
A variant ofArrayByteBufferPool
that 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.Sized, ByteBufferPool.Wrapper
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Dumpable
Dumpable.DumpableContainer
-
Field Summary
Fields inherited from interface org.eclipse.jetty.io.ByteBufferPool
NON_POOLING, SIZED_NON_POOLING
-
Constructor Summary
ModifierConstructorDescriptionCreates 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.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. -
Method Summary
Modifier and TypeMethodDescriptionacquire
(int size, boolean direct) Acquires aRetainableByteBuffer
from this pool.void
clear()
Removes allnon-retained
pooled instances from this pool.void
dump
(Appendable out, String indent) Dump this object (and children) into an Appendable using the provided indent after any new lines.long
long
long
long
long
long
long
long
int
int
boolean
poolFor
(int capacity, boolean direct) boolean
removeAndRelease
(RetainableByteBuffer buffer) Release
the buffer in a way that will remove it from any pool that it may be in.void
setStatisticsEnabled
(boolean enabled) toString()
-
Constructor Details
-
ArrayByteBufferPool
public ArrayByteBufferPool()Creates a new ArrayByteBufferPool with a default configuration. BothmaxHeapMemory
andmaxDirectMemory
default to 0 to use default heuristic. -
ArrayByteBufferPool
public ArrayByteBufferPool(int minCapacity, int factor, int maxCapacity) Creates a new ArrayByteBufferPool with the given configuration. BothmaxHeapMemory
andmaxDirectMemory
default 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. BothmaxHeapMemory
andmaxDirectMemory
default 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
- aIntUnaryOperator
that takes a capacity and returns a bucket indexbucketCapacity
- aIntUnaryOperator
that takes a bucket index and returns a capacity
-
-
Method Details
-
isStatisticsEnabled
-
setStatisticsEnabled
public void setStatisticsEnabled(boolean enabled) -
getMinCapacity
-
getMaxCapacity
-
acquire
Description copied from interface:ByteBufferPool
Acquires a
RetainableByteBuffer
from this pool.- Specified by:
acquire
in 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
RetainableByteBuffer
with position and limit set to 0.
-
removeAndRelease
Description copied from interface:ByteBufferPool
Release
the buffer in a way that will remove it from any pool that it may be in. If the buffer is not in a pool, calling this method is equivalent to callingRetainable.release()
. Calling this method satisfies any contract that requires a call toRetainable.release()
.- Specified by:
removeAndRelease
in interfaceByteBufferPool
- Returns:
true
if a call toRetainable.release()
would have returnedtrue
.- See Also:
-
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
public long getAvailableDirectMemory() -
getAvailableHeapMemory
public long getAvailableHeapMemory() -
clear
Description copied from interface:ByteBufferPool
Removes all
non-retained
pooled instances from this pool.- Specified by:
clear
in interfaceByteBufferPool
-
dump
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.- Specified by:
dump
in 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
-