Package org.eclipse.jetty.io
Class MappedByteBufferPool
- java.lang.Object
-
- org.eclipse.jetty.io.AbstractByteBufferPool
-
- org.eclipse.jetty.io.MappedByteBufferPool
-
- All Implemented Interfaces:
ByteBufferPool,Dumpable
- Direct Known Subclasses:
MappedByteBufferPool.Tagged
@ManagedObject public class MappedByteBufferPool extends AbstractByteBufferPool implements Dumpable
A ByteBuffer pool where ByteBuffers are held in queues that are held in a Map.
Given a capacity
factorof 1024, the Map entry with key1holds a queue of ByteBuffers each of capacity 1024, the Map entry with key2holds a queue of ByteBuffers each of capacity 2048, and so on.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classMappedByteBufferPool.Tagged-
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
-
-
Field Summary
Fields Modifier and Type Field Description private boolean_detailedDumpprivate java.util.concurrent.ConcurrentMap<java.lang.Integer,ByteBufferPool.Bucket>_directBuffersprivate java.util.concurrent.ConcurrentMap<java.lang.Integer,ByteBufferPool.Bucket>_heapBuffersprivate java.util.function.Function<java.lang.Integer,ByteBufferPool.Bucket>_newBucketprivate static LoggerLOG
-
Constructor Summary
Constructors Constructor Description MappedByteBufferPool()Creates 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, java.util.function.Function<java.lang.Integer,ByteBufferPool.Bucket> newBucket)Creates a new MappedByteBufferPool with the given configuration.MappedByteBufferPool(int factor, int maxQueueLength, java.util.function.Function<java.lang.Integer,ByteBufferPool.Bucket> newBucket, long maxHeapMemory, long maxDirectMemory)Creates a new MappedByteBufferPool with the given configuration.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.nio.ByteBufferacquire(int size, boolean direct)Requests aByteBufferof the given size.protected intbucketFor(int capacity)(package private) java.util.concurrent.ConcurrentMap<java.lang.Integer,ByteBufferPool.Bucket>bucketsFor(boolean direct)protected intcapacityFor(int bucket)voidclear()voiddump(java.lang.Appendable out, java.lang.String indent)Dump this object (and children) into an Appendable using the provided indent after any new lines.private longgetByteBufferCount(boolean direct)longgetDirectByteBufferCount()longgetHeapByteBufferCount()booleanisDetailedDump()private ByteBufferPool.BucketnewBucket(int key, boolean direct)voidrelease(java.nio.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)java.lang.StringtoString()-
Methods inherited from class org.eclipse.jetty.io.AbstractByteBufferPool
decrementMemory, getCapacityFactor, getDirectMemory, getHeapMemory, getMaxDirectMemory, getMaxHeapMemory, getMaxQueueLength, getMemory, incrementMemory, releaseExcessMemory, updateMemory
-
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 Detail
-
LOG
private static final Logger LOG
-
_directBuffers
private final java.util.concurrent.ConcurrentMap<java.lang.Integer,ByteBufferPool.Bucket> _directBuffers
-
_heapBuffers
private final java.util.concurrent.ConcurrentMap<java.lang.Integer,ByteBufferPool.Bucket> _heapBuffers
-
_newBucket
private final java.util.function.Function<java.lang.Integer,ByteBufferPool.Bucket> _newBucket
-
_detailedDump
private boolean _detailedDump
-
-
Constructor Detail
-
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, java.util.function.Function<java.lang.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, java.util.function.Function<java.lang.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 Detail
-
newBucket
private ByteBufferPool.Bucket newBucket(int key, boolean direct)
-
acquire
public java.nio.ByteBuffer acquire(int size, boolean direct)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:
ByteBufferPool.release(ByteBuffer)
-
release
public void release(java.nio.ByteBuffer buffer)
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:
ByteBufferPool.acquire(int, boolean)
-
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)
-
getDirectByteBufferCount
@ManagedAttribute("The number of pooled direct ByteBuffers") public long getDirectByteBufferCount()
-
getHeapByteBufferCount
@ManagedAttribute("The number of pooled heap ByteBuffers") public long getHeapByteBufferCount()
-
getByteBufferCount
private long getByteBufferCount(boolean direct)
-
bucketsFor
java.util.concurrent.ConcurrentMap<java.lang.Integer,ByteBufferPool.Bucket> bucketsFor(boolean direct)
-
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.IOExceptionDescription 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.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-