Class PoolUtils.SynchronizedKeyedPooledObjectFactory<K,V>
- java.lang.Object
-
- org.datanucleus.store.rdbms.datasource.dbcp2.pool2.PoolUtils.SynchronizedKeyedPooledObjectFactory<K,V>
-
- Type Parameters:
K- pooled object factory key typeV- pooled object factory key value
- All Implemented Interfaces:
KeyedPooledObjectFactory<K,V>
- Enclosing class:
- PoolUtils
private static final class PoolUtils.SynchronizedKeyedPooledObjectFactory<K,V> extends java.lang.Object implements KeyedPooledObjectFactory<K,V>
A fully synchronized KeyedPooledObjectFactory that wraps a KeyedPooledObjectFactory and synchronizes access to the wrapped factory methods.Note: This should not be used on pool implementations that already provide proper synchronization such as the pools provided in the Commons Pool library.
-
-
Field Summary
Fields Modifier and Type Field Description private KeyedPooledObjectFactory<K,V>keyedFactoryWrapped factoryprivate java.util.concurrent.locks.ReentrantReadWriteLock.WriteLockwriteLockSynchronization lock
-
Constructor Summary
Constructors Constructor Description SynchronizedKeyedPooledObjectFactory(KeyedPooledObjectFactory<K,V> keyedFactory)Creates a SynchronizedKeyedPoolableObjectFactory wrapping the given factory.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidactivateObject(K key, PooledObject<V> p)Reinitialize an instance to be returned by the pool.voiddestroyObject(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 aPooledObjectto be managed by the pool.voidpassivateObject(K key, PooledObject<V> p)Uninitialize an instance to be returned to the idle object pool.java.lang.StringtoString()booleanvalidateObject(K key, PooledObject<V> p)Ensures that the instance is safe to be returned by the pool.
-
-
-
Field Detail
-
writeLock
private final java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock writeLock
Synchronization lock
-
keyedFactory
private final KeyedPooledObjectFactory<K,V> keyedFactory
Wrapped factory
-
-
Constructor Detail
-
SynchronizedKeyedPooledObjectFactory
SynchronizedKeyedPooledObjectFactory(KeyedPooledObjectFactory<K,V> keyedFactory) throws java.lang.IllegalArgumentException
Creates a SynchronizedKeyedPoolableObjectFactory wrapping the given factory.- Parameters:
keyedFactory- underlying factory to wrap- Throws:
java.lang.IllegalArgumentException- if the factory is null
-
-
Method Detail
-
makeObject
public PooledObject<V> makeObject(K key) throws java.lang.Exception
Create an instance that can be served by the pool and wrap it in aPooledObjectto be managed by the pool.- Specified by:
makeObjectin interfaceKeyedPooledObjectFactory<K,V>- Parameters:
key- the key used when constructing the object- Returns:
- a
PooledObjectwrapping an instance that can be served by the pool. - Throws:
java.lang.Exception- if there is a problem creating a new instance, this will be propagated to the code requesting an object.
-
destroyObject
public void destroyObject(K key, PooledObject<V> p) throws java.lang.Exception
Destroy an instance no longer needed by the pool.It is important for implementations of this method to be aware that there is no guarantee about what state
objwill 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.
- Specified by:
destroyObjectin interfaceKeyedPooledObjectFactory<K,V>- Parameters:
key- the key used when selecting the instancep- aPooledObjectwrapping the instance to be destroyed- Throws:
java.lang.Exception- should be avoided as it may be swallowed by the pool implementation.- See Also:
KeyedPooledObjectFactory.validateObject(K, org.datanucleus.store.rdbms.datasource.dbcp2.pool2.PooledObject<V>),KeyedObjectPool.invalidateObject(K, V)
-
validateObject
public boolean validateObject(K key, PooledObject<V> p)
Ensures that the instance is safe to be returned by the pool.- Specified by:
validateObjectin interfaceKeyedPooledObjectFactory<K,V>- Parameters:
key- the key used when selecting the objectp- aPooledObjectwrapping the instance to be validated- Returns:
falseifobjis not valid and should be dropped from the pool,trueotherwise.
-
activateObject
public void activateObject(K key, PooledObject<V> p) throws java.lang.Exception
Reinitialize an instance to be returned by the pool.- Specified by:
activateObjectin interfaceKeyedPooledObjectFactory<K,V>- Parameters:
key- the key used when selecting the objectp- aPooledObjectwrapping the instance to be activated- Throws:
java.lang.Exception- if there is a problem activatingobj, this exception may be swallowed by the pool.- See Also:
KeyedPooledObjectFactory.destroyObject(K, org.datanucleus.store.rdbms.datasource.dbcp2.pool2.PooledObject<V>)
-
passivateObject
public void passivateObject(K key, PooledObject<V> p) throws java.lang.Exception
Uninitialize an instance to be returned to the idle object pool.- Specified by:
passivateObjectin interfaceKeyedPooledObjectFactory<K,V>- Parameters:
key- the key used when selecting the objectp- aPooledObjectwrapping the instance to be passivated- Throws:
java.lang.Exception- if there is a problem passivatingobj, this exception may be swallowed by the pool.- See Also:
KeyedPooledObjectFactory.destroyObject(K, org.datanucleus.store.rdbms.datasource.dbcp2.pool2.PooledObject<V>)
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-