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

public Class ProxiedObjectPool<T>

extends Object
implements ObjectPool<T>
Class Inheritance
All Implemented Interfaces
org.apache.commons.pool2.ObjectPool, java.io.Closeable, java.lang.AutoCloseable
Type Parameters
<T>
type of the pooled object
Imports
org.apache.commons.pool2.ObjectPool, .UsageTracking

Create a new 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 ObjectPool<T>
private final ProxySource<T>

Constructor Summary

AccessConstructor and Description
public
ProxiedObjectPool(final ObjectPool<T>
The object pool to wrap
pool
,
final ProxySource<T>
The source of the proxy objects
proxySource
)

Constructs a new proxied object pool.

Method Summary

Modifier and TypeMethod and Description
public void
addObject()

Implements org.apache.commons.pool2.ObjectPool.addObject.

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

Implements org.apache.commons.pool2.ObjectPool.borrowObject.

Borrows an instance from this pool.
public void
clear()

Implements org.apache.commons.pool2.ObjectPool.clear.

Clears any objects sitting idle in the pool, releasing any associated resources (optional operation).
public void
close()

Implements org.apache.commons.pool2.ObjectPool.close.

Closes this pool, and free any resources associated with it.
public int
getNumActive()

Implements org.apache.commons.pool2.ObjectPool.getNumActive.

Gets the number of instances currently borrowed from this pool.
public int
getNumIdle()

Implements org.apache.commons.pool2.ObjectPool.getNumIdle.

Gets the number of instances currently idle in this pool.
public void
invalidateObject(final T
a borrowed instance to be disposed.
proxy
)

Implements org.apache.commons.pool2.ObjectPool.invalidateObject.

Invalidates an object from the pool.
public void
returnObject(final T
a borrowed instance to be returned.
proxy
)

Implements org.apache.commons.pool2.ObjectPool.returnObject.

Returns 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 ObjectPool<T> pool
proxySourceback to summary
private final ProxySource<T> proxySource

Constructor Detail

ProxiedObjectPoolback to summary
public ProxiedObjectPool(final ObjectPool<T> pool, final ProxySource<T> proxySource)

Constructs a new proxied object pool.

Parameters
pool:ObjectPool<T>

The object pool to wrap

proxySource:ProxySource<T>

The source of the proxy objects

Method Detail

addObjectback to summary
public void addObject() throws Exception

Implements org.apache.commons.pool2.ObjectPool.addObject.

Doc from org.apache.commons.pool2.ObjectPool.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 PooledObjectFactory#makeObject fails.
borrowObjectback to summary
public T borrowObject() throws Exception

Implements org.apache.commons.pool2.ObjectPool.borrowObject.

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

Borrows an instance from this pool.

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

By contract, clients must return the borrowed instance using returnObject, invalidateObject, or a related method as defined in an implementation or sub-interface.

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

Returns:T

an instance from this pool.

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

Implements org.apache.commons.pool2.ObjectPool.clear.

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

Clears any objects sitting idle in the pool, releasing any associated resources (optional operation). Idle objects cleared must be PooledObjectFactory#destroyObject(PooledObject).

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

Implements org.apache.commons.pool2.ObjectPool.close.

Doc from org.apache.commons.pool2.ObjectPool.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
getNumActiveback to summary
public int getNumActive()

Implements org.apache.commons.pool2.ObjectPool.getNumActive.

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

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

Returns:int

the number of instances currently borrowed from this pool.

Annotations
@Override
getNumIdleback to summary
public int getNumIdle()

Implements org.apache.commons.pool2.ObjectPool.getNumIdle.

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

Gets the number of instances currently idle in this pool. This may be considered an approximation of the number of objects that can be borrowed without creating any new instances. Returns a negative value if this information is not available.

Returns:int

the number of instances currently idle in this pool.

Annotations
@Override
invalidateObjectback to summary
public void invalidateObject(final T proxy) throws Exception

Implements org.apache.commons.pool2.ObjectPool.invalidateObject.

Doc from org.apache.commons.pool2.ObjectPool.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.

This method should be used when an object that has been borrowed is determined (due to an exception or other problem) to be invalid.

Parameters
proxy:T

a borrowed instance to be disposed.

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

Implements org.apache.commons.pool2.ObjectPool.returnObject.

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

Returns 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.

Parameters
proxy:T

a borrowed instance to be returned.

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.

Returns:String

a string representation of the object.

Annotations
@Override
Since
2.4.3