Package org.eclipse.jetty.io
Class MappedByteBufferPool
java.lang.Object
org.eclipse.jetty.io.AbstractByteBufferPool
org.eclipse.jetty.io.MappedByteBufferPool
- All Implemented Interfaces:
ByteBufferPool
- 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
Nested ClassesNested classes/interfaces inherited from interface org.eclipse.jetty.io.ByteBufferPool
ByteBufferPool.Bucket, ByteBufferPool.Lease
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ConcurrentMap<Integer,
ByteBufferPool.Bucket> private final ConcurrentMap<Integer,
ByteBufferPool.Bucket> private final Function<Integer,
ByteBufferPool.Bucket> private static final Logger
-
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 aByteBuffer
of the given size.private int
bucketFor
(int size) (package private) ConcurrentMap<Integer,
ByteBufferPool.Bucket> bucketsFor
(boolean direct) void
clear()
private void
clearOldestBucket
(boolean direct) private long
getByteBufferCount
(boolean direct) long
long
private ByteBufferPool.Bucket
newBucket
(int key) void
release
(ByteBuffer buffer) Returns aByteBuffer
, usually obtained withByteBufferPool.acquire(int, boolean)
(but not necessarily), making it available for recycling and reuse.Methods inherited from class org.eclipse.jetty.io.AbstractByteBufferPool
decrementMemory, getCapacityFactor, getDirectMemory, getHeapMemory, getMaxQueueLength, getMemory, incrementMemory, releaseExcessMemory
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.eclipse.jetty.io.ByteBufferPool
newByteBuffer, remove
-
Field Details
-
LOG
-
_directBuffers
-
_heapBuffers
-
_newBucket
-
-
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 bytesmaxDirectMemory
- the max direct memory in bytes
-
-
Method Details
-
newBucket
-
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 but it will have the limit set to the given size.
- 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:ByteBufferPool
Returns a
ByteBuffer
, usually obtained withByteBufferPool.acquire(int, boolean)
(but not necessarily), making it available for recycling and reuse.- Parameters:
buffer
- the buffer to return- See Also:
-
clear
public void clear()- Overrides:
clear
in classAbstractByteBufferPool
-
clearOldestBucket
private void clearOldestBucket(boolean direct) -
bucketFor
private int bucketFor(int size) -
getDirectByteBufferCount
-
getHeapByteBufferCount
-
getByteBufferCount
private long getByteBufferCount(boolean direct) -
bucketsFor
-