This class consists exclusively of static methods that operate on or return keyedPool related interfaces.
adapt
public static ObjectPool adapt(KeyedObjectPool keyedPool,
Object key)
throws IllegalArgumentException
Adapt a 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.
- an
ObjectPool
that delegates to keyedPool
with the specified key.
adapt
public static PoolableObjectFactory adapt(KeyedPoolableObjectFactory keyedFactory,
Object key)
throws IllegalArgumentException
Adapt a KeyedPoolableObjectFactory
instance to work where a PoolableObjectFactory
is
needed using the specified key
when delegating.
adapt
public static KeyedObjectPool adapt(ObjectPool pool)
throws IllegalArgumentException
Adapt an ObjectPool
to work where an KeyedObjectPool
is needed.
The key is ignored.
checkMinIdle
public static Map checkMinIdle(KeyedObjectPool keyedPool,
Collection keys,
int minIdle,
long period)
throws IllegalArgumentException
Periodically check the idle object count for each key in the 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)
.
- a
Map
of key and TimerTask
pairs that will periodically check the pools idle object count.
checkMinIdle
public static TimerTask checkMinIdle(KeyedObjectPool keyedPool,
Object key,
int minIdle,
long period)
throws IllegalArgumentException
Periodically check the idle object count for the key in the keyedPool. At most one idle object will be added per period.
If there is an exception when calling
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)
.
- the
TimerTask
that will periodically check the pools idle object count.
checkMinIdle
public static TimerTask checkMinIdle(ObjectPool pool,
int minIdle,
long period)
throws IllegalArgumentException
Periodically check the idle object count for the keyedPool. At most one idle object will be added per period.
If there is an exception when calling
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)
.
- the
TimerTask
that will periodically check the pools idle object count.
checkedPool
public static KeyedObjectPool checkedPool(KeyedObjectPool keyedPool,
Class type)
Wraps an 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
- an
KeyedObjectPool
that will only allow objects of type
checkedPool
public static ObjectPool checkedPool(ObjectPool pool,
Class type)
Wraps an 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
- an
ObjectPool
that will only allow objects of type
prefill
public static void prefill(KeyedObjectPool keyedPool,
Collection keys,
int count)
throws Exception,
IllegalArgumentException
Call
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
.
prefill
public static void prefill(KeyedObjectPool keyedPool,
Object key,
int count)
throws Exception,
IllegalArgumentException
Call 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
.
prefill
public static void prefill(ObjectPool pool,
int count)
throws Exception,
IllegalArgumentException
Call addObject()
on keyedPool
count
number of times.
pool
- the keyedPool to prefill.count
- the number of idle objects to add.
synchronizedPool
public static KeyedObjectPool synchronizedPool(KeyedObjectPool keyedPool)
Returns a synchronized (thread-safe) KeyedObjectPool backed by the specified KeyedObjectPool.
keyedPool
- the KeyedObjectPool to be "wrapped" in a synchronized KeyedObjectPool.
- a synchronized view of the specified KeyedObjectPool.
synchronizedPool
public static ObjectPool synchronizedPool(ObjectPool pool)
Returns a synchronized (thread-safe) ObjectPool backed by the specified ObjectPool.
pool
- the ObjectPool to be "wrapped" in a synchronized ObjectPool.
- a synchronized view of the specified ObjectPool.
synchronizedPoolableFactory
public static KeyedPoolableObjectFactory synchronizedPoolableFactory(KeyedPoolableObjectFactory keyedFactory)
Returns a synchronized (thread-safe) KeyedPoolableObjectFactory backed by the specified KeyedPoolableObjectFactory.
keyedFactory
- the KeyedPoolableObjectFactory to be "wrapped" in a synchronized KeyedPoolableObjectFactory.
- a synchronized view of the specified KeyedPoolableObjectFactory.
synchronizedPoolableFactory
public static PoolableObjectFactory synchronizedPoolableFactory(PoolableObjectFactory factory)
Returns a synchronized (thread-safe) PoolableObjectFactory backed by the specified PoolableObjectFactory.
factory
- the PoolableObjectFactory to be "wrapped" in a synchronized PoolableObjectFactory.
- a synchronized view of the specified PoolableObjectFactory.