java.lang.Object
org.eclipse.jetty.io.MappedByteBufferPool
- All Implemented Interfaces:
ByteBufferPool,org.eclipse.jetty.util.component.Dumpable
- Direct Known Subclasses:
MappedByteBufferPool.Tagged
@ManagedObject
public class MappedByteBufferPool
extends Object
implements org.eclipse.jetty.util.component.Dumpable
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
Nested ClassesNested classes/interfaces inherited from interface org.eclipse.jetty.io.ByteBufferPool
ByteBufferPool.Bucket, ByteBufferPool.LeaseNested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Dumpable
org.eclipse.jetty.util.component.Dumpable.DumpableContainer -
Field Summary
Fields inherited from interface org.eclipse.jetty.util.component.Dumpable
KEY -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new MappedByteBufferPool with a default configuration.MappedByteBufferPool(int factor) Creates a new MappedByteBufferPool with the given capacity factor.MappedByteBufferPool(int factor, int maxQueueLength) Creates a new MappedByteBufferPool with the given configuration.MappedByteBufferPool(int factor, int maxQueueLength, Function<Integer, ByteBufferPool.Bucket> newBucket) Creates a new MappedByteBufferPool with the given configuration.MappedByteBufferPool(int factor, int maxQueueLength, Function<Integer, ByteBufferPool.Bucket> newBucket, long maxHeapMemory, long maxDirectMemory) Creates a new MappedByteBufferPool with the given configuration. -
Method Summary
Modifier and TypeMethodDescriptionacquire(int size, boolean direct) Requests aByteBufferof the given size.protected intbucketFor(int capacity) protected intcapacityFor(int bucket) voidclear()protected voiddecrementMemory(ByteBuffer buffer) Deprecated.voiddump(Appendable out, String indent) protected intlonglonglonglonglonglongprotected intlonggetMemory(boolean direct) protected voidincrementMemory(ByteBuffer buffer) Deprecated.booleanvoidrelease(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
-
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 maxQueueLength) Creates a new MappedByteBufferPool with the given configuration.- Parameters:
factor- the capacity factormaxQueueLength- the maximum ByteBuffer queue length
-
MappedByteBufferPool
public MappedByteBufferPool(int factor, int maxQueueLength, Function<Integer, ByteBufferPool.Bucket> newBucket) Creates a new MappedByteBufferPool with the given configuration.- Parameters:
factor- the capacity factormaxQueueLength- the maximum ByteBuffer queue lengthnewBucket- the function that creates a Bucket
-
MappedByteBufferPool
public MappedByteBufferPool(int factor, int maxQueueLength, Function<Integer, ByteBufferPool.Bucket> newBucket, long maxHeapMemory, long maxDirectMemory) Creates a new MappedByteBufferPool with the given configuration.- Parameters:
factor- the capacity factormaxQueueLength- the maximum ByteBuffer queue lengthnewBucket- the function that creates a BucketmaxHeapMemory- 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:
-
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
- Specified by:
dumpin interfaceorg.eclipse.jetty.util.component.Dumpable- Throws:
IOException
-
toString
-
getCapacityFactor
protected int getCapacityFactor() -
getMaxQueueLength
protected int getMaxQueueLength() -
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)
-