org.objectweb.jonas.dbm
Class Pool

java.lang.Object
  extended byorg.objectweb.jonas.dbm.Pool

public class Pool
extends java.lang.Object

Connection Pool

Author:
Philippe Durieux Contributor(s): 00/01/08 Markus Fritz make connection pooling thread safe (with same tx) introduce MaxAge for connections optimize pooling add some 'paranoia code': test conns before returning them from the pool. 00/18/04 Jun Inamori (j-office@osa.att.ne.jp) For closing correctly all connections at server shutdown. 01/11/06 Christophe Ney cney@batisseurs.com for Lutris Technologies Added ResourceManagerListener mechanism. 02/01/15 Dean Jennings - Map instead of Hashtable for lists 03/05/15 Adriana Danes - Introduce pool size configuration

Constructor Summary
Pool(ConnectionManager cmgr, XADataSourceImpl xads)
          Pool constructor
 
Method Summary
 void adjust()
          Adjust the pool size, according to poolMax and poolMin values.
 void closeAllConnections()
          Close all connections in the pool, when server is shut down.
 PoolItem closeConnection(javax.sql.XAConnection xac, int flag)
          Mark a specific Connection in the pool as closed.
 void freeConnections(javax.transaction.Transaction tx)
          The transaction has committed (or rolled back).
 int getBusyMaxRecent()
           
 int getBusyMinRecent()
           
 int getCheckLevel()
           
 int getConnectionFailures()
           
 int getConnectionLeaks()
           
 int getCurrentBusy()
           
 int getCurrentInTx()
           
 int getCurrentOpened()
           
 int getCurrentWaiters()
           
 int getMaxAge()
           
 long getMaxAgeMilli()
           
 int getMaxOpenTime()
           
 long getMaxOpenTimeMilli()
           
 int getMaxWaiters()
           
 int getMaxWaitTime()
           
 int getOpenedCount()
           
 int getPoolMax()
           
 int getPoolMin()
           
 int getRejectedFull()
           
 int getRejectedOpen()
           
 int getRejectedOther()
           
 int getRejectedTimeout()
           
 int getSamplingPeriod()
           
 int getServedOpen()
           
 java.lang.String getTestStatement()
           
 int getWaiterCount()
           
 int getWaitersHigh()
           
 int getWaitersHighRecent()
           
 long getWaitingHigh()
           
 long getWaitingHighRecent()
           
 long getWaitingTime()
           
 PoolItem openConnection(java.lang.String user, javax.transaction.Transaction tx)
          lookup connection in the pool for this user/tx
 void recomputeBusy()
          compute current min/max busyConnections
 void sampling()
          make samples with some monitoring values
 void setCheckLevel(int level)
           
 void setMaxAge(int mn)
           
 void setMaxOpenTime(int mn)
           
 void setMaxWaiters(int nb)
           
 void setMaxWaitTime(int sec)
           
 void setPoolMax(int max)
           
 void setPoolMin(int min)
           
 void setSamplingPeriod(int sec)
           
 void setTestStatement(java.lang.String s)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Pool

public Pool(ConnectionManager cmgr,
            XADataSourceImpl xads)
     throws java.lang.Exception
Pool constructor

Parameters:
xads - XA DataSource implementation created by this pool's Connection manager. Allows for getting XA Connections.
cmgr - the pool's Connection manager has to be registered as ConnectionEventListener of the XA connections created at the pool creation
Throws:
java.lang.Exception - The pool could not be initialized
Method Detail

getPoolMin

public int getPoolMin()
Returns:
min pool size

setPoolMin

public void setPoolMin(int min)
Parameters:
min - minimum connection pool size to be set.

getPoolMax

public int getPoolMax()
Returns:
actual max pool size

setPoolMax

public void setPoolMax(int max)
Parameters:
max - max pool size. -1 means "no limit".

getMaxAge

public int getMaxAge()
Returns:
max age for connections (in mm)

getMaxAgeMilli

public long getMaxAgeMilli()
Returns:
max age for connections (in millisec)

setMaxAge

public void setMaxAge(int mn)
Parameters:
mn - max age of connection in minutes

getMaxOpenTime

public int getMaxOpenTime()
Returns:
max age for connections (in mns)

getMaxOpenTimeMilli

public long getMaxOpenTimeMilli()
Returns:
max age for connections (in millisecs)

setMaxOpenTime

public void setMaxOpenTime(int mn)
Parameters:
mn - max time of open connection in minutes

getMaxWaitTime

public int getMaxWaitTime()
Returns:
waiter timeout in seconds

setMaxWaitTime

public void setMaxWaitTime(int sec)
Parameters:
sec - max time to wait for a connection, in seconds

getMaxWaiters

public int getMaxWaiters()
Returns:
max nb of waiters

setMaxWaiters

public void setMaxWaiters(int nb)
Parameters:
nb - max nb of waiters

getSamplingPeriod

public int getSamplingPeriod()
Returns:
sampling period in sec.

setSamplingPeriod

public void setSamplingPeriod(int sec)
Parameters:
sec - sampling period in sec.

getCheckLevel

public int getCheckLevel()
Returns:
connection checking level

setCheckLevel

public void setCheckLevel(int level)
Parameters:
level - jdbc connection checking level (0, 1, or 2)

getTestStatement

public java.lang.String getTestStatement()
Returns:
test statement used when checkLevel = 2.

setTestStatement

public void setTestStatement(java.lang.String s)
Parameters:
s - test statement

getBusyMaxRecent

public int getBusyMaxRecent()
Returns:
maximum nb of busy connections in last sampling period

getBusyMinRecent

public int getBusyMinRecent()
Returns:
minimum nb of busy connections in last sampling period

getCurrentWaiters

public int getCurrentWaiters()
Returns:
current number of connection waiters

getOpenedCount

public int getOpenedCount()
Returns:
int number of physical jdbc connection opened

getConnectionFailures

public int getConnectionFailures()
Returns:
int number of xa connection failures on open

getConnectionLeaks

public int getConnectionLeaks()
Returns:
int number of connection leaks

getServedOpen

public int getServedOpen()
Returns:
int number of xa connection served

getRejectedFull

public int getRejectedFull()
Returns:
int number of open calls that were rejected due to waiter overflow

getRejectedTimeout

public int getRejectedTimeout()
Returns:
int number of open calls that were rejected by timeout

getRejectedOther

public int getRejectedOther()
Returns:
int number of open calls that were rejected

getRejectedOpen

public int getRejectedOpen()
Returns:
int number of open calls that were rejected

getWaitersHigh

public int getWaitersHigh()
Returns:
maximum nb of waiters since the datasource creation

getWaitersHighRecent

public int getWaitersHighRecent()
Returns:
maximum nb of waiters in last sampling period

getWaiterCount

public int getWaiterCount()
Returns:
total nb of waiters since the datasource creation

getWaitingTime

public long getWaitingTime()
Returns:
total waiting time since the datasource creation

getWaitingHigh

public long getWaitingHigh()
Returns:
max waiting time since the datasource creation

getWaitingHighRecent

public long getWaitingHighRecent()
Returns:
max waiting time in last sampling period

getCurrentOpened

public int getCurrentOpened()
Returns:
int number of xa connection

getCurrentBusy

public int getCurrentBusy()
Returns:
int number of busy xa connection

recomputeBusy

public void recomputeBusy()
compute current min/max busyConnections


getCurrentInTx

public int getCurrentInTx()
Returns:
int number of xa connection reserved for tx

openConnection

public PoolItem openConnection(java.lang.String user,
                               javax.transaction.Transaction tx)
                        throws java.sql.SQLException
lookup connection in the pool for this user/tx

Parameters:
user - user name
tx - Transaction the connection is involved
Returns:
the free PoolItem (never null)
Throws:
java.sql.SQLException - Cannot open a connection because the pool's max size is reached

freeConnections

public void freeConnections(javax.transaction.Transaction tx)
The transaction has committed (or rolled back). We can return its connections to the pool of available connections.

Parameters:
tx - the non null transaction

closeConnection

public PoolItem closeConnection(javax.sql.XAConnection xac,
                                int flag)
Mark a specific Connection in the pool as closed. If it is no longer associated to a Tx, we can free it.

Parameters:
xac - XAConnection being closed
flag - TMSUCCESS (normal close) or TMFAIL (error)
Returns:
the PoolItem the connection is in (=> tx) or null if error.

sampling

public void sampling()
make samples with some monitoring values


adjust

public void adjust()
Adjust the pool size, according to poolMax and poolMin values. Also remove old connections in the freeList.


closeAllConnections

public void closeAllConnections()
Close all connections in the pool, when server is shut down.