|
||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.commons.pool.PoolUtils
public final class PoolUtils
This class consists exclusively of static methods that operate on or return keyedPool related interfaces.
Constructor Summary | |
---|---|
PoolUtils()
PoolUtils instances should NOT be constructed in standard programming. |
Method Summary | |
---|---|
static ObjectPool |
adapt(KeyedObjectPool keyedPool)
Adapt a KeyedObjectPool instance to work where an ObjectPool is needed. |
static ObjectPool |
adapt(KeyedObjectPool keyedPool,
java.lang.Object key)
Adapt a KeyedObjectPool instance to work where an ObjectPool is needed using the
specified key when delegating. |
static PoolableObjectFactory |
adapt(KeyedPoolableObjectFactory keyedFactory)
Adapt a KeyedPoolableObjectFactory instance to work where a PoolableObjectFactory is
needed. |
static PoolableObjectFactory |
adapt(KeyedPoolableObjectFactory keyedFactory,
java.lang.Object key)
Adapt a KeyedPoolableObjectFactory instance to work where a PoolableObjectFactory is
needed using the specified key when delegating. |
static KeyedObjectPool |
adapt(ObjectPool pool)
Adapt an ObjectPool to work where an KeyedObjectPool is needed. |
static KeyedPoolableObjectFactory |
adapt(PoolableObjectFactory factory)
Adapt a PoolableObjectFactory instance to work where a KeyedPoolableObjectFactory is
needed. |
static KeyedObjectPool |
checkedPool(KeyedObjectPool keyedPool,
java.lang.Class type)
Wraps an KeyedObjectPool and dynamically checks the type of objects borrowed and returned to the keyedPool. |
static ObjectPool |
checkedPool(ObjectPool pool,
java.lang.Class type)
Wraps an ObjectPool and dynamically checks the type of objects borrowed and returned to the keyedPool. |
static java.util.Map |
checkMinIdle(KeyedObjectPool keyedPool,
java.util.Collection keys,
int minIdle,
long period)
Periodically check the idle object count for each key in the Collection keys in the keyedPool. |
static java.util.TimerTask |
checkMinIdle(KeyedObjectPool keyedPool,
java.lang.Object key,
int minIdle,
long period)
Periodically check the idle object count for the key in the keyedPool. |
static java.util.TimerTask |
checkMinIdle(ObjectPool pool,
int minIdle,
long period)
Periodically check the idle object count for the keyedPool. |
static void |
prefill(KeyedObjectPool keyedPool,
java.util.Collection keys,
int count)
Call addObject(Object) on keyedPool with each key in keys for
count number of times. |
static void |
prefill(KeyedObjectPool keyedPool,
java.lang.Object key,
int count)
Call addObject(Object) on keyedPool with key count
number of times. |
static void |
prefill(ObjectPool pool,
int count)
Call addObject() on keyedPool count number of times. |
static KeyedObjectPool |
synchronizedPool(KeyedObjectPool keyedPool)
Returns a synchronized (thread-safe) KeyedObjectPool backed by the specified KeyedObjectPool. |
static ObjectPool |
synchronizedPool(ObjectPool pool)
Returns a synchronized (thread-safe) ObjectPool backed by the specified ObjectPool. |
static KeyedPoolableObjectFactory |
synchronizedPoolableFactory(KeyedPoolableObjectFactory keyedFactory)
Returns a synchronized (thread-safe) KeyedPoolableObjectFactory backed by the specified KeyedPoolableObjectFactory. |
static PoolableObjectFactory |
synchronizedPoolableFactory(PoolableObjectFactory factory)
Returns a synchronized (thread-safe) PoolableObjectFactory backed by the specified PoolableObjectFactory. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public PoolUtils()
Method Detail |
---|
public static ObjectPool adapt(KeyedObjectPool keyedPool) throws java.lang.IllegalArgumentException
KeyedObjectPool
instance to work where an ObjectPool
is needed. This is the
equivalent of calling PoolUtils.adapt(aKeyedObjectPool, new Object())
.
keyedPool
- the KeyedObjectPool
to delegate to.
ObjectPool
that delegates to keyedPool
with an internal key.
java.lang.IllegalArgumentException
- when keyedPool
is null
.adapt(KeyedObjectPool, Object)
public static ObjectPool adapt(KeyedObjectPool keyedPool, java.lang.Object key) throws java.lang.IllegalArgumentException
KeyedObjectPool
instance to work where an ObjectPool
is needed using the
specified key
when delegating.
keyedPool
- the KeyedObjectPool
to delegate to.key
- the key to use when delegating.
ObjectPool
that delegates to keyedPool
with the specified key.
java.lang.IllegalArgumentException
- when keyedPool
or key
is null
.adapt(KeyedObjectPool)
public static PoolableObjectFactory adapt(KeyedPoolableObjectFactory keyedFactory) throws java.lang.IllegalArgumentException
KeyedPoolableObjectFactory
instance to work where a PoolableObjectFactory
is
needed. This method is the equivalent of calling
PoolUtils.adapt(aKeyedPoolableObjectFactory, new Object())
.
keyedFactory
- the KeyedPoolableObjectFactory
to delegate to.
PoolableObjectFactory
that delegates to keyedFactory
with an internal key.
java.lang.IllegalArgumentException
- when keyedFactory
is null
.adapt(KeyedPoolableObjectFactory, Object)
public static PoolableObjectFactory adapt(KeyedPoolableObjectFactory keyedFactory, java.lang.Object key) throws java.lang.IllegalArgumentException
KeyedPoolableObjectFactory
instance to work where a PoolableObjectFactory
is
needed using the specified key
when delegating.
keyedFactory
- the KeyedPoolableObjectFactory
to delegate to.key
- the key to use when delegating.
PoolableObjectFactory
that delegates to keyedFactory
with the specified key.
java.lang.IllegalArgumentException
- when keyedFactory
or key
is null
.adapt(KeyedPoolableObjectFactory)
public static KeyedObjectPool adapt(ObjectPool pool) throws java.lang.IllegalArgumentException
ObjectPool
to work where an KeyedObjectPool
is needed.
The key is ignored.
pool
- the ObjectPool
to delegate to.
KeyedObjectPool
that delegates to keyedPool
ignoring the key.
java.lang.IllegalArgumentException
- when keyedPool
is null
.public static KeyedPoolableObjectFactory adapt(PoolableObjectFactory factory) throws java.lang.IllegalArgumentException
PoolableObjectFactory
instance to work where a KeyedPoolableObjectFactory
is
needed. The key is ignored.
factory
- the PoolableObjectFactory
to delegate to.
KeyedPoolableObjectFactory
that delegates to factory
ignoring the key.
java.lang.IllegalArgumentException
- when factory
is null
.public static KeyedObjectPool checkedPool(KeyedObjectPool keyedPool, java.lang.Class type)
KeyedObjectPool
and dynamically checks the type of objects borrowed and returned to the keyedPool.
If an object is passed to the keyedPool that isn't of type type
a ClassCastException
will be thrown.
keyedPool
- the keyedPool to enforce type safety on
KeyedObjectPool
that will only allow objects of type
public static ObjectPool checkedPool(ObjectPool pool, java.lang.Class type)
ObjectPool
and dynamically checks the type of objects borrowed and returned to the keyedPool.
If an object is passed to the keyedPool that isn't of type type
a ClassCastException
will be thrown.
pool
- the keyedPool to enforce type safety on
ObjectPool
that will only allow objects of type
public static java.util.Map checkMinIdle(KeyedObjectPool keyedPool, java.util.Collection keys, int minIdle, long period) throws java.lang.IllegalArgumentException
Collection
keys
in the keyedPool.
At most one idle object will be added per period.
keyedPool
- the keyedPool to check periodically.keys
- a collection of keys to check the idle object count.minIdle
- if the KeyedObjectPool.getNumIdle(Object)
is less than this then add an idle object.period
- the frequency to check the number of idle objects in a keyedPool, see
Timer.schedule(TimerTask, long, long)
.
Map
of key and TimerTask
pairs that will periodically check the pools idle object count.
java.lang.IllegalArgumentException
- when keyedPool
, keys
, or any of the values in the
collection is null
or when minIdle
is negative or when period
isn't
valid for Timer.schedule(TimerTask, long, long)
.checkMinIdle(KeyedObjectPool, Object, int, long)
public static java.util.TimerTask checkMinIdle(KeyedObjectPool keyedPool, java.lang.Object key, int minIdle, long period) throws java.lang.IllegalArgumentException
KeyedObjectPool.addObject(Object)
then no more checks for that key
will be performed.
keyedPool
- the keyedPool to check periodically.key
- the key to check the idle count of.minIdle
- if the KeyedObjectPool.getNumIdle(Object)
is less than this then add an idle object.period
- the frequency to check the number of idle objects in a keyedPool, see
Timer.schedule(TimerTask, long, long)
.
TimerTask
that will periodically check the pools idle object count.
java.lang.IllegalArgumentException
- when keyedPool
, key
is null
or
when minIdle
is negative or when period
isn't
valid for Timer.schedule(TimerTask, long, long)
.public static java.util.TimerTask checkMinIdle(ObjectPool pool, int minIdle, long period) throws java.lang.IllegalArgumentException
ObjectPool.addObject()
then no more checks will be performed.
pool
- the keyedPool to check periodically.minIdle
- if the ObjectPool.getNumIdle()
is less than this then add an idle object.period
- the frequency to check the number of idle objects in a keyedPool, see
Timer.schedule(TimerTask, long, long)
.
TimerTask
that will periodically check the pools idle object count.
java.lang.IllegalArgumentException
- when keyedPool
is null
or
when minIdle
is negative or when period
isn't
valid for Timer.schedule(TimerTask, long, long)
.public static void prefill(KeyedObjectPool keyedPool, java.util.Collection keys, int count) throws java.lang.Exception, java.lang.IllegalArgumentException
addObject(Object)
on keyedPool
with each key in keys
for
count
number of times. This has the same effect as calling
prefill(KeyedObjectPool, Object, int)
for each key in the keys
collection.
keyedPool
- the keyedPool to prefill.keys
- Collection
of keys to add objects for.count
- the number of idle objects to add for each key
.
java.lang.Exception
- when KeyedObjectPool.addObject(Object)
fails.
java.lang.IllegalArgumentException
- when keyedPool
, keys
, or
any value in keys
is null
.prefill(KeyedObjectPool, Object, int)
public static void prefill(KeyedObjectPool keyedPool, java.lang.Object key, int count) throws java.lang.Exception, java.lang.IllegalArgumentException
addObject(Object)
on keyedPool
with key
count
number of times.
keyedPool
- the keyedPool to prefill.key
- the key to add objects for.count
- the number of idle objects to add for key
.
java.lang.Exception
- when KeyedObjectPool.addObject(Object)
fails.
java.lang.IllegalArgumentException
- when keyedPool
or key
is null
.public static void prefill(ObjectPool pool, int count) throws java.lang.Exception, java.lang.IllegalArgumentException
addObject()
on keyedPool
count
number of times.
pool
- the keyedPool to prefill.count
- the number of idle objects to add.
java.lang.Exception
- when ObjectPool.addObject()
fails.
java.lang.IllegalArgumentException
- when keyedPool
is null
.public static KeyedObjectPool synchronizedPool(KeyedObjectPool keyedPool)
keyedPool
- the KeyedObjectPool to be "wrapped" in a synchronized KeyedObjectPool.
public static ObjectPool synchronizedPool(ObjectPool pool)
pool
- the ObjectPool to be "wrapped" in a synchronized ObjectPool.
public static KeyedPoolableObjectFactory synchronizedPoolableFactory(KeyedPoolableObjectFactory keyedFactory)
keyedFactory
- the KeyedPoolableObjectFactory to be "wrapped" in a synchronized KeyedPoolableObjectFactory.
public static PoolableObjectFactory synchronizedPoolableFactory(PoolableObjectFactory factory)
factory
- the PoolableObjectFactory to be "wrapped" in a synchronized PoolableObjectFactory.
|
||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |