Package org.apache.commons.pool2
Class BaseKeyedPooledObjectFactory<K,V>
java.lang.Object
org.apache.commons.pool2.BaseObject
org.apache.commons.pool2.BaseKeyedPooledObjectFactory<K,V>
- Type Parameters:
K
- The type of keys managed by this factory.V
- Type of element managed by this factory.
- All Implemented Interfaces:
KeyedPooledObjectFactory<K,
V>
public abstract class BaseKeyedPooledObjectFactory<K,V>
extends BaseObject
implements KeyedPooledObjectFactory<K,V>
A base implementation of
KeyedPooledObjectFactory
.
All operations defined here are essentially no-op's.
This class is immutable, and therefore thread-safe.
- Since:
- 2.0
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
activateObject
(K key, PooledObject<V> p) Reinitializes an instance to be returned by the pool.abstract V
Creates an instance that can be served by the pool.void
destroyObject
(K key, PooledObject<V> p) Destroys an instance no longer needed by the pool.makeObject
(K key) Creates 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) Uninitializes an instance to be returned to the idle object pool.boolean
validateObject
(K key, PooledObject<V> p) Ensures that the instance is safe to be returned by the pool.abstract PooledObject<V>
Wraps the provided instance with an implementation ofPooledObject
.Methods inherited from class org.apache.commons.pool2.BaseObject
toString, toStringAppendFields
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.apache.commons.pool2.KeyedPooledObjectFactory
destroyObject
-
Constructor Details
-
BaseKeyedPooledObjectFactory
public BaseKeyedPooledObjectFactory()
-
-
Method Details
-
activateObject
Reinitializes an instance to be returned by the pool.The default implementation is a no-op.
- 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:
-
create
Creates an instance that can be served by the pool.- Parameters:
key
- the key used when constructing the object- Returns:
- 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
Destroys an instance no longer needed by the pool.The default implementation is a no-op.
- 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:
-
makeObject
Description copied from interface:KeyedPooledObjectFactory
Creates 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.
-
passivateObject
Uninitializes an instance to be returned to the idle object pool.The default implementation is a no-op.
- 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:
-
validateObject
Ensures that the instance is safe to be returned by the pool.The default implementation always returns
true
.- Specified by:
validateObject
in interfaceKeyedPooledObjectFactory<K,
V> - Parameters:
key
- the key used when selecting the objectp
- aPooledObject
wrapping the instance to be validated- Returns:
- always
true
in this default implementation
-
wrap
Wraps the provided instance with an implementation ofPooledObject
.- Parameters:
value
- the instance to wrap, should not be null.- Returns:
- The provided instance, wrapped by a
PooledObject
-