public abstract class SimplePool<T>
extends java.lang.Object
implements javax.management.DynamicMBean
Modifier and Type | Field and Description |
---|---|
protected java.util.List<T> |
_availSafe |
protected boolean |
_debug |
protected int |
_maxToKeep |
protected int |
_maxTotal |
protected javax.management.MBeanInfo |
_mbeanInfo |
protected java.lang.String |
_name |
protected boolean |
_trackLeaks |
Constructor and Description |
---|
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.
|
Modifier and Type | Method and Description |
---|---|
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() |
protected final java.lang.String _name
protected final int _maxToKeep
protected final int _maxTotal
protected final boolean _trackLeaks
protected final boolean _debug
protected final javax.management.MBeanInfo _mbeanInfo
protected final java.util.List<T> _availSafe
public SimplePool(java.lang.String name, int maxToKeep, int maxTotal)
public SimplePool(java.lang.String name, int maxToKeep, int maxTotal, boolean trackLeaks, boolean debug)
name
- name for the poolmaxToKeep
- max to hold to at any given time. if < 0 then no limitmaxTotal
- max to have allocated at any point. if there are no more, get() will blocktrackLeaks
- if leaks should be trackedprotected abstract T createNew()
public boolean ok(T t)
public void cleanup(T t)
protected int pick(int iThink, boolean couldCreate)
public void done(T t)
t
- Object to addpublic void remove(T t)
public T get()
public T get(long waitTime)
waitTime
- negative - forever
0 - return immediately no matter what
positive ms to waitprotected void clear()
public int total()
public int inUse()
public java.util.Iterator<T> getAll()
public int available()
public int everCreated()
public int maxToKeep()
public java.lang.Object getAttribute(java.lang.String attribute)
getAttribute
in interface javax.management.DynamicMBean
public javax.management.AttributeList getAttributes(java.lang.String[] attributes)
getAttributes
in interface javax.management.DynamicMBean
public javax.management.MBeanInfo getMBeanInfo()
getMBeanInfo
in interface javax.management.DynamicMBean
public java.lang.Object invoke(java.lang.String actionName, java.lang.Object[] params, java.lang.String[] signature)
invoke
in interface javax.management.DynamicMBean
public void setAttribute(javax.management.Attribute attribute)
setAttribute
in interface javax.management.DynamicMBean
public javax.management.AttributeList setAttributes(javax.management.AttributeList attributes)
setAttributes
in interface javax.management.DynamicMBean
public java.lang.String toString()
toString
in class java.lang.Object