|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.objectweb.easybeans.component.jdbcpool.ConnectionManager
public class ConnectionManager
DataSource implementation. Manage a pool of connections.
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 |
---|
private static final long serialVersionUID
private JLog logger
private static final long MILLI
private static final long ONE_MIN_MILLI
private static final int DEFAULT_TIMEOUT
private static final long WAITER_TIMEOUT
private static final int DEFAULT_MAX_WAITERS
private static final int DEFAULT_PSTMT
private static final int DEFAULT_SAMPLING
private static java.util.Map<java.lang.String,ConnectionManager> cmList
private javax.transaction.TransactionManager tm
private java.util.TreeSet<JManagedConnection> freeList
private java.util.LinkedList<JManagedConnection> mcList
private java.util.Map<javax.transaction.Transaction,JManagedConnection> tx2mc
private int loginTimeout
private java.io.PrintWriter log
private java.lang.String dSName
private java.lang.String dataSourceName
private java.lang.String url
private java.lang.String className
private java.lang.String userName
private java.lang.String password
private int isolationLevel
private java.lang.String isolationStr
private int waiterCount
private long waitingTime
private int busyMax
private int busyMin
private static final int NO_LIMIT
private static final long ONE_DAY
private static final int MAX_REMOVE_FREELIST
private int poolMin
private int poolMax
private long maxAge
private int maxAgeMn
private long maxOpenTime
private int maxOpenTimeMn
private long waiterTimeout
private int maxWaiters
private int samplingPeriod
private int checkLevel
private int pstmtMax
private java.lang.String testStatement
private int busyMaxRecent
private int busyMinRecent
private int currentWaiters
private int openedCount
private int connectionFailures
private int connectionLeaks
private int servedOpen
private int rejectedFull
private int rejectedTimeout
private int rejectedOther
private int waitersHigh
private int waitersHighRecent
private int totalWaiterCount
private long totalWaitingTime
private long waitingHigh
private long waitingHighRecent
Constructor Detail |
---|
public ConnectionManager()
Method Detail |
---|
public static ConnectionManager getConnectionManager(java.lang.String dsname)
dsname
- datasource name.
public java.lang.String getDSName()
public void setDSName(java.lang.String s)
s
- Jndi name for the datasourcepublic java.lang.String getDatasourceName()
public void setDatasourceName(java.lang.String dataSourceName)
dataSourceName
- the name of the datasourcepublic java.lang.String getUrl()
public void setUrl(java.lang.String url)
url
- the url for JDBC connections.public java.lang.String getClassName()
public void setClassName(java.lang.String className) throws java.lang.ClassNotFoundException
className
- the name of the JDBC driver
java.lang.ClassNotFoundException
- if driver is not foundpublic java.lang.String getUserName()
public void setUserName(java.lang.String userName)
userName
- the name of the user.public java.lang.String getPassword()
public void setPassword(java.lang.String password)
password
- the password value.public void setTransactionIsolation(java.lang.String level)
level
- the level of isolation.public java.lang.String getTransactionIsolation()
public int getPoolMin()
public void setPoolMin(int min)
min
- minimum connection pool size to be set.public int getPoolMax()
public void setPoolMax(int max)
max
- max pool size. -1 means "no limit".public int getMaxAge()
public long getMaxAgeMilli()
public void setMaxAge(int mn)
mn
- max age of connection in minutes.public int getMaxOpenTime()
public long getMaxOpenTimeMilli()
public void setMaxOpenTime(int mn)
mn
- max time of open connection in minutes.public int getMaxWaitTime()
public void setMaxWaitTime(int sec)
sec
- max time to wait for a connection, in seconds.public int getMaxWaiters()
public void setMaxWaiters(int nb)
nb
- max nb of waiterspublic int getSamplingPeriod()
public void setSamplingPeriod(int sec)
sec
- sampling period in sec.public int getCheckLevel()
public void setCheckLevel(int level)
level
- jdbc connection checking level (0, 1, or 2)public int getPstmtMax()
public void setPstmtMax(int nb)
nb
- PreparedStatement cache size.public java.lang.String getTestStatement()
public void setTestStatement(java.lang.String s)
s
- test statementpublic 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)
connchecklevel
- JDBC connection checking levelconnmaxage
- JDBC connection maximum agemaxopentime
- JDBC connection maximum open timeconnteststmt
- SQL query for test statementpstmtmax
- prepare statement pool size per managed connectionminconpool
- Min size for the connection poolmaxconpool
- Max size for the connection poolmaxwaittime
- Max time to wait for a connection (in seconds)maxwaiters
- Max nb of waiters for a connectionsamplingperiod
- sampling period in sec.public int getBusyMaxRecent()
public int getBusyMinRecent()
public int getCurrentWaiters()
public int getOpenedCount()
public int getConnectionFailures()
public int getConnectionLeaks()
public int getServedOpen()
public int getRejectedFull()
public int getRejectedTimeout()
public int getRejectedOther()
public int getRejectedOpen()
public int getWaitersHigh()
public int getWaitersHighRecent()
public int getWaiterCount()
public long getWaitingTime()
public long getWaitingHigh()
public long getWaitingHighRecent()
public int getLoginTimeout() throws java.sql.SQLException
getLoginTimeout
in interface javax.sql.DataSource
getLoginTimeout
in interface javax.sql.XADataSource
java.sql.SQLException
public void setLoginTimeout(int seconds) throws java.sql.SQLException
setLoginTimeout
in interface javax.sql.DataSource
setLoginTimeout
in interface javax.sql.XADataSource
java.sql.SQLException
public java.io.PrintWriter getLogWriter() throws java.sql.SQLException
getLogWriter
in interface javax.sql.DataSource
getLogWriter
in interface javax.sql.XADataSource
java.sql.SQLException
public void setLogWriter(java.io.PrintWriter out) throws java.sql.SQLException
setLogWriter
in interface javax.sql.DataSource
setLogWriter
in interface javax.sql.XADataSource
java.sql.SQLException
public java.sql.Connection getConnection() throws java.sql.SQLException
getConnection
in interface javax.sql.DataSource
java.sql.SQLException
public java.sql.Connection getConnection(java.lang.String username, java.lang.String password) throws java.sql.SQLException
getConnection
in interface javax.sql.DataSource
username
- - the database user on whose behalf the connection is
being madepassword
- - the user's password
java.sql.SQLException
- - if a database access error occurspublic javax.sql.XAConnection getXAConnection() throws java.sql.SQLException
getXAConnection
in interface javax.sql.XADataSource
XAConnection
object, which represents a
physical connection to a data source, that can be used in
a distributed transaction
java.sql.SQLException
- if a database access error occurspublic javax.sql.XAConnection getXAConnection(java.lang.String user, java.lang.String passwd) throws java.sql.SQLException
getXAConnection
in interface javax.sql.XADataSource
user
- - the database user on whose behalf the connection is being
madepasswd
- - the user's password
java.sql.SQLException
- - if a database access error occurspublic javax.naming.Reference getReference() throws javax.naming.NamingException
getReference
in interface javax.naming.Referenceable
javax.naming.NamingException
- If a naming exception was encountered while
retrieving the reference.public void connectionClosed(javax.sql.ConnectionEvent event)
ConnectionEventListener
that
the application has called the method close
on its
representation of a pooled connection.
connectionClosed
in interface javax.sql.ConnectionEventListener
event
- an event object describing the source of
the eventpublic void connectionErrorOccurred(javax.sql.ConnectionEvent event)
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.
connectionErrorOccurred
in interface javax.sql.ConnectionEventListener
event
- an event object describing the source of
the event and containing the SQLException
that the
driver is about to throwpublic int getCurrentOpened()
public int getCurrentBusy()
public void recomputeBusy()
public int getCurrentInTx()
public void sampling()
public void adjust()
public JManagedConnection openConnection(java.lang.String user, javax.transaction.Transaction tx) throws java.sql.SQLException
user
- user nametx
- Transaction the connection is involved
java.sql.SQLException
- Cannot open a connection because the pool's max size
is reachedpublic void freeConnections(javax.transaction.Transaction tx)
tx
- the non null transactionpublic void closeAllConnection()
private boolean closeConnection(JManagedConnection mc, int flag)
mc
- XAConnection being closedflag
- TMSUCCESS (normal close) or TMFAIL (error) or null if error.
private void freeItem(JManagedConnection item)
item
- The item to be freedprivate void destroyItem(JManagedConnection mc)
mc
- The mc to be destroyedpublic java.lang.String checkConnection(java.lang.String testStatement) throws java.sql.SQLException
testStatement
- the statement to use for test
java.sql.SQLException
- If an error occured when trying to test (not due to
the test itself, but to other preliminary or post operation).protected void setTm(javax.transaction.TransactionManager tm)
tm
- the transaction manager.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |