org.objectweb.easybeans.dbpool
Class ConnectionManager

java.lang.Object
  extended by org.objectweb.easybeans.dbpool.ConnectionManager
All Implemented Interfaces:
java.io.Serializable, java.util.EventListener, javax.naming.Referenceable, javax.sql.ConnectionEventListener, javax.sql.DataSource, javax.sql.XADataSource
Direct Known Subclasses:
DummyDataSource

public class ConnectionManager
extends java.lang.Object
implements javax.sql.DataSource, javax.sql.XADataSource, javax.naming.Referenceable, java.io.Serializable, javax.sql.ConnectionEventListener

DataSource implementation. Manage a pool of connections.

Author:
Philippe Durieux, Florent Benoit
See Also:
Serialized Form

Field Summary
private  int busyMax
          count max busy connection during current period.
private  int busyMaxRecent
          maximum nb of busy connections in last sampling period.
private  int busyMin
          count min busy connection during current period.
private  int busyMinRecent
          minimum nb of busy connections in last sampling period.
private  int checkLevel
          Level of checking on connections when got from the pool.
private  java.lang.String className
          JDBC driver Class.
private static java.util.Map<java.lang.String,ConnectionManager> cmList
          List of all datasources.
private  int connectionFailures
          total nb of physical connection failures.
private  int connectionLeaks
          total nb of connection leaks.
private  int currentWaiters
          nb of threads waiting for a Connection.
private  java.lang.String dataSourceName
           
private static int DEFAULT_MAX_WAITERS
          Max waiters (by default).
private static int DEFAULT_PSTMT
          Default prepare statement.
private static int DEFAULT_SAMPLING
          Default sampling period.
private static int DEFAULT_TIMEOUT
          Default timeout.
private  java.lang.String dSName
          Datasource name.
private  java.util.TreeSet<JManagedConnection> freeList
          List of JManagedConnection not currently used.
private  int isolationLevel
          Isolation level for JDBC.
private  java.lang.String isolationStr
          Isolation level (but String format).
private  java.io.PrintWriter log
          PrintWriter used logging (DataSource impl).
private  JLog logger
          Logger.
private  int loginTimeout
          Login timeout (DataSource impl).
private static int MAX_REMOVE_FREELIST
          max number of remove at once in the freelist We avoid removing too much mcs at once for perf reasons.
private  long maxAge
          Max age of a Connection in milliseconds.
private  int maxAgeMn
          Same value in mns.
private  long maxOpenTime
          max open time for a connection, in millisec.
private  int maxOpenTimeMn
          Same value in mn.
private  int maxWaiters
          max nb of waiters allowed to wait for a Connection.
private  java.util.LinkedList<JManagedConnection> mcList
          Total list of JManagedConnection physically opened.
private static long MILLI
          Milliseconds.
private static int NO_LIMIT
          High Value for no limit for the connection pool.
private static long ONE_DAY
          Nb of milliseconds in a day.
private static long ONE_MIN_MILLI
          One minute in milliseconds.
private  int openedCount
          total number of opened physical connections since the datasource creation.
private  java.lang.String password
          default passwd.
private  int poolMax
          maximum size of the connection pool.
private  int poolMin
          minimum size of the connection pool.
private  int pstmtMax
          PreparedStatement pool size per managed connection.
private  int rejectedFull
          total nb of open connection failures because waiter overflow.
private  int rejectedOther
          total nb of open connection failures for any other reason.
private  int rejectedTimeout
          total nb of open connection failures because timeout.
private  int samplingPeriod
          sampling period in sec.
private static long serialVersionUID
          uid for Serializable class.
private  int servedOpen
          total number of opened connections since the datasource creation.
private  java.lang.String testStatement
          test statement used when checkLevel = 2.
private  javax.transaction.TransactionManager tm
          Transaction manager.
private  int totalWaiterCount
          total nb of waiters since datasource creation.
private  long totalWaitingTime
          total waiting time in milliseconds.
private  java.util.Map<javax.transaction.Transaction,JManagedConnection> tx2mc
          This HashMap gives the JManagedConnection from its transaction Requests with same tx get always the same connection.
private  java.lang.String url
          url for database.
private  java.lang.String userName
          default user.
private static long WAITER_TIMEOUT
          Default timeout for waiters (10s).
private  int waiterCount
          count max waiters during current period.
private  int waitersHigh
          maximum nb of waiters since datasource creation.
private  int waitersHighRecent
          maximum nb of waiters in last sampling period.
private  long waiterTimeout
          max nb of milliseconds to wait for a connection when pool is empty.
private  long waitingHigh
          max waiting time in milliseconds.
private  long waitingHighRecent
          max waiting time in milliseconds in last sampling period.
private  long waitingTime
          count max waiting time during current period.
 
Constructor Summary
ConnectionManager()
          Constructor for Factory.
 
Method Summary
 void adjust()
          Adjust the pool size, according to poolMax and poolMin values.
 java.lang.String checkConnection(java.lang.String testStatement)
          Check on a connection the test statement.
 void closeAllConnection()
          Close all connections in the pool, when server is shut down.
private  boolean closeConnection(JManagedConnection mc, int flag)
          Mark a specific Connection in the pool as closed.
 void connectionClosed(javax.sql.ConnectionEvent event)
          Notifies this ConnectionEventListener that the application has called the method close on its representation of a pooled connection.
 void connectionErrorOccurred(javax.sql.ConnectionEvent event)
          Notifies this ConnectionEventListener that a fatal error has occurred and the pooled connection can no longer be used.
private  void destroyItem(JManagedConnection mc)
          Destroy an mc because connection closed or error occured.
 void freeConnections(javax.transaction.Transaction tx)
          The transaction has committed (or rolled back).
private  void freeItem(JManagedConnection item)
          Free item and return it in the free list.
 int getBusyMaxRecent()
           
 int getBusyMinRecent()
           
 int getCheckLevel()
           
 java.lang.String getClassName()
           
 java.sql.Connection getConnection()
          
 java.sql.Connection getConnection(java.lang.String username, java.lang.String password)
          Attempts to establish a connection with the data source that this DataSource object represents.
 int getConnectionFailures()
           
 int getConnectionLeaks()
           
static ConnectionManager getConnectionManager(java.lang.String dsname)
          Gets the ConnectionManager matching the DataSource name.
 int getCurrentBusy()
           
 int getCurrentInTx()
           
 int getCurrentOpened()
           
 int getCurrentWaiters()
           
 java.lang.String getDatasourceName()
          Gets the name of the datasource.
 java.lang.String getDSName()
           
 int getLoginTimeout()
          
 java.io.PrintWriter getLogWriter()
          
 int getMaxAge()
           
 long getMaxAgeMilli()
           
 int getMaxOpenTime()
           
 long getMaxOpenTimeMilli()
           
 int getMaxWaiters()
           
 int getMaxWaitTime()
           
 int getOpenedCount()
           
 java.lang.String getPassword()
           
 int getPoolMax()
           
 int getPoolMin()
           
 int getPstmtMax()
           
 javax.naming.Reference getReference()
          Retrieves the Reference of this object.
 int getRejectedFull()
           
 int getRejectedOpen()
           
 int getRejectedOther()
           
 int getRejectedTimeout()
           
 int getSamplingPeriod()
           
 int getServedOpen()
           
 java.lang.String getTestStatement()
           
 java.lang.String getTransactionIsolation()
          Gets the transaction isolation level.
 java.lang.String getUrl()
           
 java.lang.String getUserName()
           
 int getWaiterCount()
           
 int getWaitersHigh()
           
 int getWaitersHighRecent()
           
 long getWaitingHigh()
           
 long getWaitingHighRecent()
           
 long getWaitingTime()
           
 javax.sql.XAConnection getXAConnection()
          Attempts to establish a physical database connection that can be used in a distributed transaction.
 javax.sql.XAConnection getXAConnection(java.lang.String user, java.lang.String passwd)
          Attempts to establish a physical database connection, using the given user name and password.
 JManagedConnection openConnection(java.lang.String user, javax.transaction.Transaction tx)
          Lookup connection in the pool for this user/tx.
 void poolConfigure(java.lang.String connchecklevel, java.lang.String connmaxage, java.lang.String maxopentime, java.lang.String connteststmt, java.lang.String pstmtmax, java.lang.String minconpool, java.lang.String maxconpool, java.lang.String maxwaittime, java.lang.String maxwaiters, java.lang.String samplingperiod)
          Configure the Connection pool.
 void recomputeBusy()
          compute current min/max busyConnections.
 void sampling()
          make samples with some monitoring values.
 void setCheckLevel(int level)
           
 void setClassName(java.lang.String className)
          Sets the driver class for JDBC.
 void setDatasourceName(java.lang.String dataSourceName)
          Sets the name of the datasource.
 void setDSName(java.lang.String s)
           
 void setLoginTimeout(int seconds)
          
 void setLogWriter(java.io.PrintWriter out)
          
 void setMaxAge(int mn)
           
 void setMaxOpenTime(int mn)
           
 void setMaxWaiters(int nb)
           
 void setMaxWaitTime(int sec)
           
 void setPassword(java.lang.String password)
          Sets the password used to get connections.
 void setPoolMax(int max)
           
 void setPoolMin(int min)
           
 void setPstmtMax(int nb)
           
 void setSamplingPeriod(int sec)
           
 void setTestStatement(java.lang.String s)
           
protected  void setTm(javax.transaction.TransactionManager tm)
          Sets the transaction managed used by the connections.
 void setTransactionIsolation(java.lang.String level)
          Sets the transaction isolation level of the connections.
 void setUrl(java.lang.String url)
          Sets the url to get connections.
 void setUserName(java.lang.String userName)
          Sets the user for getting connections.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
uid for Serializable class.

See Also:
Constant Field Values

logger

private JLog logger
Logger.


MILLI

private static final long MILLI
Milliseconds.

See Also:
Constant Field Values

ONE_MIN_MILLI

private static final long ONE_MIN_MILLI
One minute in milliseconds.

See Also:
Constant Field Values

DEFAULT_TIMEOUT

private static final int DEFAULT_TIMEOUT
Default timeout.

See Also:
Constant Field Values

WAITER_TIMEOUT

private static final long WAITER_TIMEOUT
Default timeout for waiters (10s).

See Also:
Constant Field Values

DEFAULT_MAX_WAITERS

private static final int DEFAULT_MAX_WAITERS
Max waiters (by default).

See Also:
Constant Field Values

DEFAULT_PSTMT

private static final int DEFAULT_PSTMT
Default prepare statement.

See Also:
Constant Field Values

DEFAULT_SAMPLING

private static final int DEFAULT_SAMPLING
Default sampling period.

See Also:
Constant Field Values

cmList

private static java.util.Map<java.lang.String,ConnectionManager> cmList
List of all datasources.


tm

private javax.transaction.TransactionManager tm
Transaction manager.


freeList

private java.util.TreeSet<JManagedConnection> freeList
List of JManagedConnection not currently used. This avoids closing and reopening physical connections. We try to keep a minimum of minConPool elements here.


mcList

private java.util.LinkedList<JManagedConnection> mcList
Total list of JManagedConnection physically opened.


tx2mc

private java.util.Map<javax.transaction.Transaction,JManagedConnection> tx2mc
This HashMap gives the JManagedConnection from its transaction Requests with same tx get always the same connection.


loginTimeout

private int loginTimeout
Login timeout (DataSource impl).


log

private java.io.PrintWriter log
PrintWriter used logging (DataSource impl).


dSName

private java.lang.String dSName
Datasource name.


dataSourceName

private java.lang.String dataSourceName

url

private java.lang.String url
url for database.


className

private java.lang.String className
JDBC driver Class.


userName

private java.lang.String userName
default user.


password

private java.lang.String password
default passwd.


isolationLevel

private int isolationLevel
Isolation level for JDBC.


isolationStr

private java.lang.String isolationStr
Isolation level (but String format).


waiterCount

private int waiterCount
count max waiters during current period.


waitingTime

private long waitingTime
count max waiting time during current period.


busyMax

private int busyMax
count max busy connection during current period.


busyMin

private int busyMin
count min busy connection during current period.


NO_LIMIT

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

See Also:
Constant Field Values

ONE_DAY

private static final long ONE_DAY
Nb of milliseconds in a day.

See Also:
Constant Field Values

MAX_REMOVE_FREELIST

private static final int MAX_REMOVE_FREELIST
max number of remove at once in the freelist We avoid removing too much mcs at once for perf reasons.

See Also:
Constant Field Values

poolMin

private int poolMin
minimum size of the connection pool.


poolMax

private int poolMax
maximum size of the connection pool. default value is "NO LIMIT".


maxAge

private long maxAge
Max age of a Connection in milliseconds. When the time is elapsed, the connection will be closed. This avoids keeping connections open too long for nothing.


maxAgeMn

private int maxAgeMn
Same value in mns.


maxOpenTime

private long maxOpenTime
max open time for a connection, in millisec.


maxOpenTimeMn

private int maxOpenTimeMn
Same value in mn.


waiterTimeout

private long waiterTimeout
max nb of milliseconds to wait for a connection when pool is empty.


maxWaiters

private int maxWaiters
max nb of waiters allowed to wait for a Connection.


samplingPeriod

private int samplingPeriod
sampling period in sec.


checkLevel

private int checkLevel
Level of checking on connections when got from the pool. this avoids reusing bad connections because too old, for example when database was restarted... 0 = no checking 1 = check that still physically opened. 2 = try a null statement.


pstmtMax

private int pstmtMax
PreparedStatement pool size per managed connection.


testStatement

private java.lang.String testStatement
test statement used when checkLevel = 2.


busyMaxRecent

private int busyMaxRecent
maximum nb of busy connections in last sampling period.


busyMinRecent

private int busyMinRecent
minimum nb of busy connections in last sampling period.


currentWaiters

private int currentWaiters
nb of threads waiting for a Connection.


openedCount

private int openedCount
total number of opened physical connections since the datasource creation.


connectionFailures

private int connectionFailures
total nb of physical connection failures.


connectionLeaks

private int connectionLeaks
total nb of connection leaks. A connection leak occurs when the caller never issues a close method on the connection.


servedOpen

private int servedOpen
total number of opened connections since the datasource creation.


rejectedFull

private int rejectedFull
total nb of open connection failures because waiter overflow.


rejectedTimeout

private int rejectedTimeout
total nb of open connection failures because timeout.


rejectedOther

private int rejectedOther
total nb of open connection failures for any other reason.


waitersHigh

private int waitersHigh
maximum nb of waiters since datasource creation.


waitersHighRecent

private int waitersHighRecent
maximum nb of waiters in last sampling period.


totalWaiterCount

private int totalWaiterCount
total nb of waiters since datasource creation.


totalWaitingTime

private long totalWaitingTime
total waiting time in milliseconds.


waitingHigh

private long waitingHigh
max waiting time in milliseconds.


waitingHighRecent

private long waitingHighRecent
max waiting time in milliseconds in last sampling period.

Constructor Detail

ConnectionManager

public ConnectionManager()
Constructor for Factory.

Method Detail

getConnectionManager

public static ConnectionManager getConnectionManager(java.lang.String dsname)
Gets the ConnectionManager matching the DataSource name.

Parameters:
dsname - datasource name.
Returns:
a connection manager impl.

getDSName

public java.lang.String getDSName()
Returns:
Jndi name of the datasource

setDSName

public void setDSName(java.lang.String s)
Parameters:
s - Jndi name for the datasource

getDatasourceName

public java.lang.String getDatasourceName()
Gets the name of the datasource.

Returns:
the name of the datasource

setDatasourceName

public void setDatasourceName(java.lang.String dataSourceName)
Sets the name of the datasource.

Parameters:
dataSourceName - the name of the datasource

getUrl

public java.lang.String getUrl()
Returns:
the url used to get the connection.

setUrl

public void setUrl(java.lang.String url)
Sets the url to get connections.

Parameters:
url - the url for JDBC connections.

getClassName

public java.lang.String getClassName()
Returns:
the JDBC driver class name.

setClassName

public void setClassName(java.lang.String className)
                  throws java.lang.ClassNotFoundException
Sets the driver class for JDBC.

Parameters:
className - the name of the JDBC driver
Throws:
java.lang.ClassNotFoundException - if driver is not found

getUserName

public java.lang.String getUserName()
Returns:
the user used for getting connections.

setUserName

public void setUserName(java.lang.String userName)
Sets the user for getting connections.

Parameters:
userName - the name of the user.

getPassword

public java.lang.String getPassword()
Returns:
the password used for connections.

setPassword

public void setPassword(java.lang.String password)
Sets the password used to get connections.

Parameters:
password - the password value.

setTransactionIsolation

public void setTransactionIsolation(java.lang.String level)
Sets the transaction isolation level of the connections.

Parameters:
level - the level of isolation.

getTransactionIsolation

public java.lang.String getTransactionIsolation()
Gets the transaction isolation level.

Returns:
transaction isolation level.

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)

getPstmtMax

public int getPstmtMax()
Returns:
PreparedStatement cache size.

setPstmtMax

public void setPstmtMax(int nb)
Parameters:
nb - PreparedStatement cache size.

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

poolConfigure

public void poolConfigure(java.lang.String connchecklevel,
                          java.lang.String connmaxage,
                          java.lang.String maxopentime,
                          java.lang.String connteststmt,
                          java.lang.String pstmtmax,
                          java.lang.String minconpool,
                          java.lang.String maxconpool,
                          java.lang.String maxwaittime,
                          java.lang.String maxwaiters,
                          java.lang.String samplingperiod)
Configure the Connection pool. Called by the Container at init. Configuration can be set in datasource.properties files.

Parameters:
connchecklevel - JDBC connection checking level
connmaxage - JDBC connection maximum age
maxopentime - JDBC connection maximum open time
connteststmt - SQL query for test statement
pstmtmax - prepare statement pool size per managed connection
minconpool - Min size for the connection pool
maxconpool - Max size for the connection pool
maxwaittime - Max time to wait for a connection (in seconds)
maxwaiters - Max nb of waiters for a connection
samplingperiod - sampling period in sec.

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.

getLoginTimeout

public int getLoginTimeout()
                    throws java.sql.SQLException

Specified by:
getLoginTimeout in interface javax.sql.DataSource
Specified by:
getLoginTimeout in interface javax.sql.XADataSource
Throws:
java.sql.SQLException

setLoginTimeout

public void setLoginTimeout(int seconds)
                     throws java.sql.SQLException

Specified by:
setLoginTimeout in interface javax.sql.DataSource
Specified by:
setLoginTimeout in interface javax.sql.XADataSource
Throws:
java.sql.SQLException

getLogWriter

public java.io.PrintWriter getLogWriter()
                                 throws java.sql.SQLException

Specified by:
getLogWriter in interface javax.sql.DataSource
Specified by:
getLogWriter in interface javax.sql.XADataSource
Throws:
java.sql.SQLException

setLogWriter

public void setLogWriter(java.io.PrintWriter out)
                  throws java.sql.SQLException

Specified by:
setLogWriter in interface javax.sql.DataSource
Specified by:
setLogWriter in interface javax.sql.XADataSource
Throws:
java.sql.SQLException

getConnection

public java.sql.Connection getConnection()
                                  throws java.sql.SQLException

Specified by:
getConnection in interface javax.sql.DataSource
Throws:
java.sql.SQLException

getConnection

public java.sql.Connection getConnection(java.lang.String username,
                                         java.lang.String password)
                                  throws java.sql.SQLException
Attempts to establish a connection with the data source that this DataSource object represents. - comes from the javax.sql.DataSource interface

Specified by:
getConnection in interface javax.sql.DataSource
Parameters:
username - - the database user on whose behalf the connection is being made
password - - the user's password
Returns:
a connection to the data source
Throws:
java.sql.SQLException - - if a database access error occurs

getXAConnection

public javax.sql.XAConnection getXAConnection()
                                       throws java.sql.SQLException
Attempts to establish a physical database connection that can be used in a distributed transaction.

Specified by:
getXAConnection in interface javax.sql.XADataSource
Returns:
an XAConnection object, which represents a physical connection to a data source, that can be used in a distributed transaction
Throws:
java.sql.SQLException - if a database access error occurs

getXAConnection

public javax.sql.XAConnection getXAConnection(java.lang.String user,
                                              java.lang.String passwd)
                                       throws java.sql.SQLException
Attempts to establish a physical database connection, using the given user name and password. The connection that is returned is one that can be used in a distributed transaction - comes from the javax.sql.XADataSource interface

Specified by:
getXAConnection in interface javax.sql.XADataSource
Parameters:
user - - the database user on whose behalf the connection is being made
passwd - - the user's password
Returns:
an XAConnection object, which represents a physical connection to a data source, that can be used in a distributed transaction
Throws:
java.sql.SQLException - - if a database access error occurs

getReference

public javax.naming.Reference getReference()
                                    throws javax.naming.NamingException
Retrieves the Reference of this object. Used at binding time by JNDI to build a reference on this object.

Specified by:
getReference in interface javax.naming.Referenceable
Returns:
The non-null Reference of this object.
Throws:
javax.naming.NamingException - If a naming exception was encountered while retrieving the reference.

connectionClosed

public void connectionClosed(javax.sql.ConnectionEvent event)
Notifies this ConnectionEventListener that the application has called the method close on its representation of a pooled connection.

Specified by:
connectionClosed in interface javax.sql.ConnectionEventListener
Parameters:
event - an event object describing the source of the event

connectionErrorOccurred

public void connectionErrorOccurred(javax.sql.ConnectionEvent event)
Notifies this ConnectionEventListener that a fatal error has occurred and the pooled connection can no longer be used. The driver makes this notification just before it throws the application the SQLException contained in the given ConnectionEvent object.

Specified by:
connectionErrorOccurred in interface javax.sql.ConnectionEventListener
Parameters:
event - an event object describing the source of the event and containing the SQLException that the driver is about to throw

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.

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.


openConnection

public JManagedConnection 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:
a free JManagedConnection (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

closeAllConnection

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


closeConnection

private boolean closeConnection(JManagedConnection mc,
                                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:
mc - XAConnection being closed
flag - TMSUCCESS (normal close) or TMFAIL (error) or null if error.
Returns:
false if has not be closed (still in use)

freeItem

private void freeItem(JManagedConnection item)
Free item and return it in the free list.

Parameters:
item - The item to be freed

destroyItem

private void destroyItem(JManagedConnection mc)
Destroy an mc because connection closed or error occured.

Parameters:
mc - The mc to be destroyed

checkConnection

public java.lang.String checkConnection(java.lang.String testStatement)
                                 throws java.sql.SQLException
Check on a connection the test statement.

Parameters:
testStatement - the statement to use for test
Returns:
the test statement if the test succeeded, an error message otherwise
Throws:
java.sql.SQLException - If an error occured when trying to test (not due to the test itself, but to other preliminary or post operation).

setTm

protected void setTm(javax.transaction.TransactionManager tm)
Sets the transaction managed used by the connections.

Parameters:
tm - the transaction manager.