Class BaseKeyedObjectPool<K,V>
- java.lang.Object
-
- org.apache.commons.pool.BaseKeyedObjectPool<K,V>
-
- Type Parameters:
K
- the type of keys in this poolV
- the type of objects held in this pool
- All Implemented Interfaces:
KeyedObjectPool<K,V>
- Direct Known Subclasses:
GenericKeyedObjectPool
,StackKeyedObjectPool
public abstract class BaseKeyedObjectPool<K,V> extends Object implements KeyedObjectPool<K,V>
A simple base implementation ofKeyedObjectPool
. Optional operations are implemented to either do nothing, return a value indicating it is unsupported or throwUnsupportedOperationException
.- Since:
- Pool 1.0
- Version:
- $Revision: 1222396 $ $Date: 2011-12-22 14:02:25 -0500 (Thu, 22 Dec 2011) $
- Author:
- Rodney Waldhoff, Sandy McArthur
-
-
Constructor Summary
Constructors Constructor Description BaseKeyedObjectPool()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
addObject(K key)
Not supported in this base implementation.abstract V
borrowObject(K key)
Obtains an instance from this pool for the specifiedkey
.void
clear()
Not supported in this base implementation.void
clear(K key)
Not supported in this base implementation.void
close()
Close this pool.int
getNumActive()
Not supported in this base implementation.int
getNumActive(K key)
Not supported in this base implementation.int
getNumIdle()
Not supported in this base implementation.int
getNumIdle(K key)
Not supported in this base implementation.abstract void
invalidateObject(K key, V obj)
Invalidates an object from the pool.abstract void
returnObject(K key, V obj)
Return an instance to the pool.
-
-
-
Method Detail
-
borrowObject
public abstract V borrowObject(K key) throws Exception
Obtains an instance from this pool for the specifiedkey
.Instances returned from this method will have been either newly created with
makeObject
or will be a previously idle object and have been activated withactivateObject
and then validated withvalidateObject
.By contract, clients must return the borrowed object using
returnObject
,invalidateObject
, or a related method as defined in an implementation or sub-interface, using akey
that isequivalent
to the one used to borrow the instance in the first place.The behaviour of this method when the pool has been exhausted is not strictly specified (although it may be specified by implementations). Older versions of this method would return
null
to indicate exhaustion, newer versions are encouraged to throw aNoSuchElementException
.- Specified by:
borrowObject
in interfaceKeyedObjectPool<K,V>
- Parameters:
key
- the key used to obtain the object- Returns:
- an instance from this pool.
- Throws:
IllegalStateException
- afterclose
has been called on this poolException
- whenmakeObject
throws an exceptionNoSuchElementException
- when the pool is exhausted and cannot or will not return another instance
-
returnObject
public abstract void returnObject(K key, V obj) throws Exception
Return an instance to the pool. By contract,obj
must have been obtained usingborrowObject
or a related method as defined in an implementation or sub-interface using akey
that is equivalent to the one used to borrow the instance in the first place.- Specified by:
returnObject
in interfaceKeyedObjectPool<K,V>
- Parameters:
key
- the key used to obtain the objectobj
- aborrowed
instance to be returned.- Throws:
Exception
-
invalidateObject
public abstract void invalidateObject(K key, V obj) throws Exception
Invalidates an object from the pool.
By contract,
obj
must have been obtained usingborrowObject
using akey
that is equivalent to the one used to borrow theObject
in the first place.This method should be used when an object that has been borrowed is determined (due to an exception or other problem) to be invalid.
- Specified by:
invalidateObject
in interfaceKeyedObjectPool<K,V>
- Parameters:
key
- the key used to obtain the objectobj
- aborrowed
instance to be returned.- Throws:
Exception
-
addObject
public void addObject(K key) throws Exception, UnsupportedOperationException
Not supported in this base implementation. Always throws anUnsupportedOperationException
, subclasses should override this behavior.- Specified by:
addObject
in interfaceKeyedObjectPool<K,V>
- Parameters:
key
- ignored- Throws:
UnsupportedOperationException
Exception
- whenKeyedPoolableObjectFactory.makeObject(K)
fails.IllegalStateException
- afterKeyedObjectPool.close()
has been called on this pool.
-
getNumIdle
public int getNumIdle(K key) throws UnsupportedOperationException
Not supported in this base implementation.- Specified by:
getNumIdle
in interfaceKeyedObjectPool<K,V>
- Parameters:
key
- ignored- Returns:
- a negative value.
- Throws:
UnsupportedOperationException
- deprecated: when this implementation doesn't support the operation
-
getNumActive
public int getNumActive(K key) throws UnsupportedOperationException
Not supported in this base implementation.- Specified by:
getNumActive
in interfaceKeyedObjectPool<K,V>
- Parameters:
key
- ignored- Returns:
- a negative value.
- Throws:
UnsupportedOperationException
- deprecated: when this implementation doesn't support the operation
-
getNumIdle
public int getNumIdle() throws UnsupportedOperationException
Not supported in this base implementation.- Specified by:
getNumIdle
in interfaceKeyedObjectPool<K,V>
- Returns:
- a negative value.
- Throws:
UnsupportedOperationException
- deprecated: when this implementation doesn't support the operation
-
getNumActive
public int getNumActive() throws UnsupportedOperationException
Not supported in this base implementation.- Specified by:
getNumActive
in interfaceKeyedObjectPool<K,V>
- Returns:
- a negative value.
- Throws:
UnsupportedOperationException
- deprecated: when this implementation doesn't support the operation
-
clear
public void clear() throws Exception, UnsupportedOperationException
Not supported in this base implementation.- Specified by:
clear
in interfaceKeyedObjectPool<K,V>
- Throws:
UnsupportedOperationException
Exception
-
clear
public void clear(K key) throws Exception, UnsupportedOperationException
Not supported in this base implementation.- Specified by:
clear
in interfaceKeyedObjectPool<K,V>
- Parameters:
key
- ignored- Throws:
UnsupportedOperationException
Exception
-
-