org.objectweb.jonas.dbm
Class ConnectionManager

java.lang.Object
  extended byorg.objectweb.jonas.management.ReconfigDispatcher
      extended byorg.objectweb.jonas.dbm.ConnectionManager
All Implemented Interfaces:
javax.sql.ConnectionEventListener, ConnectionManagerMBean, javax.sql.DataSource, java.util.EventListener, javax.management.NotificationBroadcaster, ReconfigDispatcherMBean, javax.naming.Referenceable, java.io.Serializable

public class ConnectionManager
extends ReconfigDispatcher
implements javax.sql.DataSource, javax.naming.Referenceable, java.io.Serializable, javax.sql.ConnectionEventListener, ConnectionManagerMBean

JOnAS generic implementation of DataSource to manage an underlying JDBC-XA driver (XADataSource, XAConnection, XAResource, ...) This class acts as a factory for Connection objects. Its main goal is to manage a pool of XAConnection objects, to avoid closing the actual Connection on DBMS, and to deal with distributed transactions. This DataSource is registered in JNDI (=> implements Referenceable)

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 cmList

Adriana Danes

03/01/13 - Manage datasource name additionally to the jndi name for the datasource using this ConnectionManager

03/04/08 - ConnectionManager extends ReconfigDispatcher in order to send reconfiguration Notifications to ReconfigManager

03/05/23 - Introduce pool size configuration

See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.objectweb.jonas.management.ReconfigDispatcher
RECONFIG_TYPE, SAVE_RECONFIG_TYPE
 
Constructor Summary
ConnectionManager()
          Constructor for Factory
ConnectionManager(boolean isClient)
          Constructor for the client case
 
Method Summary
 void closeAllConnection()
           
 void connectionClosed(javax.sql.ConnectionEvent event)
          Invoked when the application calls close() on its representation of the connection.
 void connectionErrorOccurred(javax.sql.ConnectionEvent event)
          Invoked when a fatal connection error occurs, just before an SQLException is thrown to the application.
 java.lang.Integer getBusyMaxRecent()
          MBean method:
 java.lang.Integer getBusyMinRecent()
          MBean method:
 java.lang.String getClassName()
           
 java.sql.Connection getConnection()
          Attempt to establish a database connection.
 java.sql.Connection getConnection(java.lang.String username, java.lang.String password)
          Attempt to establish a database connection.
 java.lang.Integer getConnectionFailures()
          MBean method:
 java.lang.Integer getConnectionLeaks()
          MBean method:
static ConnectionManager getConnectionManager(java.lang.String dsname)
          get the ConnectionManager matching the DataSource name
 java.lang.Integer getCurrentBusy()
          MBean method:
 java.lang.Integer getCurrentInTx()
          MBean method:
 java.lang.Integer getCurrentOpened()
          MBean method:
 java.lang.Integer getCurrentWaiters()
          MBean method:
 java.lang.String getDataSourceDescription()
          MBean Method:
 java.lang.String getDatasourceName()
           
 java.lang.String getDataSourceType()
          Mbean Method: return the type of this data source
 java.lang.String getDSName()
          MBean method:
 java.lang.Integer getJDBCConnCheckLevel()
          MBean method:
 java.lang.Integer getJDBCConnMaxAge()
          MBean method:
 java.lang.Integer getJDBCMaxConnPool()
          MBean method:
 java.lang.Integer getJDBCMaxOpenTime()
          MBean method:
 java.lang.Integer getJDBCMaxWaiters()
          MBean method:
 java.lang.Integer getJDBCMaxWaitTime()
          MBean method:
 java.lang.Integer getJDBCMinConnPool()
          MBean method:
 java.lang.Integer getJDBCSamplingPeriod()
          MBean method:
 java.lang.String getJDBCTestStatement()
          MBean method:
 int getLoginTimeout()
          Gets the maximum time in seconds that this data source can wait while attempting to connect to a database.
 java.io.PrintWriter getLogWriter()
          Get the log writer for this data source.
 java.lang.String getMapperName()
           
 java.lang.Integer getOpenedCount()
          MBean method:
 java.lang.String getPassword()
           
 Pool getPool()
           
 javax.naming.Reference getReference()
          Retrieves the Reference of this object.
 java.lang.Integer getRejectedFull()
          Management method:
 java.lang.Integer getRejectedOpen()
          Management method:
 java.lang.Integer getRejectedOther()
          Management method:
 java.lang.Integer getRejectedTimeout()
          Management method:
static org.objectweb.transaction.api.ResourceManagerEventListener getResourceManagerEventListener()
           
 java.lang.Integer getServedOpen()
          Management method:
 java.lang.String getTransactionIsolation()
           
 java.lang.String getUrl()
           
 java.lang.String getUserName()
           
 java.lang.Integer getWaiterCount()
          MBean method:
 java.lang.Integer getWaitersHigh()
          MBean method:
 java.lang.Integer getWaitersHighRecent()
          MBean method:
 java.lang.Long getWaitingHigh()
          MBean method:
 java.lang.Long getWaitingHighRecent()
          MBean method:
 java.lang.Long getWaitingTime()
          MBean method:
 boolean isClientCase()
          This manager is in the client case or not ?
 void poolConfigure(java.lang.String connchecklevel, java.lang.String connmaxage, java.lang.String maxopentime, java.lang.String connteststmt, 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 saveConfig()
          save updated configuration
 void setClassName(java.lang.String s)
           
 void setDataSourceDescription(java.lang.String dsDesc)
          Management Method:
 void setDatasourceName(java.lang.String s)
           
 void setDSName(java.lang.String s)
           
 void setJDBCConnCheckLevel(java.lang.Integer level)
          MBean method allowing to set the JDBC connection checking level value
 void setJDBCConnMaxAge(java.lang.Integer mn)
          MBean method allowing to set the JDBC connection maximum age
 void setJDBCMaxConnPool(java.lang.Integer max)
          MBean method allowing to set the maximum size of connection pool
 void setJDBCMaxOpenTime(java.lang.Integer mn)
          MBean method allowing to set the JDBC connection max open time
 void setJDBCMaxWaiters(java.lang.Integer max)
          MBean method allowing to set the maximum nb of concurrent waiters for a JDBC Connection.
 void setJDBCMaxWaitTime(java.lang.Integer max)
          MBean method allowing to set the maximum time to wait for a connection
 void setJDBCMinConnPool(java.lang.Integer min)
          MBean method allowing to set the minimum size of connection pool
 void setJDBCSamplingPeriod(java.lang.Integer i)
          MBean method allowing to set the sampling period
 void setJDBCTestStatement(java.lang.String test)
          MBean method allowing to set the SQL query for test statement
 void setLoginTimeout(int seconds)
          Sets the maximum time in seconds that this data source will wait while attempting to connect to a database.
 void setLogWriter(java.io.PrintWriter out)
          Set the log writer for this data source.
 void setMapperName(java.lang.String mappername)
          Set the Mapper Name
 void setPassword(java.lang.String s)
           
 void setRMEListener(org.objectweb.transaction.api.ResourceManagerEventListener rmel)
           
 void setTransactionIsolation(java.lang.String level)
           
 void setUrl(java.lang.String s)
           
 void setUserName(java.lang.String s)
           
 
Methods inherited from class org.objectweb.jonas.management.ReconfigDispatcher
addNotificationListener, getFilter, getHandback, getListener, getNotificationInfo, initLogger, removeNotificationListener, sendReconfigNotification, sendSaveNotification
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConnectionManager

public ConnectionManager()
                  throws java.lang.Exception
Constructor for Factory


ConnectionManager

public ConnectionManager(boolean isClient)
                  throws java.lang.Exception
Constructor for the client case

Parameters:
isClient - true if this is the client case TODO : must be removed. A client can lookup a datasource
Method Detail

getPool

public Pool getPool()
Returns:
The pool associated to this datasource

isClientCase

public boolean isClientCase()
This manager is in the client case or not ?

Returns:
boolean true if this is the client case TODO : must be removed. A client can lookup a datasource

setRMEListener

public void setRMEListener(org.objectweb.transaction.api.ResourceManagerEventListener rmel)

setDSName

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

getUrl

public java.lang.String getUrl()
Specified by:
getUrl in interface ConnectionManagerMBean
Returns:
String data source url

setUrl

public void setUrl(java.lang.String s)

getClassName

public java.lang.String getClassName()
Specified by:
getClassName in interface ConnectionManagerMBean
Returns:
String data source class name

setClassName

public void setClassName(java.lang.String s)
                  throws java.lang.ClassNotFoundException
Throws:
java.lang.ClassNotFoundException

getUserName

public java.lang.String getUserName()
Specified by:
getUserName in interface ConnectionManagerMBean
Returns:
String data source user

setUserName

public void setUserName(java.lang.String s)

getPassword

public java.lang.String getPassword()
Specified by:
getPassword in interface ConnectionManagerMBean
Returns:
String data source password

setPassword

public void setPassword(java.lang.String s)

setTransactionIsolation

public void setTransactionIsolation(java.lang.String level)

getTransactionIsolation

public java.lang.String getTransactionIsolation()

setMapperName

public void setMapperName(java.lang.String mappername)
Description copied from interface: ConnectionManagerMBean
Set the Mapper Name

Specified by:
setMapperName in interface ConnectionManagerMBean
Parameters:
mappername - mapper name

getMapperName

public java.lang.String getMapperName()
Specified by:
getMapperName in interface ConnectionManagerMBean
Returns:
String Mapper Name

poolConfigure

public void poolConfigure(java.lang.String connchecklevel,
                          java.lang.String connmaxage,
                          java.lang.String maxopentime,
                          java.lang.String connteststmt,
                          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
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.

getConnection

public java.sql.Connection getConnection()
                                  throws java.sql.SQLException
Attempt to establish a database connection.

Specified by:
getConnection in interface javax.sql.DataSource
Returns:
a Connection to the database
Throws:
java.sql.SQLException - - if a database-access error occurs.

getConnection

public java.sql.Connection getConnection(java.lang.String username,
                                         java.lang.String password)
                                  throws java.sql.SQLException
Attempt to establish a database connection.

Specified by:
getConnection in interface javax.sql.DataSource
Parameters:
password - - the user's password
Returns:
a Connection to the database
Throws:
java.sql.SQLException - - if a database-access error occurs.

getLogWriter

public java.io.PrintWriter getLogWriter()
                                 throws java.sql.SQLException
Get the log writer for this data source. The log writer is a character output stream to which all logging and tracing messages for this data source object instance will be printed. This includes messages printed by the methods of this object, messages printed by methods of other objects manufactured by this object, and so on. Messages printed to a data source specificlog writer are not printed to the log writer associated with the Drivermanager class. When a data source object is created the log writer is initially null, in other words, logging is disabled.

Specified by:
getLogWriter in interface javax.sql.DataSource
Returns:
the log writer for this data source, null if disabled
Throws:
java.sql.SQLException - - if a database-access error occurs.

setLogWriter

public void setLogWriter(java.io.PrintWriter out)
                  throws java.sql.SQLException
Set the log writer for this data source. The log writer is a character output stream to which all logging and tracing messages for this data source object instance will be printed. This includes messages printed by the methods of this object, messages printed by methods of other objects manufactured by this object, and so on. Messages printed to a data source specific log writer are not printed to the log writer associated with the Drivermanager class. When a data source object is created the log writer is initially null, in other words, logging is disabled.

Specified by:
setLogWriter in interface javax.sql.DataSource
Parameters:
out - - the new log writer; to disable, set to null
Throws:
java.sql.SQLException - - if a database-access error occurs.

setLoginTimeout

public void setLoginTimeout(int seconds)
                     throws java.sql.SQLException
Sets the maximum time in seconds that this data source will wait while attempting to connect to a database. A value of zero specifies that the timeout is the default system timeout if there is one; otherwise it specifies that there is no timeout. When a data source object is created the login timeout is initially zero.

Specified by:
setLoginTimeout in interface javax.sql.DataSource
Parameters:
seconds - - the data source login time limit
Throws:
java.sql.SQLException - - if a database access error occurs.

getLoginTimeout

public int getLoginTimeout()
                    throws java.sql.SQLException
Gets the maximum time in seconds that this data source can wait while attempting to connect to a database. A value of zero means that the timeout is the default system timeout if there is one; otherwise it means that there is no timeout. When a data source object is created the login timeout is initially zero.

Specified by:
getLoginTimeout in interface javax.sql.DataSource
Returns:
the data source login time limit
Throws:
java.sql.SQLException - - if a database access error occurs.

connectionClosed

public void connectionClosed(javax.sql.ConnectionEvent event)
Invoked when the application calls close() on its representation of the 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)
Invoked when a fatal connection error occurs, just before an SQLException is thrown to the application.

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

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.

getConnectionManager

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


closeAllConnection

public void closeAllConnection()

getResourceManagerEventListener

public static org.objectweb.transaction.api.ResourceManagerEventListener getResourceManagerEventListener()

getCurrentOpened

public java.lang.Integer getCurrentOpened()
MBean method:

Specified by:
getCurrentOpened in interface ConnectionManagerMBean
Returns:
Integer number of open connection in this ds

getCurrentBusy

public java.lang.Integer getCurrentBusy()
MBean method:

Specified by:
getCurrentBusy in interface ConnectionManagerMBean
Returns:
Integer number of busy connection in this ds

getOpenedCount

public java.lang.Integer getOpenedCount()
MBean method:

Specified by:
getOpenedCount in interface ConnectionManagerMBean
Returns:
Integer number of connection served

getConnectionFailures

public java.lang.Integer getConnectionFailures()
MBean method:

Specified by:
getConnectionFailures in interface ConnectionManagerMBean
Returns:
Integer number of connection failures

getConnectionLeaks

public java.lang.Integer getConnectionLeaks()
MBean method:

Specified by:
getConnectionLeaks in interface ConnectionManagerMBean
Returns:
Integer number of connection leaks

getServedOpen

public java.lang.Integer getServedOpen()
Management method:

Specified by:
getServedOpen in interface ConnectionManagerMBean
Returns:
Integer number of xa connection served

getRejectedOpen

public java.lang.Integer getRejectedOpen()
Management method:

Specified by:
getRejectedOpen in interface ConnectionManagerMBean
Returns:
Integer number of open calls that were rejected

getRejectedFull

public java.lang.Integer getRejectedFull()
Management method:

Specified by:
getRejectedFull in interface ConnectionManagerMBean
Returns:
Integer number of open calls that were rejected

getRejectedTimeout

public java.lang.Integer getRejectedTimeout()
Management method:

Specified by:
getRejectedTimeout in interface ConnectionManagerMBean
Returns:
Integer number of open calls that were rejected

getRejectedOther

public java.lang.Integer getRejectedOther()
Management method:

Specified by:
getRejectedOther in interface ConnectionManagerMBean
Returns:
Integer number of open calls that were rejected

getCurrentWaiters

public java.lang.Integer getCurrentWaiters()
MBean method:

Specified by:
getCurrentWaiters in interface ConnectionManagerMBean
Returns:
Integer current number of connection waiters

getWaitersHigh

public java.lang.Integer getWaitersHigh()
MBean method:

Specified by:
getWaitersHigh in interface ConnectionManagerMBean
Returns:
Maximum nb of waiters since datasource creation.

getWaitersHighRecent

public java.lang.Integer getWaitersHighRecent()
MBean method:

Specified by:
getWaitersHighRecent in interface ConnectionManagerMBean
Returns:
Maximum nb of waiters in last sampling period

getBusyMaxRecent

public java.lang.Integer getBusyMaxRecent()
MBean method:

Specified by:
getBusyMaxRecent in interface ConnectionManagerMBean
Returns:
Maximum nb of busy connections in last sampling period

getBusyMinRecent

public java.lang.Integer getBusyMinRecent()
MBean method:

Specified by:
getBusyMinRecent in interface ConnectionManagerMBean
Returns:
Minimum nb of busy connections in last sampling period

getWaiterCount

public java.lang.Integer getWaiterCount()
MBean method:

Specified by:
getWaiterCount in interface ConnectionManagerMBean
Returns:
Total nb of waiters since datasource creation.

getWaitingTime

public java.lang.Long getWaitingTime()
MBean method:

Specified by:
getWaitingTime in interface ConnectionManagerMBean
Returns:
Total waiting time (millisec) since datasource creation.

getWaitingHigh

public java.lang.Long getWaitingHigh()
MBean method:

Specified by:
getWaitingHigh in interface ConnectionManagerMBean
Returns:
Maximum waiting time (millisec) since datasource creation.

getWaitingHighRecent

public java.lang.Long getWaitingHighRecent()
MBean method:

Specified by:
getWaitingHighRecent in interface ConnectionManagerMBean
Returns:
Maximum waiting time (millisec) in last sampling period

getCurrentInTx

public java.lang.Integer getCurrentInTx()
MBean method:

Specified by:
getCurrentInTx in interface ConnectionManagerMBean
Returns:
number of connection in tx

getDSName

public java.lang.String getDSName()
MBean method:

Specified by:
getDSName in interface ConnectionManagerMBean
Returns:
Jndi name of the datasource

getDatasourceName

public java.lang.String getDatasourceName()
Specified by:
getDatasourceName in interface ConnectionManagerMBean
Returns:
datasource name

setDatasourceName

public void setDatasourceName(java.lang.String s)
Parameters:
s - datasource name

getJDBCConnCheckLevel

public java.lang.Integer getJDBCConnCheckLevel()
MBean method:

Specified by:
getJDBCConnCheckLevel in interface ConnectionManagerMBean
Returns:
connection level

setJDBCConnCheckLevel

public void setJDBCConnCheckLevel(java.lang.Integer level)
MBean method allowing to set the JDBC connection checking level value

Specified by:
setJDBCConnCheckLevel in interface ConnectionManagerMBean
Parameters:
level - connection level

getJDBCConnMaxAge

public java.lang.Integer getJDBCConnMaxAge()
MBean method:

Specified by:
getJDBCConnMaxAge in interface ConnectionManagerMBean
Returns:
connection max age

setJDBCConnMaxAge

public void setJDBCConnMaxAge(java.lang.Integer mn)
MBean method allowing to set the JDBC connection maximum age

Specified by:
setJDBCConnMaxAge in interface ConnectionManagerMBean
Parameters:
mn - connection max age

getJDBCMaxOpenTime

public java.lang.Integer getJDBCMaxOpenTime()
MBean method:

Specified by:
getJDBCMaxOpenTime in interface ConnectionManagerMBean
Returns:
connection max open time

setJDBCMaxOpenTime

public void setJDBCMaxOpenTime(java.lang.Integer mn)
MBean method allowing to set the JDBC connection max open time

Specified by:
setJDBCMaxOpenTime in interface ConnectionManagerMBean
Parameters:
mn - connection max open time in minutes

getJDBCMinConnPool

public java.lang.Integer getJDBCMinConnPool()
MBean method:

Specified by:
getJDBCMinConnPool in interface ConnectionManagerMBean
Returns:
min size of connection pool

setJDBCMinConnPool

public void setJDBCMinConnPool(java.lang.Integer min)
MBean method allowing to set the minimum size of connection pool

Specified by:
setJDBCMinConnPool in interface ConnectionManagerMBean
Parameters:
min -

getJDBCMaxConnPool

public java.lang.Integer getJDBCMaxConnPool()
MBean method:

Specified by:
getJDBCMaxConnPool in interface ConnectionManagerMBean
Returns:
max size of connection pool

setJDBCMaxConnPool

public void setJDBCMaxConnPool(java.lang.Integer max)
MBean method allowing to set the maximum size of connection pool

Specified by:
setJDBCMaxConnPool in interface ConnectionManagerMBean
Parameters:
max -

getJDBCTestStatement

public java.lang.String getJDBCTestStatement()
MBean method:

Specified by:
getJDBCTestStatement in interface ConnectionManagerMBean
Returns:
test statement

setJDBCTestStatement

public void setJDBCTestStatement(java.lang.String test)
MBean method allowing to set the SQL query for test statement

Specified by:
setJDBCTestStatement in interface ConnectionManagerMBean
Parameters:
test - statement

getJDBCMaxWaitTime

public java.lang.Integer getJDBCMaxWaitTime()
MBean method:

Specified by:
getJDBCMaxWaitTime in interface ConnectionManagerMBean
Returns:
max time to wait for a connection, in seconds

setJDBCMaxWaitTime

public void setJDBCMaxWaitTime(java.lang.Integer max)
MBean method allowing to set the maximum time to wait for a connection

Specified by:
setJDBCMaxWaitTime in interface ConnectionManagerMBean
Parameters:
max -

getJDBCMaxWaiters

public java.lang.Integer getJDBCMaxWaiters()
MBean method:

Specified by:
getJDBCMaxWaiters in interface ConnectionManagerMBean
Returns:
max nb of waiters allowed

setJDBCMaxWaiters

public void setJDBCMaxWaiters(java.lang.Integer max)
MBean method allowing to set the maximum nb of concurrent waiters for a JDBC Connection.

Specified by:
setJDBCMaxWaiters in interface ConnectionManagerMBean
Parameters:
max -

getJDBCSamplingPeriod

public java.lang.Integer getJDBCSamplingPeriod()
MBean method:

Specified by:
getJDBCSamplingPeriod in interface ConnectionManagerMBean
Returns:
sampling period

setJDBCSamplingPeriod

public void setJDBCSamplingPeriod(java.lang.Integer i)
MBean method allowing to set the sampling period

Specified by:
setJDBCSamplingPeriod in interface ConnectionManagerMBean
Parameters:
i -

getDataSourceType

public java.lang.String getDataSourceType()
Mbean Method: return the type of this data source

Specified by:
getDataSourceType in interface ConnectionManagerMBean

getDataSourceDescription

public java.lang.String getDataSourceDescription()
MBean Method:

Specified by:
getDataSourceDescription in interface ConnectionManagerMBean
Returns:
the desrciption of this datasource

setDataSourceDescription

public void setDataSourceDescription(java.lang.String dsDesc)
Management Method:

Parameters:
dsDesc - the desrciption of this datasource

saveConfig

public void saveConfig()
save updated configuration

Specified by:
saveConfig in interface ConnectionManagerMBean