Class 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
KeyedObjectPool
.
Optional operations are implemented to either do nothing, return a value
indicating it is unsupported or throw UnsupportedOperationException
.- 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 -
Method Summary
Modifier and TypeMethodDescriptionvoid
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
Not supported in this base implementation.void
close()
Close this pool.int
Not supported in this base implementation.int
getNumActive
(K key) Not supported in this base implementation.int
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.
-
Constructor Details
-
BaseKeyedObjectPool
public BaseKeyedObjectPool()
-
-
Method Details
-
borrowObject
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
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
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
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
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
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
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
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
Not supported in this base implementation.- Specified by:
clear
in interfaceKeyedObjectPool<K,
V> - Throws:
UnsupportedOperationException
Exception
-
clear
Not supported in this base implementation.- Specified by:
clear
in interfaceKeyedObjectPool<K,
V> - Parameters:
key
- ignored- Throws:
UnsupportedOperationException
Exception
-
close
Close this pool. This affects the behavior ofisClosed
andassertOpen
.- Specified by:
close
in interfaceKeyedObjectPool<K,
V> - Throws:
Exception
-