Package org.apache.commons.pool
Class PoolUtils.PoolableObjectFactoryAdaptor<K,V>
- java.lang.Object
-
- org.apache.commons.pool.PoolUtils.PoolableObjectFactoryAdaptor<K,V>
-
- All Implemented Interfaces:
PoolableObjectFactory<V>
- Enclosing class:
- PoolUtils
private static class PoolUtils.PoolableObjectFactoryAdaptor<K,V> extends java.lang.Object implements PoolableObjectFactory<V>
Adaptor class that wraps and converts a KeyedPoolableObjectFactory with a fixed key to a PoolableObjectFactory.
-
-
Field Summary
Fields Modifier and Type Field Description private K
key
Fixed keyprivate KeyedPoolableObjectFactory<K,V>
keyedFactory
Wrapped factory
-
Constructor Summary
Constructors Constructor Description PoolableObjectFactoryAdaptor(KeyedPoolableObjectFactory<K,V> keyedFactory, K key)
Create a PoolableObjectFactoryAdaptor wrapping the provided KeyedPoolableObjectFactory with the given fixed key.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
activateObject(V obj)
Activate the object, passing the fixed key to the factory.void
destroyObject(V obj)
Destroy the object, passing the fixed key to the factory.V
makeObject()
Create an object instance using the configured factory and key.void
passivateObject(V obj)
Passivate the object, passing the fixed key to the factory.java.lang.String
toString()
boolean
validateObject(V obj)
Validate the object, passing the fixed key to the factory.
-
-
-
Field Detail
-
key
private final K key
Fixed key
-
keyedFactory
private final KeyedPoolableObjectFactory<K,V> keyedFactory
Wrapped factory
-
-
Constructor Detail
-
PoolableObjectFactoryAdaptor
PoolableObjectFactoryAdaptor(KeyedPoolableObjectFactory<K,V> keyedFactory, K key) throws java.lang.IllegalArgumentException
Create a PoolableObjectFactoryAdaptor wrapping the provided KeyedPoolableObjectFactory with the given fixed key.- Parameters:
keyedFactory
- KeyedPoolableObjectFactory that will manage objectskey
- fixed key- Throws:
java.lang.IllegalArgumentException
- if either of the parameters is null
-
-
Method Detail
-
makeObject
public V makeObject() throws java.lang.Exception
Create an object instance using the configured factory and key.- Specified by:
makeObject
in interfacePoolableObjectFactory<K>
- Returns:
- new object instance
- 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(V obj) throws java.lang.Exception
Destroy the object, passing the fixed key to the factory.- Specified by:
destroyObject
in interfacePoolableObjectFactory<K>
- Parameters:
obj
- object to destroy- Throws:
java.lang.Exception
- should be avoided as it may be swallowed by the pool implementation.- See Also:
PoolableObjectFactory.validateObject(T)
,ObjectPool.invalidateObject(T)
-
validateObject
public boolean validateObject(V obj)
Validate the object, passing the fixed key to the factory.- Specified by:
validateObject
in interfacePoolableObjectFactory<K>
- Parameters:
obj
- object to validate- Returns:
- true if validation is successful
-
activateObject
public void activateObject(V obj) throws java.lang.Exception
Activate the object, passing the fixed key to the factory.- Specified by:
activateObject
in interfacePoolableObjectFactory<K>
- Parameters:
obj
- object to activate- Throws:
java.lang.Exception
- if there is a problem activatingobj
, this exception may be swallowed by the pool.- See Also:
PoolableObjectFactory.destroyObject(T)
-
passivateObject
public void passivateObject(V obj) throws java.lang.Exception
Passivate the object, passing the fixed key to the factory.- Specified by:
passivateObject
in interfacePoolableObjectFactory<K>
- Parameters:
obj
- object to passivate- Throws:
java.lang.Exception
- if there is a problem passivatingobj
, this exception may be swallowed by the pool.- See Also:
PoolableObjectFactory.destroyObject(T)
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-