org.apache.commons.pool.impl
Class StackKeyedObjectPool

java.lang.Object
  extended by org.apache.commons.pool.BaseKeyedObjectPool
      extended by org.apache.commons.pool.impl.StackKeyedObjectPool
All Implemented Interfaces:
KeyedObjectPool

public class StackKeyedObjectPool
extends BaseKeyedObjectPool
implements KeyedObjectPool

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.

Version:
$Revision: 328937 $ $Date: 2005-10-27 15:23:53 -0400 (Thu, 27 Oct 2005) $
Author:
Rodney Waldhoff

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
 void addObject(java.lang.Object key)
          Not supported in this base implementation.
 java.lang.Object borrowObject(java.lang.Object key)
          Obtain an instance from my pool for the specified key.
 void clear()
          Not supported in this base implementation.
 void clear(java.lang.Object key)
          Not supported in this base implementation.
 void close()
          Does nothing this base implementation.
 int getNumActive()
          Not supported in this base implementation.
 int getNumActive(java.lang.Object key)
          Not supported in this base implementation.
 int getNumIdle()
          Not supported in this base implementation.
 int getNumIdle(java.lang.Object key)
          Not supported in this base implementation.
 void invalidateObject(java.lang.Object key, java.lang.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(java.lang.Object key, java.lang.Object obj)
          Return an instance to my pool.
 void setFactory(KeyedPoolableObjectFactory factory)
          Not supported in this base implementation.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

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.

Parameters:
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.

Parameters:
max - cap on the number of "sleeping" instances in the pool
init - 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.

Parameters:
factory - the KeyedPoolableObjectFactory used to populate the pool

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

Parameters:
factory - the KeyedPoolableObjectFactory used to populate the pool
max - cap on the number of "sleeping" instances in the pool

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.

Parameters:
factory - the KeyedPoolableObjectFactory used to populate the pool
max - cap on the number of "sleeping" instances in the pool
init - initial size of the pool (this specifies the size of the container, it does not cause the pool to be pre-populated.)
Method Detail

addObject

public void addObject(java.lang.Object key)
               throws java.lang.Exception
Description copied from class: BaseKeyedObjectPool
Not supported in this base implementation.

Specified by:
addObject in interface KeyedObjectPool
Overrides:
addObject in class BaseKeyedObjectPool
Throws:
java.lang.Exception

borrowObject

public java.lang.Object borrowObject(java.lang.Object key)
                              throws java.lang.Exception
Description copied from interface: KeyedObjectPool
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.

Specified by:
borrowObject in interface KeyedObjectPool
Specified by:
borrowObject in class BaseKeyedObjectPool
Parameters:
key - the key used to obtain the object
Returns:
an instance from my pool.
Throws:
java.lang.Exception

clear

public void clear()
Description copied from class: BaseKeyedObjectPool
Not supported in this base implementation.

Specified by:
clear in interface KeyedObjectPool
Overrides:
clear in class BaseKeyedObjectPool

clear

public void clear(java.lang.Object key)
Description copied from class: BaseKeyedObjectPool
Not supported in this base implementation.

Specified by:
clear in interface KeyedObjectPool
Overrides:
clear in class BaseKeyedObjectPool
Parameters:
key - the key to clear

close

public void close()
           throws java.lang.Exception
Description copied from class: BaseKeyedObjectPool
Does nothing this base implementation.

Specified by:
close in interface KeyedObjectPool
Overrides:
close in class BaseKeyedObjectPool
Throws:
java.lang.Exception

getNumActive

public int getNumActive()
Description copied from class: BaseKeyedObjectPool
Not supported in this base implementation.

Specified by:
getNumActive in interface KeyedObjectPool
Overrides:
getNumActive in class BaseKeyedObjectPool
Returns:
the total number of instances currently borrowed from my pool

getNumActive

public int getNumActive(java.lang.Object key)
Description copied from class: BaseKeyedObjectPool
Not supported in this base implementation.

Specified by:
getNumActive in interface KeyedObjectPool
Overrides:
getNumActive in class BaseKeyedObjectPool
Parameters:
key - the key
Returns:
the number of instances corresponding to the given key currently borrowed in my pool

getNumIdle

public int getNumIdle()
Description copied from class: BaseKeyedObjectPool
Not supported in this base implementation.

Specified by:
getNumIdle in interface KeyedObjectPool
Overrides:
getNumIdle in class BaseKeyedObjectPool
Returns:
the total number of instances currently idle in my pool

getNumIdle

public int getNumIdle(java.lang.Object key)
Description copied from class: BaseKeyedObjectPool
Not supported in this base implementation.

Specified by:
getNumIdle in interface KeyedObjectPool
Overrides:
getNumIdle in class BaseKeyedObjectPool
Parameters:
key - the key
Returns:
the number of instances corresponding to the given key currently idle in my pool

invalidateObject

public void invalidateObject(java.lang.Object key,
                             java.lang.Object obj)
                      throws java.lang.Exception
Description copied from interface: KeyedObjectPool
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(java.lang.Object) method should be used instead.

Specified by:
invalidateObject in interface KeyedObjectPool
Specified by:
invalidateObject in class BaseKeyedObjectPool
obj - a borrowed instance to be returned.
Throws:
java.lang.Exception

returnObject

public void returnObject(java.lang.Object key,
                         java.lang.Object obj)
                  throws java.lang.Exception
Description copied from interface: KeyedObjectPool
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.

Specified by:
returnObject in interface KeyedObjectPool
Specified by:
returnObject in class BaseKeyedObjectPool
Parameters:
key - the key used to obtain the object
obj - a borrowed instance to be returned.
Throws:
java.lang.Exception

setFactory

public void setFactory(KeyedPoolableObjectFactory factory)
                throws java.lang.IllegalStateException
Description copied from class: BaseKeyedObjectPool
Not supported in this base implementation.

Specified by:
setFactory in interface KeyedObjectPool
Overrides:
setFactory in class BaseKeyedObjectPool
Parameters:
factory - the KeyedPoolableObjectFactory I use to create new instances.
Throws:
java.lang.IllegalStateException - when the factory cannot be set at this time

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Copyright © 2001-2003 Apache Software Foundation. Documenation generated April 15 2009.