Package org.eclipse.jetty.io
Class MappedByteBufferPool
java.lang.Object
org.eclipse.jetty.io.MappedByteBufferPool
- All Implemented Interfaces:
ByteBufferPool
,Dumpable
- Direct Known Subclasses:
MappedByteBufferPool.Tagged
A ByteBuffer pool where ByteBuffers are held in queues that are held in a Map.
Given a capacity factor
of 1024, the Map entry with key 1
holds a
queue of ByteBuffers each of capacity 1024, the Map entry with key 2
holds a
queue of ByteBuffers each of capacity 2048, and so on.
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected class
static class
Nested classes/interfaces inherited from interface org.eclipse.jetty.io.ByteBufferPool
ByteBufferPool.Lease
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Dumpable
Dumpable.DumpableContainer
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
static final int
-
Constructor Summary
ConstructorDescriptionCreates a new MappedByteBufferPool with a default configuration.MappedByteBufferPool
(int factor) Creates a new MappedByteBufferPool with the given capacity factor.MappedByteBufferPool
(int factor, int maxBucketSize) Creates a new MappedByteBufferPool with the given configuration.MappedByteBufferPool
(int factor, int maxBucketSize, long maxHeapMemory, long maxDirectMemory) Creates a new MappedByteBufferPool with the given configuration.MappedByteBufferPool
(int factor, int maxBucketSize, long maxHeapMemory, long maxDirectMemory, long retainedHeapMemory, long retainedDirectMemory) Creates a new MappedByteBufferPool with the given configuration. -
Method Summary
Modifier and TypeMethodDescriptionacquire
(int size, boolean direct) Requests aByteBuffer
of the given size.Get this pool as aRetainableByteBufferPool
, which supports reference counting of the buffers and possibly a more efficient lookup mechanism based on thePool
class.protected int
bucketFor
(int capacity) protected int
capacityFor
(int bucket) void
clear()
protected void
decrementMemory
(ByteBuffer buffer) Deprecated.void
dump
(Appendable out, String indent) Dump this object (and children) into an Appendable using the provided indent after any new lines.protected int
long
long
long
long
protected int
protected int
long
long
long
getMemory
(boolean direct) protected void
incrementMemory
(ByteBuffer buffer) Deprecated.boolean
protected RetainableByteBufferPool
newRetainableByteBufferPool
(int factor, int maxCapacity, int maxBucketSize, long retainedHeapMemory, long retainedDirectMemory) void
release
(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, Consumer<Boolean> clearFn) protected void
releaseMemory
(boolean direct) void
setDetailedDump
(boolean detailedDump) 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
-
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
-
MappedByteBufferPool
public MappedByteBufferPool()Creates a new MappedByteBufferPool with a default configuration. -
MappedByteBufferPool
public MappedByteBufferPool(int factor) Creates a new MappedByteBufferPool with the given capacity factor.- Parameters:
factor
- the capacity factor
-
MappedByteBufferPool
public MappedByteBufferPool(int factor, int maxBucketSize) Creates a new MappedByteBufferPool with the given configuration.- Parameters:
factor
- the capacity factormaxBucketSize
- the maximum ByteBuffer bucket size
-
MappedByteBufferPool
public MappedByteBufferPool(int factor, int maxBucketSize, long maxHeapMemory, long maxDirectMemory) Creates a new MappedByteBufferPool with the given configuration.- Parameters:
factor
- the capacity factormaxBucketSize
- the maximum ByteBuffer bucket sizemaxHeapMemory
- 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.
-
MappedByteBufferPool
public MappedByteBufferPool(int factor, int maxBucketSize, long maxHeapMemory, long maxDirectMemory, long retainedHeapMemory, long retainedDirectMemory) Creates a new MappedByteBufferPool with the given configuration.- Parameters:
factor
- the capacity factormaxBucketSize
- the maximum ByteBuffer bucket sizemaxHeapMemory
- 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.retainedHeapMemory
- 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:ByteBufferPool
Requests a
ByteBuffer
of the given size.The returned buffer may have a bigger capacity than the size being requested.
- Specified by:
acquire
in 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: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:
-
clear
public void clear() -
releaseMemory
protected void releaseMemory(boolean direct) -
bucketFor
protected int bucketFor(int capacity) -
capacityFor
protected int capacityFor(int bucket) -
getDirectByteBufferCount
-
getHeapByteBufferCount
-
isDetailedDump
public boolean isDetailedDump() -
setDetailedDump
public void setDetailedDump(boolean detailedDump) -
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
-
asRetainableByteBufferPool
Description copied from interface:ByteBufferPool
Get this pool as aRetainableByteBufferPool
, which supports reference counting of the buffers and possibly a more efficient lookup mechanism based on thePool
class.- Specified by:
asRetainableByteBufferPool
in 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
-
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)
-