org.ow2.util.pool.impl
Class JPool<InstanceType,Clue>

java.lang.Object
  extended by org.ow2.util.pool.impl.JPool<InstanceType,Clue>
Type Parameters:
InstanceType - the type of the object that are managed by the pool (could be EasyBeansSLSB, etc.)
Clue - a clue to retrieve a specific instance in the pool
All Implemented Interfaces:
org.ow2.util.pool.api.Pool<InstanceType,Clue>, org.ow2.util.pool.api.PoolAttributes

public class JPool<InstanceType,Clue>
extends java.lang.Object
implements org.ow2.util.pool.api.Pool<InstanceType,Clue>, org.ow2.util.pool.api.PoolAttributes

Abstract pool.
Need to be extended to set-up the correct generic types used for BeanType and Hint.

Author:
Florent Benoit

Constructor Summary
JPool(PoolFactory<InstanceType,Clue> poolFactory)
          Builds a new pool.
 
Method Summary
 void discard(InstanceType instance)
          Discard the instance which is in the pool.
 InstanceType get()
          Gets an object from the pool.
 InstanceType get(Clue clue)
          Gets an object by using a specific hint.
 boolean isAllowSharedInstance()
          Return true if many instances of the same object can be created (when pool is not full).
 void release(InstanceType instance)
          Puts back the instance in the pool so it can be reused.
 void setAllowSharedInstance(boolean allowSharedInstance)
          Allow to share instances (shouldn't be use in stateful case as one stateful ID is linked to one client.
 void setPoolConfiguration(org.ow2.util.pool.api.IPoolConfiguration poolConfiguration)
          Configure the pool with a given configuration.
 void start()
          Start the pool.
It could create initial instances if specified.
 void stop()
          Stop this pool.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JPool

public JPool(PoolFactory<InstanceType,Clue> poolFactory)
Builds a new pool.

Parameters:
poolFactory - factory used for delegating create, remove, etc.
Method Detail

get

public InstanceType get()
                 throws org.ow2.util.pool.api.PoolException
Gets an object from the pool.

Specified by:
get in interface org.ow2.util.pool.api.Pool<InstanceType,Clue>
Returns:
an instance of an object with type Type.
Throws:
org.ow2.util.pool.api.PoolException - if instance cannot be returned.

get

public InstanceType get(Clue clue)
                 throws org.ow2.util.pool.api.PoolException
Gets an object by using a specific hint.

Specified by:
get in interface org.ow2.util.pool.api.Pool<InstanceType,Clue>
Parameters:
clue - attribute used to retrieve a given instance
Returns:
a specific instance of the resource.
Throws:
org.ow2.util.pool.api.PoolException - if instance cannot be returned.

release

public void release(InstanceType instance)
             throws org.ow2.util.pool.api.PoolException
Puts back the instance in the pool so it can be reused.

Specified by:
release in interface org.ow2.util.pool.api.Pool<InstanceType,Clue>
Parameters:
instance - which will be put back in the pool.
Throws:
org.ow2.util.pool.api.PoolException - if instance is not released.

discard

public void discard(InstanceType instance)
             throws org.ow2.util.pool.api.PoolException
Discard the instance which is in the pool.

Specified by:
discard in interface org.ow2.util.pool.api.Pool<InstanceType,Clue>
Parameters:
instance - which will be discarded.
Throws:
org.ow2.util.pool.api.PoolException - if instance is not discarded

setAllowSharedInstance

public void setAllowSharedInstance(boolean allowSharedInstance)
Allow to share instances (shouldn't be use in stateful case as one stateful ID is linked to one client. No Stateful with same ID are authorized).

Parameters:
allowSharedInstance - true if it is allowed, else false.

isAllowSharedInstance

public boolean isAllowSharedInstance()
Return true if many instances of the same object can be created (when pool is not full).

Returns:
true if this is allowed.

setPoolConfiguration

public void setPoolConfiguration(org.ow2.util.pool.api.IPoolConfiguration poolConfiguration)
Configure the pool with a given configuration.

Specified by:
setPoolConfiguration in interface org.ow2.util.pool.api.Pool<InstanceType,Clue>
Parameters:
poolConfiguration - the given configuration

start

public void start()
           throws org.ow2.util.pool.api.PoolException
Start the pool.
It could create initial instances if specified.

Specified by:
start in interface org.ow2.util.pool.api.Pool<InstanceType,Clue>
Throws:
org.ow2.util.pool.api.PoolException - if initialization fails

stop

public void stop()
          throws org.ow2.util.pool.api.PoolException
Stop this pool.

Specified by:
stop in interface org.ow2.util.pool.api.Pool<InstanceType,Clue>
Throws:
org.ow2.util.pool.api.PoolException - if destroy fails


Copyright © 2007-2009 OW2 Consortium. All Rights Reserved.