|
|||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||
java.lang.Object
|
+--org.apache.commons.pool.BaseKeyedObjectPool
|
+--org.apache.commons.pool.impl.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.
| Constructor Summary | |
StackKeyedObjectPool()
Create a new pool using no factory. |
|
StackKeyedObjectPool(int max)
Create a new pool using no factory. |
|
StackKeyedObjectPool(int max,
int init)
Create a new pool using no factory. |
|
StackKeyedObjectPool(KeyedPoolableObjectFactory factory)
Create a new SimpleKeyedObjectPool using the specified factory to create new instances. |
|
StackKeyedObjectPool(KeyedPoolableObjectFactory factory,
int max)
Create a new SimpleKeyedObjectPool using the specified factory to create new instances. |
|
StackKeyedObjectPool(KeyedPoolableObjectFactory factory,
int max,
int init)
Create a new SimpleKeyedObjectPool using the specified factory to create new instances. |
|
| Method Summary | |
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 |
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()
|
| Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
public StackKeyedObjectPool()
returnObject(java.lang.Object,java.lang.Object)
before they can be borrowed.
public StackKeyedObjectPool(int max)
returnObject(java.lang.Object,java.lang.Object)
before they can be borrowed.
public StackKeyedObjectPool(int max,
int init)
returnObject(java.lang.Object,java.lang.Object)
before they can be borrowed.
public StackKeyedObjectPool(KeyedPoolableObjectFactory factory)
factory - the KeyedPoolableObjectFactory used to populate the pool
public StackKeyedObjectPool(KeyedPoolableObjectFactory factory,
int max)
factory - the KeyedPoolableObjectFactory used to populate the poolmax - cap on the number of "sleeping" instances in the pool
public StackKeyedObjectPool(KeyedPoolableObjectFactory factory,
int max,
int init)
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.)| Method Detail |
public Object borrowObject(Object key)
throws Exception
KeyedObjectPoolreturnObject,
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 KeyedObjectPoolborrowObject in class BaseKeyedObjectPoolkey - the key used to obtain the object
Exceptionpublic void clear()
KeyedObjectPoolUnsupportedOperationException
if the pool cannot be cleared.
clear in interface KeyedObjectPoolclear in class BaseKeyedObjectPoolpublic void clear(Object key)
KeyedObjectPoolUnsupportedOperationException
if the pool cannot be cleared.
clear in interface KeyedObjectPoolclear in class BaseKeyedObjectPoolkey - the key to clear
public void close()
throws Exception
KeyedObjectPool
close in interface KeyedObjectPoolclose in class BaseKeyedObjectPoolExceptionpublic int getNumActive()
KeyedObjectPoolUnsupportedOperationException
if this information is not available.
getNumActive in interface KeyedObjectPoolgetNumActive in class BaseKeyedObjectPoolpublic int getNumActive(Object key)
KeyedObjectPoolUnsupportedOperationException
if this information is not available.
getNumActive in interface KeyedObjectPoolgetNumActive in class BaseKeyedObjectPoolkey - the key
public int getNumIdle()
KeyedObjectPoolUnsupportedOperationException
if this information is not available.
getNumIdle in interface KeyedObjectPoolgetNumIdle in class BaseKeyedObjectPoolpublic int getNumIdle(Object key)
KeyedObjectPoolUnsupportedOperationException
if this information is not available.
getNumIdle in interface KeyedObjectPoolgetNumIdle in class BaseKeyedObjectPoolkey - the key
public void returnObject(Object key,
Object obj)
throws Exception
KeyedObjectPoolborrowObject
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 KeyedObjectPoolreturnObject in class BaseKeyedObjectPoolkey - the key used to obtain the objectobj - a borrowed instance to be returned.
Exception
public void setFactory(KeyedPoolableObjectFactory factory)
throws IllegalStateException
KeyedObjectPoolfactory I use
to create new instances (optional operation).
setFactory in interface KeyedObjectPoolsetFactory in class BaseKeyedObjectPoolfactory - the KeyedPoolableObjectFactory I use to create new instances.
IllegalStateException - when the factory cannot be set at this timepublic String toString()
toString in class Object
|
|||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||