com.jmex.pool
Class ObjectPool<T>

java.lang.Object
  extended by com.jmex.pool.ObjectPool<T>

public class ObjectPool<T>
extends java.lang.Object

ObjectPool allows re-use of Objects.

Author:
Matthew D. Hicks

Constructor Summary
ObjectPool(java.lang.Class<T> c, int preAllocate)
           
ObjectPool(ObjectGenerator<T> generator, int preAllocate)
           
 
Method Summary
 int available()
          Retrieves the number of objects available in the queue.
 T get()
          Retrieves the first available object in the pool or creates a new instance if there are none available.
protected  T newInstance()
           
 boolean release(T t)
          Releases the object back into the pool for re-use.
 T request()
          Retrieves the first available object in the pool or returns null if none are available.
 int size()
          Returns the actual number of T's created by this ObjectPool.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ObjectPool

public ObjectPool(ObjectGenerator<T> generator,
                  int preAllocate)

ObjectPool

public ObjectPool(java.lang.Class<T> c,
                  int preAllocate)
Method Detail

newInstance

protected T newInstance()

get

public T get()
Retrieves the first available object in the pool or creates a new instance if there are none available.

Returns:
T

request

public T request()
          throws java.lang.Exception
Retrieves the first available object in the pool or returns null if none are available.

Returns:
T
Throws:
java.lang.Exception

release

public boolean release(T t)
Releases the object back into the pool for re-use.

Parameters:
t -
Returns:
boolean

available

public int available()
Retrieves the number of objects available in the queue.

Returns:
int

size

public int size()
Returns the actual number of T's created by this ObjectPool.

Returns:
int