com.maverick.nio
Class ByteBufferPool

java.lang.Object
  extended bycom.maverick.nio.ByteBufferPool

public class ByteBufferPool
extends java.lang.Object

This class provides a pool for either direct or non direct ByteBuffers.

Author:
Lee David Painter

Constructor Summary
ByteBufferPool()
          Create a default pool of ByteBuffers with 4k capacity
ByteBufferPool(int capacity, boolean direct)
          Create a pool of ByteBuffers.
 
Method Summary
 void add(java.nio.ByteBuffer buffer)
          Add a buffer back to the pool.
 java.nio.ByteBuffer get()
          Get a free buffer from the pool.
 int getAllocatedBuffers()
          Get the number of buffers currently allocated out.
 int getCapacity()
          Get the capacity of buffers in this pool.
 int getFreeBuffers()
          Get the number of buffers that are ready to be allocated.
 long getTotalMemoryAllocated()
          Calculate the total memory allocated by this pool.
 long getTotalMemoryInUse()
          Calculate the total memory in use by this pool.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

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 - int
direct - boolean
Method Detail

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

public java.nio.ByteBuffer get()
Get a free buffer from the pool.

Returns:
ByteBuffer

add

public void add(java.nio.ByteBuffer buffer)
Add a buffer back to the pool.

Parameters:
buffer - ByteBuffer


Copyright © 2003-2008 SSHTools LTD. All Rights Reserved.