public class PoolManager
extends java.lang.Object
Constructor and Description |
---|
PoolManager()
Create a new PoolManager.
|
Modifier and Type | Method and Description |
---|---|
static void |
addFailoverListener(FailoverListener listener,
java.sql.Connection con)
Use this method to register a FailoverListener for the specified Connection.
|
void |
closeAll()
Close all real connections to the databases.
|
void |
closeConnection(java.sql.Connection con)
Close and remove a connection from the pool.
|
void |
dispose()
Close all Connections and free all resources of the PoolManager.
|
void |
executeFailover(javax.sql.ConnectionPoolDataSource ds,
FailoverRunnable run)
Execute a FailoverRunnable.
|
java.sql.Connection |
getConnection(javax.sql.ConnectionPoolDataSource ds)
This function returns a JDBC Connection from a pool.
|
java.sql.Connection |
getConnection(javax.sql.DataSource ds)
This function returns a JDBC Connection.
|
java.sql.Connection |
getConnection(java.lang.String dsn)
This function returns a JDBC Connection.
|
java.sql.Connection |
getConnection(javax.sql.XADataSource ds)
This function returns a JDBC Connection that comes from a pool.
|
int |
getConnectionCount()
Get the total count of Connections for all DataSources.
|
int |
getConnectionCount(java.lang.Object ds)
Get the total count of Connections for one DataSource.
|
static PoolManager |
getDefault()
Common method of getting the default PoolManager.
|
int |
getFailoverCount()
Returns the current failover count.
|
FailoverListener[] |
getFailoverListener(java.sql.Connection con)
Returns the registered FailoverListeners.
|
int |
getFailoverTimeout()
Returns the current failover timeout.
|
int |
getFreeConnectionCount()
Get the count of free Connections for all DataSources.
|
int |
getFreeConnectionCount(java.lang.Object ds)
Get the count of free Connections for one DataSource.
|
int |
getInactiveTimeout()
Returns the timeout of an unused connection in the pool before the connection was closed.
|
int |
getInitialPoolSize()
Get the number of physical connections a pool
should contain when it is created
|
int |
getLoginTimeout()
Set the maximum time in seconds that the PoolManager can wait
when the maximum number of connections for a DataSource is in use.
|
int |
getMaxConnectionCount()
Deprecated.
replace with getMaxPoolSize
|
int |
getMaxIdleTime()
Get the number of seconds that a physical connection
should remain unused in the pool before the
connection is closed. 0 (zero) indicates no limit.
|
int |
getMaxPoolSize()
Get the maximum number of physical connections that
a pool should contain. 0 (zero) indicates no
maximum size.
|
int |
getPoolTimeout()
Deprecated.
replace with getMaxIdleTime
|
int |
getUsedConnectionCount()
Get the count of used Connections for all DataSources.
|
int |
getUsedConnectionCount(java.lang.Object ds)
Get the count of used Connections for one DataSource.
|
void |
removeAllFailoverListener(java.sql.Connection con)
Removes all FailoverListener from that Connection.
|
static void |
removeFailoverListener(FailoverListener listener,
java.sql.Connection con)
Use this method to remove a registered FailoverListener for the specified Connection.
|
void |
setFailoverCount(int count)
Sets the count of how many times the driver will to try to run a
FailoverRunnable.
|
void |
setFailoverTimeout(int timeout)
Sets the maximum time in seconds the driver can wait to reconnect to the Server
after a connection break.
|
void |
setInactiveTimeout(int inactiveTimeout)
Sets the timeout that a connection can be inactive before the PoolManager
close it.
|
void |
setInitialPoolSize(int initialPoolSize)
Set the number of physical connections a pool
should contain when a new pool is created.
|
void |
setLoginTimeout(int timeout)
Set the maximum time in seconds that the PoolManager can wait
when the maximum number of connections for a DataSource is in use.
|
void |
setMaxConnectionCount(int max)
Deprecated.
replace with setMaxPoolSize
|
void |
setMaxIdleTime(int maxIdleTime)
Set the number of seconds that a physical connection
should remain unused in the pool before the
connection is closed. 0 (zero) indicates no limit.
|
void |
setMaxPoolSize(int maxPoolSize)
Set the maximum number of physical connections that
a pool should contain. 0 (zero) indicates no
maximum size.
|
void |
setPoolTimeout(int poolTimeout)
Deprecated.
replace with setMaxIdleTime
|
public PoolManager()
getDefault()
public java.sql.Connection getConnection(java.lang.String dsn) throws java.sql.SQLException
dsn
- The Data Soure Name that describes the connection in the directory.java.sql.SQLException
- if a database access error occurspublic java.sql.Connection getConnection(javax.sql.XADataSource ds) throws java.sql.SQLException
ds
- The datasoure that describes the connection.java.sql.SQLException
- if a database access error occurspublic java.sql.Connection getConnection(javax.sql.ConnectionPoolDataSource ds) throws java.sql.SQLException
ds
- The datasoure that describes the connection.java.sql.SQLException
- if a database access error occurspublic java.sql.Connection getConnection(javax.sql.DataSource ds) throws java.sql.SQLException
ds
- The datasoure that describes the connection.java.sql.SQLException
- if a database access error occurspublic void closeAll()
getConnectionCount(Object)
,
dispose()
public void dispose()
closeAll()
public void closeConnection(java.sql.Connection con) throws java.sql.SQLException
con
- the connectionjava.sql.SQLException
- if a database access error occurspublic int getConnectionCount()
getFreeConnectionCount()
,
getUsedConnectionCount()
,
getConnectionCount(Object)
public int getConnectionCount(java.lang.Object ds)
ds
- a equals DataSource that describes the connection.getUsedConnectionCount(Object)
,
getFreeConnectionCount(Object)
,
getConnectionCount()
public int getFreeConnectionCount()
getConnectionCount()
,
getUsedConnectionCount()
,
getFreeConnectionCount(Object)
public int getFreeConnectionCount(java.lang.Object ds)
ds
- a equals DataSource that describes the connection.getConnectionCount(Object)
,
getUsedConnectionCount(Object)
,
getFreeConnectionCount()
public int getUsedConnectionCount()
getConnectionCount()
,
getFreeConnectionCount()
,
getUsedConnectionCount(Object)
public int getUsedConnectionCount(java.lang.Object ds)
ds
- a equals DataSource that describes the connection.getConnectionCount(Object)
,
getFreeConnectionCount(Object)
,
getUsedConnectionCount()
public void setPoolTimeout(int poolTimeout)
poolTimeout
- timeout of the unused connection in secondsgetPoolTimeout()
public int getPoolTimeout()
setPoolTimeout(int)
,
setInactiveTimeout(int)
public void setMaxIdleTime(int maxIdleTime)
maxIdleTime
- the new valuegetMaxIdleTime()
public int getMaxIdleTime()
setMaxIdleTime(int)
public void setInactiveTimeout(int inactiveTimeout)
inactiveTimeout
- The inactive timeout in secondsgetInactiveTimeout()
,
setPoolTimeout(int)
,
getPoolTimeout()
public int getInactiveTimeout()
setPoolTimeout(int)
public void setMaxConnectionCount(int max)
max
- the maximum nuber of connetionssetLoginTimeout(int)
,
getLoginTimeout()
,
getMaxConnectionCount()
public int getMaxConnectionCount()
setLoginTimeout(int)
,
getLoginTimeout()
,
setMaxConnectionCount(int)
public void setMaxPoolSize(int maxPoolSize)
maxPoolSize
- the new valuegetMaxPoolSize()
public int getMaxPoolSize()
setMaxPoolSize(int)
public void setLoginTimeout(int timeout)
timeout
- the new valuegetLoginTimeout()
,
setMaxConnectionCount(int)
,
getMaxConnectionCount()
public int getLoginTimeout()
setLoginTimeout(int)
,
setMaxConnectionCount(int)
,
getMaxConnectionCount()
public static PoolManager getDefault()
public void setInitialPoolSize(int initialPoolSize)
initialPoolSize
- the new valuepublic int getInitialPoolSize()
public void executeFailover(javax.sql.ConnectionPoolDataSource ds, FailoverRunnable run) throws java.sql.SQLException
The driver tries to create/request a new Connection with the DataSource from the pool. This connection will be passed to your FailoverRunnable.
If an exception occurs that does not close the connection then this exception will be thrown to the calling process.
If an exception occurs that closes the connection then the driver will try to reconnect to the Server. The driver will try to get a new connection until the FailoverTimeout has expired. The driver will execute your FailoverRunnable for FailoverCount times. This can help in case the driver can reconnect but the db object is not available currently.
If you do not use a cluster then you can use the feature of the failover server. With the property "failover=true" and additional failover properties to describe the second server you can reconnect to a third server in a crash situation. If both servers are being replicated then this equals to a cluster.
ds
- a DataSource to create a connectionrun
- include your buisniss logicjava.sql.SQLException
- if a database access error occurssetFailoverCount(int)
,
setFailoverTimeout(int)
,
FailoverRunnable
public void setFailoverCount(int count)
count
- the new valueexecuteFailover(javax.sql.ConnectionPoolDataSource, com.inet.pool.FailoverRunnable)
,
FailoverRunnable
,
getFailoverCount()
public int getFailoverCount()
executeFailover(javax.sql.ConnectionPoolDataSource, com.inet.pool.FailoverRunnable)
,
FailoverRunnable
,
setFailoverCount(int)
public void setFailoverTimeout(int timeout)
timeout
- getFailoverTimeout()
,
setFailoverCount(int)
public int getFailoverTimeout()
executeFailover(javax.sql.ConnectionPoolDataSource, com.inet.pool.FailoverRunnable)
,
FailoverRunnable
,
setFailoverTimeout(int)
public static void addFailoverListener(FailoverListener listener, java.sql.Connection con) throws java.sql.SQLException
con
- the Connection for that the FailoverListener have to registered.listener
- an object from class that implements the FailoverListener to handle the FailoverEvents.java.sql.SQLException
- if a database access error occursremoveFailoverListener(FailoverListener, Connection)
,
FailoverListener
,
FailoverEvent
public static void removeFailoverListener(FailoverListener listener, java.sql.Connection con) throws java.sql.SQLException
con
- the Connection for that the FailoverListenerlistener
- an from class that implements the FailoverListener to handle the FailoverEvents.java.sql.SQLException
- if a database access error occursTAFConnection.removeFailoverListener(FailoverListener)
,
addFailoverListener(FailoverListener, Connection)
,
FailoverListener
,
FailoverEvent
public FailoverListener[] getFailoverListener(java.sql.Connection con) throws java.sql.SQLException
null
con
- the connectionjava.sql.SQLException
- if a database access error occurspublic void removeAllFailoverListener(java.sql.Connection con) throws java.sql.SQLException
con
- the connectionjava.sql.SQLException
- if a database access error occurs
copyright by i-net software