|
|||||||||
| PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES | ||||||||
See:
Description
| Interface Summary | |
| BLMContextValidator | Validates an instance of BLMContextManager object. |
| Class Summary | |
| BLMContextFactory | Implements
PoolableObjectFactory
for managing BLMContextManager instances. |
| CallBasedContextValidator | Validates BLM Context Manager by calling the BLMDeclarationManager.getKind(String) method. |
API for managing the BLMContextManager Pool.
The com.wles.blm.pool package defines BLM API for
pooling of BLMContextManager
objects. The API is extends the Apache Common Pool
Framework.
Here is a simple example of using the pool. Steps that are
optional are marked as (Optional}.
public class PoolHolder
{
public static GenericObjectPool blmContextPool = null;
//Initialize the pool
public static synchronized void init(String blmUrl, String username, String password) {
//Initialize only once
if (blmContextPool == null)
return;
// Step 1. (Optional)
// Create a BLMContextManager validator
CallBasedContextValidator blmContextValidator = new CallBasedContextValidator();
// Step 2.
// Create the BLMContext factory.
// The factory is responsible for creating, destroying and validating of BLMContextManager instances.
BLMContextFactory blmContextFactory = new BLMContextFactory(
blmUrl, username, password, blmContextValidator, 5);
// Step 3. (Optional)
// Create configuration for the pool.
// Please see set methods of GenericObjectPool for more information on different pool parameters.
// See also default values at http://jakarta.apache.org/commons/pool/apidocs/constant-values.html.
GenericObjectPool.Config config = new GenericObjectPool.Config();
// The maximum number of objects that can be borrowed from the pool at one time.
config.maxActive = 5;
// The maximum number of objects that can sit idle in the pool at any time.
config.maxIdle = -1; //unlimited
// The behaviour of the GenericObjectPool method when the pool is exhausted
config.whenExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_BLOCK; //wait
// The maximum amount of time (in milliseconds) the borrowObject() method should block before throwing an exception.
config.maxWait = -1; //unlimited
// When true, objects will be validated before being returned by the borrowObject() method.
config.testOnBorrow = true;
// When true, objects will be validated before being returned to the pool within the returnObject(java.lang.Object).
config.testOnReturn = false;
// The following parameters affect the background eviction thread
// The number of milliseconds to sleep between runs of the idle object evictor thread.
// When non-positive, no idle object evictor thread will be run.
config.timeBetweenEvictionRunsMillis = 1000 * 60 * 5; //Every 5 minutes
// The minimum amount of time an object may sit idle in the pool before it is eligable for eviction
config.minEvictableIdleTimeMillis = 1000 * 60 * 60; //An hour
// The minimum amount of time an object may sit idle in the pool before it is eligable for eviction.
// With the extra condition that at least "minIdle" amount of object remain in the pool.
config.softMinEvictableIdleTimeMillis = 1000 * 60 * 10; //Ten minutes
// When true, objects will be validated by the idle object evictor.
config.testWhileIdle = false;
// Sets the max number of objects to examine during each run of the idle object evictor thread (if any).
config.numTestsPerEvictionRun = 5;
// Sets the minimum number of objects allowed in the pool.
// Setting this number may improve performance because the pool will contain pre-loaded context managers.
config.minIdle = 2;
// Step 4.
// Create the pool
blmContextPool = new GenericObjectPool(blmContextFactory, config);
}
}
A class that makes use of a BLMContextManager could then use the pool as shown below:
public class Foo
{
private ObjectPool pool;
public Foo()
{
PoolHolder.init("https://blmserver:7011", "system", "weblogic");
pool = PoolHolder.blmContextPool;
}
public doSomething()
{
...
BLMContextManager context = null;
try
{
context = (BLMContextManager) pool.borrowObject();
// use the context
...
}
finally
{
if (context != null)
{
pool.returnObject(context);
}
}
...
}
}
|
|||||||||
| PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES | ||||||||