com.mongodb.util
Class SimplePool<T>

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

public abstract class SimplePool<T>
extends Object
implements DynamicMBean


Field Summary
protected  List<T> _availSafe
           
protected  boolean _debug
           
protected  int _maxToKeep
           
protected  int _maxTotal
           
protected  MBeanInfo _mbeanInfo
           
protected  String _name
           
protected  boolean _trackLeaks
           
 
Constructor Summary
SimplePool(String name, int maxToKeep, int maxTotal)
          See full constructor docs
SimplePool(String name, int maxToKeep, int maxTotal, boolean trackLeaks, boolean debug)
          Initializes a new pool of objects.
 
Method Summary
 int available()
           
 void cleanup(T t)
          override this if you need to do any cleanup
protected  void clear()
          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
 int everCreated()
           
 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
 Iterator<T> getAll()
           
 Object getAttribute(String attribute)
           
 AttributeList getAttributes(String[] attributes)
           
 MBeanInfo getMBeanInfo()
           
 int inUse()
           
 Object invoke(String actionName, Object[] params, String[] signature)
           
 int maxToKeep()
           
 boolean ok(T t)
          callback to determine if an object is ok to be added back to the pool or used will be called when something is put back into the queue and when it comes out
protected  int pick(int iThink, boolean couldCreate)
           
 void remove(T t)
           
 void setAttribute(Attribute attribute)
           
 AttributeList setAttributes(AttributeList attributes)
           
 String toString()
           
 int total()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_name

protected final String _name

_maxToKeep

protected final int _maxToKeep

_maxTotal

protected final int _maxTotal

_trackLeaks

protected final boolean _trackLeaks

_debug

protected final boolean _debug

_mbeanInfo

protected final MBeanInfo _mbeanInfo

_availSafe

protected final List<T> _availSafe
Constructor Detail

SimplePool

public SimplePool(String name,
                  int maxToKeep,
                  int maxTotal)
See full constructor docs


SimplePool

public SimplePool(String name,
                  int maxToKeep,
                  int maxTotal,
                  boolean trackLeaks,
                  boolean debug)
Initializes a new pool of objects.

Parameters:
name - name for the pool
maxToKeep - max to hold to at any given time. if < 0 then no limit
maxTotal - max to have allocated at any point. if there are no more, get() will block
trackLeaks - if leaks should be tracked
Method Detail

createNew

protected abstract T createNew()
Creates a new object of this pool's type.

Returns:
the new object.

ok

public boolean ok(T t)
callback to determine if an object is ok to be added back to the pool or used will be called when something is put back into the queue and when it comes out

Returns:
true if the object is ok to be added back to pool

cleanup

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


pick

protected int pick(int iThink,
                   boolean couldCreate)
Returns:
>= 0 the one to use, -1 don't use any

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()
Gets an object from the pool - will block if none are available

Returns:
An object from the pool

get

public T get(long waitTime)
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

clear

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


total

public int total()

inUse

public int inUse()

getAll

public Iterator<T> getAll()

available

public int available()

everCreated

public int everCreated()

maxToKeep

public int maxToKeep()

getAttribute

public Object getAttribute(String attribute)
Specified by:
getAttribute in interface DynamicMBean

getAttributes

public AttributeList getAttributes(String[] attributes)
Specified by:
getAttributes in interface DynamicMBean

getMBeanInfo

public MBeanInfo getMBeanInfo()
Specified by:
getMBeanInfo in interface DynamicMBean

invoke

public Object invoke(String actionName,
                     Object[] params,
                     String[] signature)
Specified by:
invoke in interface DynamicMBean

setAttribute

public void setAttribute(Attribute attribute)
Specified by:
setAttribute in interface DynamicMBean

setAttributes

public AttributeList setAttributes(AttributeList attributes)
Specified by:
setAttributes in interface DynamicMBean

toString

public String toString()
Overrides:
toString in class Object