private static class PoolUtils.SynchronizedKeyedPooledObjectFactory<K,V> extends java.lang.Object implements KeyedPooledObjectFactory<K,V>
Note: This should not be used on pool implementations that already provide proper synchronization such as the pools provided in the Commons Pool library.
| Modifier and Type | Field and Description |
|---|---|
private KeyedPooledObjectFactory<K,V> |
keyedFactory
Wrapped factory
|
private java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock |
writeLock
Synchronization lock
|
| Constructor and Description |
|---|
SynchronizedKeyedPooledObjectFactory(KeyedPooledObjectFactory<K,V> keyedFactory)
Create a SynchronizedKeyedPoolableObjectFactory wrapping the given
factory.
|
| Modifier and Type | Method and Description |
|---|---|
void |
activateObject(K key,
PooledObject<V> p)
Reinitialize an instance to be returned by the pool.
|
void |
destroyObject(K key,
PooledObject<V> p)
Destroy an instance no longer needed by the pool.
|
PooledObject<V> |
makeObject(K key)
Create an instance that can be served by the pool and
wrap it in a
PooledObject to be managed by the pool. |
void |
passivateObject(K key,
PooledObject<V> p)
Uninitialize an instance to be returned to the idle object pool.
|
java.lang.String |
toString() |
boolean |
validateObject(K key,
PooledObject<V> p)
Ensures that the instance is safe to be returned by the pool.
|
private final java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock writeLock
private final KeyedPooledObjectFactory<K,V> keyedFactory
SynchronizedKeyedPooledObjectFactory(KeyedPooledObjectFactory<K,V> keyedFactory) throws java.lang.IllegalArgumentException
keyedFactory - underlying factory to wrapjava.lang.IllegalArgumentException - if the factory is nullpublic PooledObject<V> makeObject(K key) throws java.lang.Exception
PooledObject to be managed by the pool.makeObject in interface KeyedPooledObjectFactory<K,V>key - the key used when constructing the objectPooledObject wrapping an instance that can
be served by the pool.java.lang.Exception - if there is a problem creating a new instance,
this will be propagated to the code requesting an object.public void destroyObject(K key, PooledObject<V> p) throws java.lang.Exception
It is important for implementations of this method to be aware that there
is no guarantee about what state obj will be in and the
implementation should be prepared to handle unexpected errors.
Also, an implementation must take in to consideration that instances lost to the garbage collector may never be destroyed.
destroyObject in interface KeyedPooledObjectFactory<K,V>key - the key used when selecting the instancep - a PooledObject wrapping the instance to be destroyedjava.lang.Exception - should be avoided as it may be swallowed by
the pool implementation.KeyedPooledObjectFactory.validateObject(K, org.apache.commons.pool2.PooledObject<V>),
KeyedObjectPool.invalidateObject(K, V)public boolean validateObject(K key, PooledObject<V> p)
validateObject in interface KeyedPooledObjectFactory<K,V>key - the key used when selecting the objectp - a PooledObject wrapping the instance to be validatedfalse if obj is not valid and should
be dropped from the pool, true otherwise.public void activateObject(K key, PooledObject<V> p) throws java.lang.Exception
activateObject in interface KeyedPooledObjectFactory<K,V>key - the key used when selecting the objectp - a PooledObject wrapping the instance to be activatedjava.lang.Exception - if there is a problem activating obj,
this exception may be swallowed by the pool.KeyedPooledObjectFactory.destroyObject(K, org.apache.commons.pool2.PooledObject<V>)public void passivateObject(K key, PooledObject<V> p) throws java.lang.Exception
passivateObject in interface KeyedPooledObjectFactory<K,V>key - the key used when selecting the objectp - a PooledObject wrapping the instance to be passivatedjava.lang.Exception - if there is a problem passivating obj,
this exception may be swallowed by the pool.KeyedPooledObjectFactory.destroyObject(K, org.apache.commons.pool2.PooledObject<V>)public java.lang.String toString()
toString in class java.lang.Object