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) $
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Not supported in this base implementation.protected final void
Throws anIllegalStateException
when this pool has been closed.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.protected final boolean
isClosed()
Has this pool instance been closed.abstract void
returnObject
(K key, V obj) Return an instance to the pool.void
setFactory
(KeyedPoolableObjectFactory<K, V> factory) Deprecated.to be removed in pool 2.0
-
Field Details
-
closed
private volatile boolean closedWhether or not the pool is close
-
-
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:
Exception
- whenmakeObject
throws an exception
-
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.
-
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
-
setFactory
@Deprecated public void setFactory(KeyedPoolableObjectFactory<K, V> factory) throws IllegalStateException, UnsupportedOperationExceptionDeprecated.to be removed in pool 2.0Not supported in this base implementation. Always throws anUnsupportedOperationException
, subclasses should override this behavior.- Specified by:
setFactory
in interfaceKeyedObjectPool<K,
V> - Parameters:
factory
- the new KeyedPoolableObjectFactory- Throws:
IllegalStateException
- when the factory cannot be set at this timeUnsupportedOperationException
- when this implementation doesn't support the operation
-
isClosed
protected final boolean isClosed()Has this pool instance been closed.- Returns:
true
when this pool has been closed.- Since:
- Pool 1.4
-
assertOpen
Throws anIllegalStateException
when this pool has been closed.- Throws:
IllegalStateException
- when this pool has been closed.- Since:
- Pool 1.4
- See Also:
-