|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.kafka.clients.producer.internals.BufferPool
public final class BufferPool
A pool of ByteBuffers kept under a given memory limit. This class is fairly specific to the needs of the producer. In particular it has the following properties:
Constructor Summary | |
---|---|
BufferPool(long memory,
int poolableSize,
boolean blockOnExhaustion,
Metrics metrics,
Time time)
Create a new buffer pool |
Method Summary | |
---|---|
java.nio.ByteBuffer |
allocate(int size)
Allocate a buffer of the given size. |
long |
availableMemory()
the total free memory both unallocated and in the free list |
void |
deallocate(java.nio.ByteBuffer buffer)
|
void |
deallocate(java.nio.ByteBuffer buffer,
int size)
Return buffers to the pool. |
int |
poolableSize()
The buffer size that will be retained in the free list after use |
int |
queued()
The number of threads blocked waiting on memory |
long |
totalMemory()
The total memory managed by this pool |
long |
unallocatedMemory()
Get the unallocated memory (not in the free list or in use) |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public BufferPool(long memory, int poolableSize, boolean blockOnExhaustion, Metrics metrics, Time time)
memory
- The maximum amount of memory that this buffer pool can allocatepoolableSize
- The buffer size to cache in the free list rather than deallocatingblockOnExhaustion
- This controls the behavior when the buffer pool is out of memory. If true the
allocate(int)
call will block and wait for memory to be returned to the pool. If false
allocate(int)
will throw an exception if the buffer is out of memory.Method Detail |
---|
public java.nio.ByteBuffer allocate(int size) throws java.lang.InterruptedException
size
- The buffer size to allocate in bytes
java.lang.InterruptedException
- If the thread is interrupted while blocked
java.lang.IllegalArgumentException
- if size is larger than the total memory controlled by the pool (and hence we would block
forever)
BufferExhaustedException
- if the pool is in non-blocking mode and size exceeds the free memory in the poolpublic void deallocate(java.nio.ByteBuffer buffer, int size)
buffer
- The buffer to returnsize
- The size of the buffer to mark as deallocated, note that this maybe smaller than buffer.capacity
since the buffer may re-allocate itself during in-place compressionpublic void deallocate(java.nio.ByteBuffer buffer)
public long availableMemory()
public long unallocatedMemory()
public int queued()
public int poolableSize()
public long totalMemory()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |