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 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
FieldsModifier and TypeFieldDescriptionprivate final KeyedPooledObjectFactory
<K, V> Wrapped factoryprivate final ReentrantReadWriteLock.WriteLock
Synchronization lock -
Constructor Summary
ConstructorsConstructorDescriptionSynchronizedKeyedPooledObjectFactory
(KeyedPooledObjectFactory<K, V> keyedFactory) Creates a SynchronizedKeyedPoolableObjectFactory wrapping the given factory. -
Method Summary
Modifier and TypeMethodDescriptionvoid
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.makeObject
(K key) Create an instance that can be served by the pool and wrap it in aPooledObject
to be managed by the pool.void
passivateObject
(K key, PooledObject<V> p) Uninitialize an instance to be returned to the idle object pool.toString()
boolean
validateObject
(K key, PooledObject<V> p) Ensures that the instance is safe to be returned by the pool.
-
Field Details
-
writeLock
Synchronization lock -
keyedFactory
Wrapped factory
-
-
Constructor Details
-
SynchronizedKeyedPooledObjectFactory
SynchronizedKeyedPooledObjectFactory(KeyedPooledObjectFactory<K, V> keyedFactory) throws IllegalArgumentExceptionCreates a SynchronizedKeyedPoolableObjectFactory wrapping the given factory.- Parameters:
keyedFactory
- underlying factory to wrap- Throws:
IllegalArgumentException
- if the factory is null
-
-
Method Details
-
makeObject
Create an instance that can be served by the pool and wrap it in aPooledObject
to be managed by the pool.- Specified by:
makeObject
in interfaceKeyedPooledObjectFactory<K,
V> - Parameters:
key
- the key used when constructing the object- Returns:
- a
PooledObject
wrapping an instance that can be served by the pool. - Throws:
Exception
- if there is a problem creating a new instance, this will be propagated to the code requesting an object.
-
destroyObject
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
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.
- Specified by:
destroyObject
in interfaceKeyedPooledObjectFactory<K,
V> - Parameters:
key
- the key used when selecting the instancep
- aPooledObject
wrapping the instance to be destroyed- Throws:
Exception
- should be avoided as it may be swallowed by the pool implementation.- See Also:
-
validateObject
Ensures that the instance is safe to be returned by the pool.- Specified by:
validateObject
in interfaceKeyedPooledObjectFactory<K,
V> - Parameters:
key
- the key used when selecting the objectp
- aPooledObject
wrapping the instance to be validated- Returns:
false
ifobj
is not valid and should be dropped from the pool,true
otherwise.
-
activateObject
Reinitialize an instance to be returned by the pool.- Specified by:
activateObject
in interfaceKeyedPooledObjectFactory<K,
V> - Parameters:
key
- the key used when selecting the objectp
- aPooledObject
wrapping the instance to be activated- Throws:
Exception
- if there is a problem activatingobj
, this exception may be swallowed by the pool.- See Also:
-
passivateObject
Uninitialize an instance to be returned to the idle object pool.- Specified by:
passivateObject
in interfaceKeyedPooledObjectFactory<K,
V> - Parameters:
key
- the key used when selecting the objectp
- aPooledObject
wrapping the instance to be passivated- Throws:
Exception
- if there is a problem passivatingobj
, this exception may be swallowed by the pool.- See Also:
-
toString
-