T - Type of ExternalResource to produce in this factory.public final class KeyedResourcePool<T extends ExternalResource>
extends java.lang.Object
T.
The KeyedResourcePool uses a ResourceFactory to create
new objects for the pool until the number of instances is exceeded that is
set by the factory.
| Constructor and Description |
|---|
KeyedResourcePool()
Constructs a new object.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addResourceFactory(ResourceFactory<T> resourceFactory)
Adds the given resource factory.
|
T |
borrowObject(java.lang.Object key)
Type safe return of the object to borrow from the pool.
|
void |
close()
Closes all pools for all keys.
|
java.util.Collection<java.lang.String> |
getKeys()
Retrieves the available keys of this pool.
|
int |
getNumActive()
Retrieves the number of active resources in all pools.
|
int |
getNumActive(java.lang.String key)
Retrieves the number of active resources in the pool for the given key.
|
int |
getNumIdle()
Retrieves the number of idle resources in all pools.
|
int |
getNumIdle(java.lang.String key)
Retrieves the number of idle resources in the pool for the given key.
|
void |
returnObject(java.lang.String key,
T resource)
Returns a previously borrowed resource to the pool.
|
public void addResourceFactory(ResourceFactory<T> resourceFactory) throws java.lang.Exception
resourceFactory - The ResourceFactory to add.java.lang.Exception - error populating the poolpublic T borrowObject(java.lang.Object key) throws NoresourceError
key - the type of the object to borrow from the poolNoresourceError - the object could not be borrowedpublic void returnObject(java.lang.String key,
T resource)
throws NoresourceError
key - resource type.resource - resource to return.NoresourceError - Error returning the object to the pool.public int getNumActive()
public int getNumActive(java.lang.String key)
key - the keypublic int getNumIdle()
public int getNumIdle(java.lang.String key)
key - the key-1 if there is no resource
with that keypublic java.util.Collection<java.lang.String> getKeys()
public void close()
throws java.lang.Exception
java.lang.Exception - error closing a pool