Package com.sshtools.common.util
Class ByteBufferPool
java.lang.Object
com.sshtools.common.util.ByteBufferPool
This class provides a pool for either direct or non direct ByteBuffers.
-
Constructor Summary
ConstructorsConstructorDescriptionCreate a default pool of ByteBuffers with 4k capacityByteBufferPool(int capacity, boolean direct) Create a pool of ByteBuffers. -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(ByteBuffer buffer) Add a buffer back to the pool.get()Get a free buffer from the pool.intGet the number of buffers currently allocated out.intGet the capacity of buffers in this pool.intGet the number of buffers that are ready to be allocated.longCalculate the total memory allocated by this pool.longCalculate the total memory in use by this pool.
-
Constructor Details
-
ByteBufferPool
public ByteBufferPool()Create a default pool of ByteBuffers with 4k capacity -
ByteBufferPool
public ByteBufferPool(int capacity, boolean direct) Create a pool of ByteBuffers.- Parameters:
capacity- intdirect- boolean
-
-
Method Details
-
getCapacity
public int getCapacity()Get the capacity of buffers in this pool.- Returns:
- int
-
getAllocatedBuffers
public int getAllocatedBuffers()Get the number of buffers currently allocated out.- Returns:
- int
-
getFreeBuffers
public int getFreeBuffers()Get the number of buffers that are ready to be allocated.- Returns:
- int
-
getTotalMemoryInUse
public long getTotalMemoryInUse()Calculate the total memory in use by this pool.- Returns:
- long
-
getTotalMemoryAllocated
public long getTotalMemoryAllocated()Calculate the total memory allocated by this pool.- Returns:
- long
-
get
Get a free buffer from the pool.- Returns:
- ByteBuffer
-
add
Add a buffer back to the pool.- Parameters:
buffer- ByteBuffer
-