org.objectweb.easybeans.pool
Class JPool<InstanceType,Clue>

java.lang.Object
  extended by org.objectweb.easybeans.pool.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:
Pool<InstanceType,Clue>, PoolAttributes

public class JPool<InstanceType,Clue>
extends java.lang.Object
implements Pool<InstanceType,Clue>, PoolAttributes

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

Author:
Florent Benoit

Field Summary
private  java.util.List<InstanceType> availableList
          List of available objects in the pool.
private  java.util.List<InstanceType> busyList
          List of objects which are currently busy and not available from the pool.
private  int currentWaiters
          Current number of waiters.
private static int DEFAULT_MAX_WAITERS
          Default maximum of waiters (1000).
private static long DEFAULT_TIMEOUT
          Default timeout (10s) in ms.
private  int highMaxWaiters
          Maximum number of waiters during current period.
private  long highWaitingTime
          Maximum waiting time during current period.
private  java.util.Map<InstanceType,PoolEntryStatistics> infoMap
          Information on entries managed in the pool.
private  int initSize
          Initial size of the pool.
private  JLog logger
          Logger used.
private  int maxSize
          Maximum size of the pool.
private  int maxWaiters
          Max nb of waiters allowed to wait for an instance.
private  int minSize
          Minimum size of the pool.
private static int NO_LIMIT
          High Value for no limit for the connection pool.
private  PoolFactory<InstanceType,Clue> poolFactory
          Factory used for delegate creating, matching, removing actions.
private  int rejectedFull
          Total nb of instance not served due to an overflow of waiters.
private  int rejectedTimeout
          Total nb of instance not served due to timeout.
private  int servedInstance
          Total number of instances since the pool creation.
private  boolean strict
          Maximum size of the pool is strict.
private  int totalWaiters
          Total nb of waiters since pool creation.
private  long totalWaitingTime
          total waiting time in milliseconds.
private  long waiterTimeout
          Max nb of milliseconds to wait for an object when the pool is full.
 
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.
 void release(InstanceType instance)
          Puts back the instance in the pool so it can be reused.
 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
 

Field Detail

DEFAULT_TIMEOUT

private static final long DEFAULT_TIMEOUT
Default timeout (10s) in ms.

See Also:
Constant Field Values

DEFAULT_MAX_WAITERS

private static final int DEFAULT_MAX_WAITERS
Default maximum of waiters (1000).

See Also:
Constant Field Values

NO_LIMIT

private static final int NO_LIMIT
High Value for no limit for the connection pool.

See Also:
Constant Field Values

logger

private JLog logger
Logger used.


poolFactory

private PoolFactory<InstanceType,Clue> poolFactory
Factory used for delegate creating, matching, removing actions.


availableList

private java.util.List<InstanceType> availableList
List of available objects in the pool.


busyList

private java.util.List<InstanceType> busyList
List of objects which are currently busy and not available from the pool.


infoMap

private java.util.Map<InstanceType,PoolEntryStatistics> infoMap
Information on entries managed in the pool.


minSize

private int minSize
Minimum size of the pool.


maxSize

private int maxSize
Maximum size of the pool.


initSize

private int initSize
Initial size of the pool.


strict

private boolean strict
Maximum size of the pool is strict.


maxWaiters

private int maxWaiters
Max nb of waiters allowed to wait for an instance.


waiterTimeout

private long waiterTimeout
Max nb of milliseconds to wait for an object when the pool is full.


currentWaiters

private int currentWaiters
Current number of waiters.


highMaxWaiters

private int highMaxWaiters
Maximum number of waiters during current period.


totalWaiters

private int totalWaiters
Total nb of waiters since pool creation.


totalWaitingTime

private long totalWaitingTime
total waiting time in milliseconds.


highWaitingTime

private long highWaitingTime
Maximum waiting time during current period.


servedInstance

private int servedInstance
Total number of instances since the pool creation.


rejectedTimeout

private int rejectedTimeout
Total nb of instance not served due to timeout.


rejectedFull

private int rejectedFull
Total nb of instance not served due to an overflow of waiters.

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 PoolException
Gets an object from the pool.

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

get

public InstanceType get(Clue clue)
                 throws PoolException
Gets an object by using a specific hint.

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

release

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

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

discard

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

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

start

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

Specified by:
start in interface Pool<InstanceType,Clue>
Throws:
PoolException - if initialization fails

stop

public void stop()
          throws PoolException
Stop this pool.

Specified by:
stop in interface Pool<InstanceType,Clue>
Throws:
PoolException - if destroy fails