org.apache.commons.pool
public final class PoolUtils extends Object
Since: Pool 1.3
Version: $Revision: 385296 $ $Date: 2006-03-12 10:28:08 -0500 (Sun, 12 Mar 2006) $
Constructor Summary | |
---|---|
PoolUtils()
PoolUtils instances should NOT be constructed in standard programming.
|
Method Summary | |
---|---|
static PoolableObjectFactory | adapt(KeyedPoolableObjectFactory keyedFactory)
Adapt a KeyedPoolableObjectFactory instance to work where a PoolableObjectFactory is
needed. |
static PoolableObjectFactory | adapt(KeyedPoolableObjectFactory keyedFactory, Object key)
Adapt a KeyedPoolableObjectFactory instance to work where a PoolableObjectFactory is
needed using the specified key when delegating.
|
static KeyedPoolableObjectFactory | adapt(PoolableObjectFactory factory)
Adapt a PoolableObjectFactory instance to work where a KeyedPoolableObjectFactory is
needed. |
static ObjectPool | adapt(KeyedObjectPool keyedPool)
Adapt a KeyedObjectPool instance to work where an ObjectPool is needed. |
static ObjectPool | adapt(KeyedObjectPool keyedPool, Object key)
Adapt a KeyedObjectPool instance to work where an ObjectPool is needed using the
specified key when delegating.
|
static KeyedObjectPool | adapt(ObjectPool pool)
Adapt an ObjectPool to work where an KeyedObjectPool is needed.
|
static ObjectPool | checkedPool(ObjectPool pool, Class type)
Wraps an ObjectPool and dynamically checks the type of objects borrowed and returned to the keyedPool.
|
static KeyedObjectPool | checkedPool(KeyedObjectPool keyedPool, Class type)
Wraps an KeyedObjectPool and dynamically checks the type of objects borrowed and returned to the keyedPool.
|
static TimerTask | checkMinIdle(ObjectPool pool, int minIdle, long period)
Periodically check the idle object count for the keyedPool. |
static TimerTask | checkMinIdle(KeyedObjectPool keyedPool, Object key, int minIdle, long period)
Periodically check the idle object count for the key in the keyedPool. |
static Map | checkMinIdle(KeyedObjectPool keyedPool, Collection keys, int minIdle, long period)
Periodically check the idle object count for each key in the Collection keys in the keyedPool.
|
static void | prefill(ObjectPool pool, int count)
Call addObject() on keyedPool count number of times.
|
static void | prefill(KeyedObjectPool keyedPool, Object key, int count)
Call addObject(Object) on keyedPool with key count
number of times.
|
static void | prefill(KeyedObjectPool keyedPool, Collection keys, int count)
Call addObject(Object) on keyedPool with each key in keys for
count number of times. |
static ObjectPool | synchronizedPool(ObjectPool pool)
Returns a synchronized (thread-safe) ObjectPool backed by the specified ObjectPool.
|
static KeyedObjectPool | synchronizedPool(KeyedObjectPool keyedPool)
Returns a synchronized (thread-safe) KeyedObjectPool backed by the specified KeyedObjectPool.
|
static PoolableObjectFactory | synchronizedPoolableFactory(PoolableObjectFactory factory)
Returns a synchronized (thread-safe) PoolableObjectFactory backed by the specified PoolableObjectFactory.
|
static KeyedPoolableObjectFactory | synchronizedPoolableFactory(KeyedPoolableObjectFactory keyedFactory)
Returns a synchronized (thread-safe) KeyedPoolableObjectFactory backed by the specified KeyedPoolableObjectFactory.
|
KeyedPoolableObjectFactory
instance to work where a PoolableObjectFactory
is
needed. This method is the equivalent of calling
{@link #adapt(KeyedPoolableObjectFactory, Object) PoolUtils.adapt(aKeyedPoolableObjectFactory, new Object())}.
Parameters: keyedFactory the {@link KeyedPoolableObjectFactory} to delegate to.
Returns: a {@link PoolableObjectFactory} that delegates to keyedFactory
with an internal key.
Throws: IllegalArgumentException when keyedFactory
is null
.
Since: Pool 1.3
See Also: PoolUtils
KeyedPoolableObjectFactory
instance to work where a PoolableObjectFactory
is
needed using the specified key
when delegating.
Parameters: keyedFactory the {@link KeyedPoolableObjectFactory} to delegate to. key the key to use when delegating.
Returns: a {@link PoolableObjectFactory} that delegates to keyedFactory
with the specified key.
Throws: IllegalArgumentException when keyedFactory
or key
is null
.
Since: Pool 1.3
See Also: adapt
PoolableObjectFactory
instance to work where a KeyedPoolableObjectFactory
is
needed. The key is ignored.
Parameters: factory the {@link PoolableObjectFactory} to delegate to.
Returns: a {@link KeyedPoolableObjectFactory} that delegates to factory
ignoring the key.
Throws: IllegalArgumentException when factory
is null
.
Since: Pool 1.3
KeyedObjectPool
instance to work where an ObjectPool
is needed. This is the
equivalent of calling {@link #adapt(KeyedObjectPool, Object) PoolUtils.adapt(aKeyedObjectPool, new Object())}.
Parameters: keyedPool the {@link KeyedObjectPool} to delegate to.
Returns: an {@link ObjectPool} that delegates to keyedPool
with an internal key.
Throws: IllegalArgumentException when keyedPool
is null
.
Since: Pool 1.3
See Also: PoolUtils
KeyedObjectPool
instance to work where an ObjectPool
is needed using the
specified key
when delegating.
Parameters: keyedPool the {@link KeyedObjectPool} to delegate to. key the key to use when delegating.
Returns: an {@link ObjectPool} that delegates to keyedPool
with the specified key.
Throws: IllegalArgumentException when keyedPool
or key
is null
.
Since: Pool 1.3
See Also: adapt
ObjectPool
to work where an KeyedObjectPool
is needed.
The key is ignored.
Parameters: pool the {@link ObjectPool} to delegate to.
Returns: a {@link KeyedObjectPool} that delegates to keyedPool
ignoring the key.
Throws: IllegalArgumentException when keyedPool
is null
.
Since: Pool 1.3
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 {@link ClassCastException} will be thrown.
Parameters: pool the keyedPool to enforce type safety on
Returns: an ObjectPool
that will only allow objects of type
Since: Pool 1.3
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 {@link ClassCastException} will be thrown.
Parameters: keyedPool the keyedPool to enforce type safety on
Returns: an KeyedObjectPool
that will only allow objects of type
Since: Pool 1.3
Parameters: pool the keyedPool to check periodically. minIdle if the {@link 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 {@link Timer#schedule(TimerTask, long, long)}.
Returns: the {@link TimerTask} that will periodically check the pools idle object count.
Throws: IllegalArgumentException when keyedPool
is null
or
when minIdle
is negative or when period
isn't
valid for {@link Timer#schedule(TimerTask, long, long)}.
Since: Pool 1.3
Parameters: keyedPool the keyedPool to check periodically. key the key to check the idle count of. minIdle if the {@link 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 {@link Timer#schedule(TimerTask, long, long)}.
Returns: the {@link TimerTask} that will periodically check the pools idle object count.
Throws: IllegalArgumentException when keyedPool
, key
is null
or
when minIdle
is negative or when period
isn't
valid for {@link Timer#schedule(TimerTask, long, long)}.
Since: Pool 1.3
Collection
keys
in the keyedPool.
At most one idle object will be added per period.
Parameters: keyedPool the keyedPool to check periodically. keys a collection of keys to check the idle object count. minIdle if the {@link 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 {@link Timer#schedule(TimerTask, long, long)}.
Returns: a {@link Map} of key and {@link TimerTask} pairs that will periodically check the pools idle object count.
Throws: 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 {@link Timer#schedule(TimerTask, long, long)}.
Since: Pool 1.3
See Also: PoolUtils
addObject()
on keyedPool
count
number of times.
Parameters: pool the keyedPool to prefill. count the number of idle objects to add.
Throws: Exception when {@link ObjectPool#addObject()} fails. IllegalArgumentException when keyedPool
is null
.
Since: Pool 1.3
addObject(Object)
on keyedPool
with key
count
number of times.
Parameters: keyedPool the keyedPool to prefill. key the key to add objects for. count the number of idle objects to add for key
.
Throws: Exception when {@link KeyedObjectPool#addObject(Object)} fails. IllegalArgumentException when keyedPool
or key
is null
.
Since: Pool 1.3
addObject(Object)
on keyedPool
with each key in keys
for
count
number of times. This has the same effect as calling
{@link #prefill(KeyedObjectPool, Object, int)} for each key in the keys
collection.
Parameters: keyedPool the keyedPool to prefill. keys {@link Collection} of keys to add objects for. count the number of idle objects to add for each key
.
Throws: Exception when {@link KeyedObjectPool#addObject(Object)} fails. IllegalArgumentException when keyedPool
, keys
, or
any value in keys
is null
.
Since: Pool 1.3
See Also: PoolUtils
Parameters: pool the ObjectPool to be "wrapped" in a synchronized ObjectPool.
Returns: a synchronized view of the specified ObjectPool.
Since: Pool 1.3
Parameters: keyedPool the KeyedObjectPool to be "wrapped" in a synchronized KeyedObjectPool.
Returns: a synchronized view of the specified KeyedObjectPool.
Since: Pool 1.3
Parameters: factory the PoolableObjectFactory to be "wrapped" in a synchronized PoolableObjectFactory.
Returns: a synchronized view of the specified PoolableObjectFactory.
Since: Pool 1.3
Parameters: keyedFactory the KeyedPoolableObjectFactory to be "wrapped" in a synchronized KeyedPoolableObjectFactory.
Returns: a synchronized view of the specified KeyedPoolableObjectFactory.
Since: Pool 1.3