|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Object | +--com.cafesoft.core.pool.DefaultObjectPool
Provides a generic implementation of the ObjectPool interface. It is recommended that this class be extended to create specific implementations such as SessionPool, Connection, etc...
| Constructor Summary | |
DefaultObjectPool()
Create a new DefaultObjectPool. |
|
DefaultObjectPool(PoolableObjectFactory objectFactory)
Create a new DefaultObjectPool Creates an object pool with no minimum, no maximum, and no expiration time. |
|
DefaultObjectPool(PoolableObjectFactory objectFactory,
int minimum)
Create a new DefaultObjectPool. |
|
DefaultObjectPool(PoolableObjectFactory objectFactory,
int minimum,
int maximum)
Create a new DefaultObjectPool. |
|
DefaultObjectPool(PoolableObjectFactory objectFactory,
int minimum,
int maximum,
long expiration)
Create a new DefaultObjectPool Creates an object pool with the specified minimum, specified maximum, and the specified expiration time. |
|
| Method Summary | |
Object |
borrowObject()
Borrow an object from the ObjectPool. |
void |
cleanIdle()
Remove idle objects from the ObjectPool. |
void |
cleanIdle(int number)
Remove the given number of idle objects from the ObjectPool. |
void |
close()
Close the ObjectPool. |
long |
getExpiration()
Get the expiration time of objects in the ObjectPool. |
int |
getMaximum()
Get the maximum number of objects the ObjectPool must maintain. |
int |
getMinimum()
Get the minimum number of objects the ObjectPool must maintain. |
PoolableObjectFactory |
getPoolableObjectFactory()
Get the PoolableObjectFactory that the ObjectPool is currently using. |
int |
numActive()
Get the number of active ObjectPool objects being used. |
int |
numIdle()
Get the number of idle ObjectPool objects being used. |
void |
recycle()
Recycle the resources of this object |
void |
returnObject(Object object)
Return an object to the ObjectPool. |
void |
setDebug(boolean debug)
Set debug on or off. |
void |
setExpiration(long expiration)
Set the expiration time for objects in the ObjectPool. |
void |
setMaximum(int maximum)
Set the maximum number of objects both active and inactive that the ObjectPool must maintain. |
void |
setMinimum(int minimum)
Set the minimum number of objects both active and inactive that the ObjectPool must maintain. |
void |
setPoolableObjectFactory(PoolableObjectFactory poolableObjectFactory)
Set the PoolableObjectFactory that the ObjectPool will use. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
public DefaultObjectPool()
throws Exception
Creates an object pool with no minimum, no maximum, and no expiration time.
public DefaultObjectPool(PoolableObjectFactory objectFactory)
throws Exception
Creates an object pool with no minimum, no maximum, and no expiration time.
objectFactory - the PoolableObjectFactory to use to manage the
objects for the ObjectPool
public DefaultObjectPool(PoolableObjectFactory objectFactory,
int minimum)
throws Exception
Creates an object pool with the specified minimum, no maximum, and no expiration time.
objectFactory - the PoolableObjectFactory to use to manage the
objects for the ObjectPoolminimum - the minimum number of objects the ObjectPool must
maintain
public DefaultObjectPool(PoolableObjectFactory objectFactory,
int minimum,
int maximum)
throws Exception
Creates an object pool with the specified minimum, specified maximum, and no expiration time.
objectFactory - the PoolableObjectFactory to use to manage the
objects for the ObjectPoolminimum - the minimum number of objects the ObjectPool must
maintainmaximum - the maximum number of objects the ObjectPool is allowed to
create and maintain
public DefaultObjectPool(PoolableObjectFactory objectFactory,
int minimum,
int maximum,
long expiration)
throws Exception
Creates an object pool with the specified minimum, specified maximum, and the specified expiration time.
objectFactory - the PoolableObjectFactory to use to manage the
objects for the ObjectPoolminimum - the minimum number of objects the ObjectPool must maintainmaximum - the maximum number of objects the ObjectPool is allowed to
create and maintain.expiration - the expiration time at which objects that are idle are
recycled| Method Detail |
public void recycle()
recycle in interface Recyclable
public Object borrowObject()
throws Exception
Note: Implementing class should make this method synchronized.
This method is responsible for "checking-out" an object for use. It is recommended that the implementing class provide a Class specific get method that casts the generic object returned by this method to the appropriate class.
For example:
ConnectionPool implements ObjectPool
{
public Connection getConnection() throws ConnectionException
{
return (Connection) borrowObject();
}
}
borrowObject in interface ObjectPoolException - thrown if an error occurs while trying to get an
instance of an object to use. Typically this will be the result of the
createObject() method from the implementing PoolableObjectFactory
assigned to the ObjectPool
PoolAtMaximumException - thrown if no more objects can be
created to borrow.public void returnObject(Object object)
Note: Implementing class should make this method synchronized.
This method is responsible for "checking-in" an object. It is recommended that the implementing class provide a Class specific return method that accepts the specific class as a parameter.
For example:
ConnectionPool implements ObjectPool
{
public void releaseConnection(Connection connection)
{
returnObject(connection);
}
}
returnObject in interface ObjectPoolobject - The object to be returned to the ObjectPoolpublic void close()
Destroy all objects and release all resources that were used by both the objects in the ObjectPool and the ObjectPool itself
close in interface ObjectPoolpublic void cleanIdle(int number)
Remove objects that are not actively used and release their resources. See the implementation for specifics as to the algorithm that is used to determine idle object status.
cleanIdle in interface ObjectPoolnumber - the number of idle objects to remove unless removing
the specified number of objects would put the ObjectPool
below it's minimum number of objectspublic void cleanIdle()
Remove objects that are not actively used and release their resources. See the implementation for specifics as to the algorithm that is used to determine idle object status.
cleanIdle in interface ObjectPoolpublic int numActive()
numActive in interface ObjectPoolpublic int numIdle()
numIdle in interface ObjectPoolpublic void setPoolableObjectFactory(PoolableObjectFactory poolableObjectFactory)
The PoolableObjectFactory is responsible for object creation, destruction, and validation.
setPoolableObjectFactory in interface ObjectPoolpoolableObjectFactory - the new poolableObjectFactory for the
ObjectPool to usepublic PoolableObjectFactory getPoolableObjectFactory()
The PoolableObjectFactory is responsible for object creation, destruction, and validation.
getPoolableObjectFactory in interface ObjectPoolpublic void setMaximum(int maximum)
Formula for determining maximum object status
numActive() + numIdle() <= maximum
setMaximum in interface ObjectPoolmaximum - the new maximum number of objects that the ObjectPool
must maintain.public void setMinimum(int minimum)
Formula for determining minimum object status
numActive() + numIdle() >= minimum
setMinimum in interface ObjectPoolminimum - the new minimum number of objects that the ObjectPool must
maintainpublic void setExpiration(long expiration)
Set the time that an object is allowed to remain in an idle state before it is collected and recycled by the pool. The implementing class is responsible for creating the mechanism to use the expiration time to expire objects.
setExpiration in interface ObjectPoolexpiration - the new expiration time for the ObjectPool to usepublic int getMaximum()
getMaximum in interface ObjectPoolpublic int getMinimum()
getMinimum in interface ObjectPoolpublic long getExpiration()
getExpiration in interface ObjectPoolpublic void setDebug(boolean debug)
setDebug in interface ObjectPooldebug - the value of debug true is on false is off
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||