com.mongodb.util
Class SimplePool<T>

java.lang.Object
  extended by com.mongodb.util.SimplePool<T>
Direct Known Subclasses:
DBPortPool, StringBuilderPool

public abstract class SimplePool<T>
extends Object

This class is NOT part of the public API. Be prepared for non-binary compatible changes in minor releases.


Field Summary
protected  List<T> _avail
           
protected  String _name
           
protected  Set<T> _out
           
protected  int _size
           
 
Constructor Summary
SimplePool(String name, int size)
          Initializes a new pool of objects.
 
Method Summary
 void cleanup(T t)
          override this if you need to do any cleanup
protected  void close()
          Clears the pool of all objects.
protected abstract  T createNew()
          Creates a new object of this pool's type.
 void done(T t)
          call done when you are done with an object form the pool if there is room and the object is ok will get added
 T get()
          Gets an object from the pool - will block if none are available
 T get(long waitTime)
          Gets an object from the pool - will block if none are available
 int getAvailable()
           
 int getInUse()
           
 int getMaxSize()
           
 String getName()
           
 int getTotal()
           
protected  int pick(int recommended, boolean couldCreate)
          Pick a member of _avail.
 void remove(T t)
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_name

protected final String _name

_size

protected final int _size

_avail

protected final List<T> _avail

_out

protected final Set<T> _out
Constructor Detail

SimplePool

public SimplePool(String name,
                  int size)
Initializes a new pool of objects.

Parameters:
name - name for the pool
size - max to hold to at any given time. if < 0 then no limit
Method Detail

createNew

protected abstract T createNew()
Creates a new object of this pool's type. Implementations should throw a runtime exception if unable to create.

Returns:
the new object.

cleanup

public void cleanup(T t)
override this if you need to do any cleanup


pick

protected int pick(int recommended,
                   boolean couldCreate)
Pick a member of _avail. This method is called with a lock held on _avail, so it may be used safely.

Parameters:
recommended - the recommended member to choose.
couldCreate - true if there is room in the pool to create a new object
Returns:
>= 0 the one to use, -1 create a new one

done

public void done(T t)
call done when you are done with an object form the pool if there is room and the object is ok will get added

Parameters:
t - Object to add

remove

public void remove(T t)

get

public T get()
      throws InterruptedException
Gets an object from the pool - will block if none are available

Returns:
An object from the pool
Throws:
InterruptedException

get

public T get(long waitTime)
      throws InterruptedException
Gets an object from the pool - will block if none are available

Parameters:
waitTime - negative - forever 0 - return immediately no matter what positive ms to wait
Returns:
An object from the pool, or null if can't get one in the given waitTime
Throws:
InterruptedException

close

protected void close()
Clears the pool of all objects.


getName

public String getName()

getTotal

public int getTotal()

getInUse

public int getInUse()

getAvailable

public int getAvailable()

getMaxSize

public int getMaxSize()

toString

public String toString()
Overrides:
toString in class Object