Top Description Fields Constructors Methods
org.apache.commons.pool2.proxy

public Class ProxiedKeyedObjectPool<K, V>

extends Object
implements KeyedObjectPool<K, V>
Class Inheritance
All Implemented Interfaces
org.apache.commons.pool2.KeyedObjectPool, java.io.Closeable, java.lang.AutoCloseable
Type Parameters
<K>
type of the key
<V>
type of the pooled object
Imports
java.util.List, org.apache.commons.pool2.KeyedObjectPool, .UsageTracking

Create a new keyed object pool where the pooled objects are wrapped in proxies allowing better control of pooled objects and in particular the prevention of the continued use of an object by a client after that client returns the object to the pool.
Since
2.0

Field Summary

Modifier and TypeField and Description
private final KeyedObjectPool<K, V>
private final ProxySource<V>

Constructor Summary

AccessConstructor and Description
public
ProxiedKeyedObjectPool(final KeyedObjectPool<K, V>
The object pool to wrap
pool
,
final ProxySource<V>
The source of the proxy objects
proxySource
)

Constructs a new proxied object pool.

Method Summary

Modifier and TypeMethod and Description
public void
addObject(final K key)

Implements org.apache.commons.pool2.KeyedObjectPool.addObject.

Creates an object using the factory or other implementation dependent mechanism, passivate it, and then place it in the idle object pool.

public V
borrowObject(final K key)

Implements org.apache.commons.pool2.KeyedObjectPool.borrowObject.

Borrows an instance from this pool for the specified key.

public void
clear()

Implements org.apache.commons.pool2.KeyedObjectPool.clear.

Clears the pool, removing all pooled instances (optional operation).

public void
clear(final K key)

Implements org.apache.commons.pool2.KeyedObjectPool.clear.

Clears the specified pool, removing all pooled instances corresponding to the given key (optional operation).

public void
close()

Implements org.apache.commons.pool2.KeyedObjectPool.close.

Closes this pool, and free any resources associated with it.

public List<K>

Returns:

a copy of the pool key list.
getKeys
()

Overrides default org.apache.commons.pool2.KeyedObjectPool.getKeys.

Gets a copy of the pool key list.

public int
getNumActive()

Implements org.apache.commons.pool2.KeyedObjectPool.getNumActive.

Gets the total number of instances currently borrowed from this pool but not yet returned.

public int
getNumActive(final K key)

Implements org.apache.commons.pool2.KeyedObjectPool.getNumActive.

Gets the number of instances currently borrowed from but not yet returned to the pool corresponding to the given key.

public int
getNumIdle()

Implements org.apache.commons.pool2.KeyedObjectPool.getNumIdle.

Gets the total number of instances currently idle in this pool.

public int
getNumIdle(final K key)

Implements org.apache.commons.pool2.KeyedObjectPool.getNumIdle.

Gets the number of instances corresponding to the given key currently idle in this pool.

public void
invalidateObject(final K key, final V proxy)

Implements org.apache.commons.pool2.KeyedObjectPool.invalidateObject.

Invalidates an object from the pool.

public void
returnObject(final K key, final V proxy)

Implements org.apache.commons.pool2.KeyedObjectPool.returnObject.

Return an instance to the pool.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

poolback to summary
private final KeyedObjectPool<K, V> pool
proxySourceback to summary
private final ProxySource<V> proxySource

Constructor Detail

ProxiedKeyedObjectPoolback to summary
public ProxiedKeyedObjectPool(final KeyedObjectPool<K, V> pool, final ProxySource<V> proxySource)

Constructs a new proxied object pool.

Parameters
pool:KeyedObjectPool<K, V>

The object pool to wrap

proxySource:ProxySource<V>

The source of the proxy objects

Method Detail

addObjectback to summary
public void addObject(final K key) throws Exception

Implements org.apache.commons.pool2.KeyedObjectPool.addObject.

Doc from org.apache.commons.pool2.KeyedObjectPool.addObject.

Creates an object using the factory or other implementation dependent mechanism, passivate it, and then place it in the idle object pool. addObject is useful for "pre-loading" a pool with idle objects (Optional operation).

Annotations
@Override
Exceptions
Exception:
when KeyedPooledObjectFactory#makeObject fails.
borrowObjectback to summary
public V borrowObject(final K key) throws Exception

Implements org.apache.commons.pool2.KeyedObjectPool.borrowObject.

Doc from org.apache.commons.pool2.KeyedObjectPool.borrowObject.

Borrows an instance from this pool for the specified key.

Instances returned from this method will have been either newly created with makeObject or will be a previously idle object and have been activated with activateObject and then (optionally) validated with validateObject.

By contract, clients must return the borrowed object using returnObject, invalidateObject, or a related method as defined in an implementation or sub-interface, using a key that is equivalent to the one used to borrow the instance in the first place.

The behavior of this method when the pool has been exhausted is not strictly specified (although it may be specified by implementations).

Annotations
@SuppressWarnings:unchecked
@Override
Exceptions
Exception:
when makeObject throws an exception
clearback to summary
public void clear() throws Exception

Implements org.apache.commons.pool2.KeyedObjectPool.clear.

Doc from org.apache.commons.pool2.KeyedObjectPool.clear.

Clears the pool, removing all pooled instances (optional operation).

Annotations
@Override
Exceptions
Exception:
if the pool cannot be cleared
clearback to summary
public void clear(final K key) throws Exception

Implements org.apache.commons.pool2.KeyedObjectPool.clear.

Doc from org.apache.commons.pool2.KeyedObjectPool.clear.

Clears the specified pool, removing all pooled instances corresponding to the given key (optional operation).

Annotations
@Override
Exceptions
Exception:
if the key cannot be cleared
closeback to summary
public void close()

Implements org.apache.commons.pool2.KeyedObjectPool.close.

Doc from org.apache.commons.pool2.KeyedObjectPool.close.

Closes this pool, and free any resources associated with it.

Calling addObject or borrowObject after invoking this method on a pool will cause them to throw an IllegalStateException.

Implementations should silently fail if not all resources can be freed.

Annotations
@Override
getKeysback to summary
public List<K> getKeys()

Overrides default org.apache.commons.pool2.KeyedObjectPool.getKeys.

Gets a copy of the pool key list.

Returns:List<K>

a copy of the pool key list.

Annotations
@Override
Since
2.12.0
getNumActiveback to summary
public int getNumActive()

Implements org.apache.commons.pool2.KeyedObjectPool.getNumActive.

Doc from org.apache.commons.pool2.KeyedObjectPool.getNumActive.

Gets the total number of instances currently borrowed from this pool but not yet returned. Returns a negative value if this information is not available.

Annotations
@Override
getNumActiveback to summary
public int getNumActive(final K key)

Implements org.apache.commons.pool2.KeyedObjectPool.getNumActive.

Doc from org.apache.commons.pool2.KeyedObjectPool.getNumActive.

Gets the number of instances currently borrowed from but not yet returned to the pool corresponding to the given key. Returns a negative value if this information is not available.

Annotations
@Override
getNumIdleback to summary
public int getNumIdle()

Implements org.apache.commons.pool2.KeyedObjectPool.getNumIdle.

Doc from org.apache.commons.pool2.KeyedObjectPool.getNumIdle.

Gets the total number of instances currently idle in this pool. Returns a negative value if this information is not available.

Annotations
@Override
getNumIdleback to summary
public int getNumIdle(final K key)

Implements org.apache.commons.pool2.KeyedObjectPool.getNumIdle.

Doc from org.apache.commons.pool2.KeyedObjectPool.getNumIdle.

Gets the number of instances corresponding to the given key currently idle in this pool. Returns a negative value if this information is not available.

Annotations
@Override
invalidateObjectback to summary
public void invalidateObject(final K key, final V proxy) throws Exception

Implements org.apache.commons.pool2.KeyedObjectPool.invalidateObject.

Doc from org.apache.commons.pool2.KeyedObjectPool.invalidateObject.

Invalidates an object from the pool.

By contract, obj must have been obtained using borrowObject or a related method as defined in an implementation or sub-interface using a key that is equivalent to the one used to borrow the Object 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.

Annotations
@Override
Exceptions
Exception:
if the instance cannot be invalidated
returnObjectback to summary
public void returnObject(final K key, final V proxy) throws Exception

Implements org.apache.commons.pool2.KeyedObjectPool.returnObject.

Doc from org.apache.commons.pool2.KeyedObjectPool.returnObject.

Return an instance to the pool. By contract, obj must have been obtained using borrowObject or a related method as defined in an implementation or sub-interface using a key that is equivalent to the one used to borrow the instance in the first place.

Annotations
@Override
Exceptions
Exception:
if an instance cannot be returned to the pool
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Annotations
@Override
Since
2.4.3