com.mongodb.util
Class SimplePool<T>

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

public abstract class SimplePool<T>
extends java.lang.Object
implements javax.management.DynamicMBean


Field Summary
protected  java.util.List<T> _availSafe
           
protected  boolean _debug
           
protected  int _maxToKeep
           
protected  int _maxTotal
           
protected  java.lang.String _name
           
protected  boolean _trackLeaks
           
 
Constructor Summary
SimplePool(java.lang.String name, int maxToKeep, int maxTotal)
          See full constructor docs
SimplePool(java.lang.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
 java.util.Iterator<T> getAll()
           
 java.lang.Object getAttribute(java.lang.String attribute)
           
 javax.management.AttributeList getAttributes(java.lang.String[] attributes)
           
 javax.management.MBeanInfo getMBeanInfo()
           
 int inUse()
           
 java.lang.Object invoke(java.lang.String actionName, java.lang.Object[] params, java.lang.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(javax.management.Attribute attribute)
           
 javax.management.AttributeList setAttributes(javax.management.AttributeList attributes)
           
 java.lang.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 java.lang.String _name

_maxToKeep

protected final int _maxToKeep

_maxTotal

protected final int _maxTotal

_trackLeaks

protected final boolean _trackLeaks

_debug

protected final boolean _debug

_availSafe

protected final java.util.List<T> _availSafe
Constructor Detail

SimplePool

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


SimplePool

public SimplePool(java.lang.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 iff 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 java.util.Iterator<T> getAll()

available

public int available()

everCreated

public int everCreated()

maxToKeep

public int maxToKeep()

getAttribute

public java.lang.Object getAttribute(java.lang.String attribute)
Specified by:
getAttribute in interface javax.management.DynamicMBean

getAttributes

public javax.management.AttributeList getAttributes(java.lang.String[] attributes)
Specified by:
getAttributes in interface javax.management.DynamicMBean

getMBeanInfo

public javax.management.MBeanInfo getMBeanInfo()
Specified by:
getMBeanInfo in interface javax.management.DynamicMBean

invoke

public java.lang.Object invoke(java.lang.String actionName,
                               java.lang.Object[] params,
                               java.lang.String[] signature)
Specified by:
invoke in interface javax.management.DynamicMBean

setAttribute

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

setAttributes

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

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object