org.apache.commons.pool.impl
Class StackKeyedObjectPool
- KeyedObjectPool
public class StackKeyedObjectPool
A simple,
Stack
-based
KeyedObjectPool
implementation.
Given a
KeyedPoolableObjectFactory
, this class will maintain
a simple pool of instances. A finite number of "sleeping"
or inactive instances is enforced, but when the pool is
empty, new instances are created to support the new load.
Hence this class places no limit on the number of "active"
instances created by the pool, but is quite useful for
re-using
Objects without introducing
artificial limits.
$Revision: 1.14 $ $Date: 2004/02/28 12:16:21 $
void | addObject(Object key) - Create an object using my
factory or other
implementation dependent mechanism, and place it into the pool.
|
Object | borrowObject(Object key) - Obtain an instance from my pool
for the specified key.
|
void | clear() - Clears my pool, removing all pooled instances
(optional operation).
|
void | clear(Object key) - Clears the specified pool, removing all
pooled instances corresponding to
the given key (optional operation).
|
void | close() - Close this pool, and free any resources associated with it.
|
int | getNumActive() - Returns the total number of instances
current borrowed from my pool but not
yet returned (optional operation).
|
int | getNumActive(Object key) - Returns the number of instances
currently borrowed from but not yet returned
to my pool corresponding to the
given key (optional operation).
|
int | getNumIdle() - Returns the total number of instances
currently idle in my pool (optional operation).
|
int | getNumIdle(Object key) - Returns the number of instances
corresponding to the given key
currently idle in my pool (optional operation).
|
void | invalidateObject(Object key, Object obj) - 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.
|
void | returnObject(Object key, Object obj) - Return an instance to my pool.
|
void | setFactory(KeyedPoolableObjectFactory factory) - Sets the
factory I use
to create new instances (optional operation).
|
String | toString()
|
addObject , borrowObject , clear , clear , close , getNumActive , getNumActive , getNumIdle , getNumIdle , invalidateObject , returnObject , setFactory |
StackKeyedObjectPool
public StackKeyedObjectPool()
Create a new pool using
no factory. Clients must first populate the pool
using returnObject(java.lang.Object,java.lang.Object)
before they can be borrowed
.
StackKeyedObjectPool
public StackKeyedObjectPool(int max)
Create a new pool using
no factory. Clients must first populate the pool
using returnObject(java.lang.Object,java.lang.Object)
before they can be borrowed
.
max
- cap on the number of "sleeping" instances in the pool
StackKeyedObjectPool
public StackKeyedObjectPool(int max,
int init)
Create a new pool using
no factory. Clients must first populate the pool
using returnObject(java.lang.Object,java.lang.Object)
before they can be borrowed
.
max
- cap on the number of "sleeping" instances in the poolinit
- initial size of the pool (this specifies the size of the container,
it does not cause the pool to be pre-populated.)
StackKeyedObjectPool
public StackKeyedObjectPool(KeyedPoolableObjectFactory factory)
Create a new SimpleKeyedObjectPool using
the specified factory to create new instances.
StackKeyedObjectPool
public StackKeyedObjectPool(KeyedPoolableObjectFactory factory,
int max)
Create a new SimpleKeyedObjectPool using
the specified factory to create new instances.
capping the number of "sleeping" instances to max
StackKeyedObjectPool
public StackKeyedObjectPool(KeyedPoolableObjectFactory factory,
int max,
int init)
Create a new SimpleKeyedObjectPool using
the specified factory to create new instances.
capping the number of "sleeping" instances to max,
and initially allocating a container capable of containing
at least init instances.
factory
- the KeyedPoolableObjectFactory
used to populate the poolmax
- cap on the number of "sleeping" instances in the poolinit
- initial size of the pool (this specifies the size of the container,
it does not cause the pool to be pre-populated.)
addObject
public void addObject(Object key)
throws Exception
Create an object using my
factory
or other
implementation dependent mechanism, and place it into the pool.
addObject() is useful for "pre-loading" a pool with idle objects.
(Optional operation).
- addObject in interface KeyedObjectPool
- addObject in interface BaseKeyedObjectPool
borrowObject
public Object borrowObject(Object key)
throws Exception
Obtain an instance from my pool
for the specified key.
By contract, clients MUST return
the borrowed object using
returnObject
,
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.
- borrowObject in interface KeyedObjectPool
- borrowObject in interface BaseKeyedObjectPool
key
- the key used to obtain the object
- an instance from my pool.
clear
public void clear()
Clears my pool, removing all pooled instances
(optional operation).
Throws UnsupportedOperationException
if the pool cannot be cleared.
- clear in interface KeyedObjectPool
- clear in interface BaseKeyedObjectPool
clear
public void clear(Object key)
Clears the specified pool, removing all
pooled instances corresponding to
the given key (optional operation).
Throws UnsupportedOperationException
if the pool cannot be cleared.
- clear in interface KeyedObjectPool
- clear in interface BaseKeyedObjectPool
getNumActive
public int getNumActive()
Returns the total number of instances
current borrowed from my pool but not
yet returned (optional operation).
Throws UnsupportedOperationException
if this information is not available.
- getNumActive in interface KeyedObjectPool
- getNumActive in interface BaseKeyedObjectPool
- the total number of instances currently borrowed from my pool
getNumActive
public int getNumActive(Object key)
Returns the number of instances
currently borrowed from but not yet returned
to my pool corresponding to the
given key (optional operation).
Throws UnsupportedOperationException
if this information is not available.
- getNumActive in interface KeyedObjectPool
- getNumActive in interface BaseKeyedObjectPool
- the number of instances corresponding to the given key currently borrowed in my pool
getNumIdle
public int getNumIdle()
Returns the total number of instances
currently idle in my pool (optional operation).
Throws UnsupportedOperationException
if this information is not available.
- getNumIdle in interface KeyedObjectPool
- getNumIdle in interface BaseKeyedObjectPool
- the total number of instances currently idle in my pool
getNumIdle
public int getNumIdle(Object key)
Returns the number of instances
corresponding to the given key
currently idle in my pool (optional operation).
Throws UnsupportedOperationException
if this information is not available.
- getNumIdle in interface KeyedObjectPool
- getNumIdle in interface BaseKeyedObjectPool
- the number of instances corresponding to the given key currently idle in my pool
invalidateObject
public void invalidateObject(Object key,
Object obj)
throws Exception
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.
If the connection should be validated before or after borrowing,
then the
PoolableObjectFactory.validateObject(Object)
method should be
used instead.
- invalidateObject in interface KeyedObjectPool
- invalidateObject in interface BaseKeyedObjectPool
obj
- a borrowed
instance to be returned.
returnObject
public void returnObject(Object key,
Object obj)
throws Exception
Return an instance to my 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.
- returnObject in interface KeyedObjectPool
- returnObject in interface BaseKeyedObjectPool
key
- the key used to obtain the objectobj
- a borrowed
instance to be returned.
toString
public String toString()
Copyright © 2001-2003 Apache Software Foundation. Documenation generated March 31 2006.