private static class PoolUtils.KeyedObjectPoolAdaptor<K,V> extends java.lang.Object implements KeyedObjectPool<K,V>
Modifier and Type | Field and Description |
---|---|
private ObjectPool<V> |
pool
Underlying pool
|
Constructor and Description |
---|
KeyedObjectPoolAdaptor(ObjectPool<V> pool)
Create a new KeyedObjectPoolAdaptor wrapping the given ObjectPool
|
Modifier and Type | Method and Description |
---|---|
void |
addObject(K key)
Add an object to the pool, ignoring the key
|
V |
borrowObject(K key)
Borrow and object from the pool, ignoring the key
|
void |
clear()
Clears the pool, removing all pooled instances (optional operation).
|
void |
clear(K key)
Clear the pool, ignoring the key (has same effect as
clear() . |
void |
close()
Close this pool, and free any resources associated with it.
|
int |
getNumActive()
Returns the total number of instances
current borrowed from this pool but not
yet returned (optional operation).
|
int |
getNumActive(K key)
Return the number of objects checked out from the pool, ignoring the key.
|
int |
getNumIdle()
Returns the total number of instances
currently idle in this pool (optional operation).
|
int |
getNumIdle(K key)
Return the number of objects idle in the pool, ignoring the key.
|
void |
invalidateObject(K key,
V obj)
Invalidate and object, ignoring the key
|
void |
returnObject(K key,
V obj)
Return and object to the pool, ignoring the key
|
void |
setFactory(KeyedPoolableObjectFactory<K,V> factory)
Deprecated.
to be removed in version 2.0
|
java.lang.String |
toString() |
private final ObjectPool<V> pool
KeyedObjectPoolAdaptor(ObjectPool<V> pool) throws java.lang.IllegalArgumentException
pool
- underlying object pooljava.lang.IllegalArgumentException
- if pool is nullpublic V borrowObject(K key) throws java.lang.Exception, java.util.NoSuchElementException, java.lang.IllegalStateException
borrowObject
in interface KeyedObjectPool<K,V>
key
- ignoredjava.lang.IllegalStateException
- after close
has been called on this pooljava.lang.Exception
- when makeObject
throws an exceptionjava.util.NoSuchElementException
- when the pool is exhausted and cannot or will not return another instancepublic void returnObject(K key, V obj)
returnObject
in interface KeyedObjectPool<K,V>
key
- ignoredobj
- object to returnpublic void invalidateObject(K key, V obj)
invalidateObject
in interface KeyedObjectPool<K,V>
obj
- object to invalidatekey
- ignoredpublic void addObject(K key) throws java.lang.Exception, java.lang.IllegalStateException
addObject
in interface KeyedObjectPool<K,V>
key
- ignoredjava.lang.Exception
- when KeyedPoolableObjectFactory.makeObject(K)
fails.java.lang.IllegalStateException
- after KeyedObjectPool.close()
has been called on this pool.java.lang.UnsupportedOperationException
- when this pool cannot add new idle objects.public int getNumIdle(K key) throws java.lang.UnsupportedOperationException
getNumIdle
in interface KeyedObjectPool<K,V>
key
- ignoredjava.lang.UnsupportedOperationException
- deprecated: when this implementation doesn't support the operationpublic int getNumActive(K key) throws java.lang.UnsupportedOperationException
getNumActive
in interface KeyedObjectPool<K,V>
key
- ignoredjava.lang.UnsupportedOperationException
- deprecated: when this implementation doesn't support the operationpublic int getNumIdle() throws java.lang.UnsupportedOperationException
getNumIdle
in interface KeyedObjectPool<K,V>
java.lang.UnsupportedOperationException
- deprecated: when this implementation doesn't support the operationpublic int getNumActive() throws java.lang.UnsupportedOperationException
getNumActive
in interface KeyedObjectPool<K,V>
java.lang.UnsupportedOperationException
- deprecated: when this implementation doesn't support the operationpublic void clear() throws java.lang.Exception, java.lang.UnsupportedOperationException
UnsupportedOperationException
if the pool cannot be cleared.clear
in interface KeyedObjectPool<K,V>
java.lang.UnsupportedOperationException
- when this implementation doesn't support the operationjava.lang.Exception
public void clear(K key) throws java.lang.Exception, java.lang.UnsupportedOperationException
clear()
.clear
in interface KeyedObjectPool<K,V>
key
- ignored.java.lang.UnsupportedOperationException
- when this implementation doesn't support the operationjava.lang.Exception
public void close()
Calling addObject
or borrowObject
after invoking
this method on a pool will cause them to throw an IllegalStateException
.
close
in interface KeyedObjectPool<K,V>
@Deprecated public void setFactory(KeyedPoolableObjectFactory<K,V> factory) throws java.lang.IllegalStateException, java.lang.UnsupportedOperationException
setFactory
in interface KeyedObjectPool<K,V>
factory
- new factory to use managing object instancesjava.lang.IllegalStateException
- when the factory cannot be set at this timejava.lang.UnsupportedOperationException
- when this implementation doesn't support the operationpublic java.lang.String toString()
toString
in class java.lang.Object