public class PoolingByteBufferManager extends Object implements ByteBufferManager, org.mule.runtime.api.lifecycle.Disposable
ByteBufferManager implementation which pools instances for better performance.
Buffers are kept in separate pools depending on their capacity.
Idle buffers and capacity pools are automatically expired.
Unlike traditional pools which are exhausted in terms of number of instances, we don't care about
the number of buffers pooled but in the amount of memory they retain. This pool will be exhausted
when a certain threshold of retained memory is reached. When exhausted, invokations to
allocate(int) will block until more memory becomes available (by invoking deallocate(ByteBuffer)).
If allocate(int) is blocked by more than waitTimeoutMillis milliseconds, then a
MaxStreamingMemoryExceededException is thrown.
| Constructor and Description |
|---|
PoolingByteBufferManager()
Creates a new instance which allows the pool to grow up to 50% of the runtime's max memory and has a wait
timeout of 10 seconds.
|
PoolingByteBufferManager(MemoryManager memoryManager,
long waitTimeoutMillis)
Creates a new instance which allows the pool to grow up to 50% of calling
MemoryManager.getMaxMemory()
on the given memoryManager, and has waitTimeoutMillis as wait timeout. |
| Modifier and Type | Method and Description |
|---|---|
ByteBuffer |
allocate(int capacity)
Returns a
ByteBuffer of the given capacity. |
void |
deallocate(ByteBuffer byteBuffer)
Indicates that the given
byteBuffer is no longer needed and the runtime
may dispose of it however it sees fit. |
void |
dispose() |
public PoolingByteBufferManager()
MemoryManager.getMaxMemory()public PoolingByteBufferManager(MemoryManager memoryManager, long waitTimeoutMillis)
MemoryManager.getMaxMemory()
on the given memoryManager, and has waitTimeoutMillis as wait timeout.memoryManager - a MemoryManager used to determine the runtime's max memorywaitTimeoutMillis - how long to wait when the pool is exhaustedpublic ByteBuffer allocate(int capacity)
ByteBuffer of the given capacity.
Invokers MUST call the ByteBufferManager.deallocate(ByteBuffer) method with the returned
buffer once it's no longer needed.
allocate in interface ByteBufferManagercapacity - the capacity of the returned bufferByteBuffer of the given capacitypublic void deallocate(ByteBuffer byteBuffer)
byteBuffer is no longer needed and the runtime
may dispose of it however it sees fit.deallocate in interface ByteBufferManagerbyteBuffer - the buffer to be deallocated.public void dispose()
dispose in interface org.mule.runtime.api.lifecycle.DisposableCopyright © 2003–2017 MuleSoft, Inc.. All rights reserved.