[jboss-svn-commits] JBL Code SVN: r5495 - labs/jbossesb/branches/refactor/product/core/common/src/org/jboss/soa/esb/connection
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Sat Aug 5 12:14:02 EDT 2006
Author: mohit309
Date: 2006-08-05 12:13:55 -0400 (Sat, 05 Aug 2006)
New Revision: 5495
Modified:
labs/jbossesb/branches/refactor/product/core/common/src/org/jboss/soa/esb/connection/AbandonedConnectionTimerTask.java
labs/jbossesb/branches/refactor/product/core/common/src/org/jboss/soa/esb/connection/ConnectionFactory.java
labs/jbossesb/branches/refactor/product/core/common/src/org/jboss/soa/esb/connection/ConnectionPool.java
labs/jbossesb/branches/refactor/product/core/common/src/org/jboss/soa/esb/connection/ConnectionPoolFactory.java
labs/jbossesb/branches/refactor/product/core/common/src/org/jboss/soa/esb/connection/ConnectionProperties.java
labs/jbossesb/branches/refactor/product/core/common/src/org/jboss/soa/esb/connection/ConnectionWrapper.java
labs/jbossesb/branches/refactor/product/core/common/src/org/jboss/soa/esb/connection/DefaultConnectionPoolImpl.java
labs/jbossesb/branches/refactor/product/core/common/src/org/jboss/soa/esb/connection/DriverConnectionFactory.java
labs/jbossesb/branches/refactor/product/core/common/src/org/jboss/soa/esb/connection/FreeConnectionPoolResources.java
labs/jbossesb/branches/refactor/product/core/common/src/org/jboss/soa/esb/connection/PasswordDecoder.java
labs/jbossesb/branches/refactor/product/core/common/src/org/jboss/soa/esb/connection/PoolDataSource.java
Log:
Modified code to coding standards
Modified: labs/jbossesb/branches/refactor/product/core/common/src/org/jboss/soa/esb/connection/AbandonedConnectionTimerTask.java
===================================================================
--- labs/jbossesb/branches/refactor/product/core/common/src/org/jboss/soa/esb/connection/AbandonedConnectionTimerTask.java 2006-08-05 15:07:22 UTC (rev 5494)
+++ labs/jbossesb/branches/refactor/product/core/common/src/org/jboss/soa/esb/connection/AbandonedConnectionTimerTask.java 2006-08-05 16:13:55 UTC (rev 5495)
@@ -26,7 +26,7 @@
/**
* Timer task which will run at scheduled times based on the property set by the user.
* This task will remove all unused connections which have elapsed a certain period of time
- * User: MohitK
+ * @author MohitK
* Date: Jul 26, 2006
*/
public class AbandonedConnectionTimerTask extends TimerTask {
Modified: labs/jbossesb/branches/refactor/product/core/common/src/org/jboss/soa/esb/connection/ConnectionFactory.java
===================================================================
--- labs/jbossesb/branches/refactor/product/core/common/src/org/jboss/soa/esb/connection/ConnectionFactory.java 2006-08-05 15:07:22 UTC (rev 5494)
+++ labs/jbossesb/branches/refactor/product/core/common/src/org/jboss/soa/esb/connection/ConnectionFactory.java 2006-08-05 16:13:55 UTC (rev 5495)
@@ -25,8 +25,9 @@
import java.sql.SQLException;
/**
- * Factory interface for creating connections based on different sources such as DataSource, DriverConnection
- * User: MohitK
+ * Factory interface for creating connections based on different sources such as Driver, DriverManager or any
+ * third party implementation
+ * @author MohitK
* Date: Jul 18, 2006
*/
public interface ConnectionFactory {
Modified: labs/jbossesb/branches/refactor/product/core/common/src/org/jboss/soa/esb/connection/ConnectionPool.java
===================================================================
--- labs/jbossesb/branches/refactor/product/core/common/src/org/jboss/soa/esb/connection/ConnectionPool.java 2006-08-05 15:07:22 UTC (rev 5494)
+++ labs/jbossesb/branches/refactor/product/core/common/src/org/jboss/soa/esb/connection/ConnectionPool.java 2006-08-05 16:13:55 UTC (rev 5495)
@@ -21,23 +21,25 @@
*/
package org.jboss.soa.esb.connection;
-import org.jboss.soa.esb.connection.exception.ESBConnectionException;
+import org.jboss.soa.esb.connection.exception.ConnectionException;
import java.sql.Connection;
import java.sql.SQLException;
/**
- * TODO
- * User: MohitK
+ * Interface that needs to be implemented to provide pool of connections.
+ * @see DefaultConnectionPoolImpl
+ * Default implementation of Connection Pool
+ * @author MohitK
* Date: Jul 18, 2006
*/
public interface ConnectionPool {
/**
* This method is used to create the connection pool and keep it ready
* @param prop Properties for the connection pool including connection properties
- * @throws ESBConnectionException
+ * @throws ConnectionException
*/
- public void createPool(ConnectionProperties prop) throws ESBConnectionException;
+ public void createPool(ConnectionProperties prop) throws ConnectionException;
/**
* This method is called whenever a connection is needed from the pool.
Modified: labs/jbossesb/branches/refactor/product/core/common/src/org/jboss/soa/esb/connection/ConnectionPoolFactory.java
===================================================================
--- labs/jbossesb/branches/refactor/product/core/common/src/org/jboss/soa/esb/connection/ConnectionPoolFactory.java 2006-08-05 15:07:22 UTC (rev 5494)
+++ labs/jbossesb/branches/refactor/product/core/common/src/org/jboss/soa/esb/connection/ConnectionPoolFactory.java 2006-08-05 16:13:55 UTC (rev 5495)
@@ -21,35 +21,44 @@
*/
package org.jboss.soa.esb.connection;
-import org.jboss.soa.esb.connection.exception.ESBConnectionException;
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.connection.exception.ConnectionException;
/**
- * Factory class to create the connection pool.
- * User: MohitK
- * Date: Jul 19, 2006
+ * Factory class which creates a connection pool. The factory also creates a JVM Shutdown hook which is called when
+ * JVM is shutting down which indirectly calls @link ConnectionPool#releasePool
+ *
+ * @author MohitK
+ * Date: Jul 19, 2006
*/
public class ConnectionPoolFactory {
+
+ private static Logger Log = Logger.getLogger(ConnectionPoolFactory.class);
+
/**
* Factory method to create and return a connection pool based on the property set for the connection pool
* implementation. The factory also registers a shut down hook with the JVM so that the connections in the pool
* are closed and released with causing connections leaks.
+ *
* @param connProperties Properties for the connection pool
* @return Connection Pool
- * @throws ESBConnectionException
+ * @throws ConnectionException
*/
- public static ConnectionPool createPool(ConnectionProperties connProperties) throws ESBConnectionException {
+ public static ConnectionPool createPool(ConnectionProperties connProperties) throws ConnectionException {
String connectionPoolClassName = connProperties.getConnectionPoolClass();
try {
- ConnectionPool pool = (ConnectionPool)Class.forName(connectionPoolClassName).newInstance();
+ ConnectionPool pool = (ConnectionPool) Class.forName(connectionPoolClassName).newInstance();
pool.createPool(connProperties);
FreeConnectionPoolResources freeResourcesThread = new FreeConnectionPoolResources(pool);
Runtime.getRuntime().addShutdownHook(freeResourcesThread);
return pool;
- } catch (Throwable t) {
- System.err.println("ConnectionPoolFactory: Error in Connection Pool");
- System.err.println(t);
- throw new ESBConnectionException(t);
+ } catch (ConnectionException e) {
+ Log.error("ConnectionPoolFactory: Error in creating Connection Pool", e);
+ throw e;
+ } catch (Throwable t){
+ Log.error("ConnectionPoolFactory: Error in Connection Pool", t);
+ throw new ConnectionException(t);
}
}
}
Modified: labs/jbossesb/branches/refactor/product/core/common/src/org/jboss/soa/esb/connection/ConnectionProperties.java
===================================================================
--- labs/jbossesb/branches/refactor/product/core/common/src/org/jboss/soa/esb/connection/ConnectionProperties.java 2006-08-05 15:07:22 UTC (rev 5494)
+++ labs/jbossesb/branches/refactor/product/core/common/src/org/jboss/soa/esb/connection/ConnectionProperties.java 2006-08-05 16:13:55 UTC (rev 5495)
@@ -21,18 +21,23 @@
*/
package org.jboss.soa.esb.connection;
+import org.apache.log4j.Logger;
+
import java.util.Properties;
/**
- * Connection Property class which stores all connection and connection pool properties. It keeps the peroperties ready
+ * Connection Property class which stores all connection and connection pool properties. It keeps the properties ready
* so that is can be used by the pool and connection factory
- * User: MohitK
- * Date: Jul 18, 2006
+ *
+ * @author MohitK
+ * Date: Jul 18, 2006
*/
public class ConnectionProperties {
- private Properties _connectionProperties;
+ private static Logger Log = Logger.getLogger(ConnectionProperties.class);
+ private Properties m_oConnectionProperties;
+
public static final String DRIVER_CLASSNAME = "driver-class";
public static final String CONNECTION_URL = "connection-url";
public static final String USERNAME = "user-name";
@@ -47,18 +52,18 @@
public static final String ABANDONED_CONNECTION_TIMEOUT = "abandoned-connection-timeout";
public static final String ABANDONED_CONNECTION_CHECK_INTERVAL = "abandoned-connection-time-interval";
- private boolean _autoCommit;
- private Integer _isolationLvl;
- private int _minPoolSize;
- private int _maxPoolSize;
- private long _connBlockTime;
- private String _connectionPoolClass;
- private String _user;
- private String _password;
- private String _connectionUrl;
- private long _abandonedConnectionTimeout;
- private long _abandonedConnectionCheckInterval;
- private String _driverClassName;
+ private boolean m_bAutoCommit;
+ private Integer m_iIsolationLvl;
+ private int m_iMinPoolSize;
+ private int m_iMaxPoolSize;
+ private long m_lConnBlockTime;
+ private String m_sConnectionPoolClass;
+ private String m_sUser;
+ private String m_sPassword;
+ private String m_sConnectionUrl;
+ private long m_lAbandonedConnectionTimeout;
+ private long m_lAbandonedConnectionCheckInterval;
+ private String m_sDriverClassName;
public static final String DEFAULT_MIN_POOL_SIZE = "5";
@@ -69,7 +74,7 @@
public static final String DEFAULT_ABANDONED_CONNECTION_CHECK_INTERVAL = "30000";
public ConnectionProperties(Properties connectionProperties) {
- this._connectionProperties = connectionProperties;
+ this.m_oConnectionProperties = connectionProperties;
setDriverClassName();
setConnectionUrl();
setUser();
@@ -85,164 +90,162 @@
}
private void setDriverClassName() {
- _driverClassName = _connectionProperties.getProperty(DRIVER_CLASSNAME);
- if (_driverClassName == null) {
- _driverClassName = System.getProperty(DRIVER_CLASSNAME);
+ m_sDriverClassName = m_oConnectionProperties.getProperty(DRIVER_CLASSNAME);
+ if (m_sDriverClassName == null) {
+ m_sDriverClassName = System.getProperty(DRIVER_CLASSNAME);
}
}
protected String getDriverClassName() {
- return _driverClassName;
+ return m_sDriverClassName;
}
protected String getConnectionUrl() {
- return _connectionUrl;
+ return m_sConnectionUrl;
}
private void setConnectionUrl() {
- _connectionUrl = _connectionProperties.getProperty(CONNECTION_URL);
- if (_connectionUrl == null) {
- _connectionUrl = System.getProperty(CONNECTION_URL);
+ m_sConnectionUrl = m_oConnectionProperties.getProperty(CONNECTION_URL);
+ if (m_sConnectionUrl == null) {
+ m_sConnectionUrl = System.getProperty(CONNECTION_URL);
}
}
protected boolean getAutoCommit() {
- return _autoCommit;
+ return m_bAutoCommit;
}
protected Integer getIsolationLevel() {
- return _isolationLvl;
+ return m_iIsolationLvl;
}
private void setIsolationLevel() {
- String isolation = (String) _connectionProperties.get(ISOLATION_LEVEL);
+ String isolation = (String) m_oConnectionProperties.get(ISOLATION_LEVEL);
if (isolation == null) {
isolation = System.getProperty(ISOLATION_LEVEL);
}
- this._isolationLvl = (isolation != null) ? new Integer(isolation) : null;
+ this.m_iIsolationLvl = (isolation != null) ? new Integer(isolation) : null;
}
protected int getMinPoolSize() {
- return _minPoolSize;
+ return m_iMinPoolSize;
}
protected int getMaxPoolSize() {
- return _maxPoolSize;
+ return m_iMaxPoolSize;
}
private void setMinPoolSize() {
- String strPoolSize = _connectionProperties.getProperty(MIN_POOL_SIZE);
+ String strPoolSize = m_oConnectionProperties.getProperty(MIN_POOL_SIZE);
if (strPoolSize == null) {
strPoolSize = System.getProperty(MIN_POOL_SIZE, DEFAULT_MIN_POOL_SIZE);
- this._minPoolSize = Integer.parseInt(strPoolSize);
+ this.m_iMinPoolSize = Integer.parseInt(strPoolSize);
}
}
private void setMaxPoolSize() {
- String strPoolSize = (String) _connectionProperties.get(MAX_POOL_SIZE);
+ String strPoolSize = (String) m_oConnectionProperties.get(MAX_POOL_SIZE);
if (strPoolSize == null) {
strPoolSize = System.getProperty(MAX_POOL_SIZE, DEFAULT_MAX_POOL_SIZE);
- this._maxPoolSize = Integer.parseInt(strPoolSize);
+ this.m_iMaxPoolSize = Integer.parseInt(strPoolSize);
}
}
private void setBlockingConnectionTime() {
- String strBlockTimeMillis = (String) _connectionProperties.get(BLOCKING_CONNECTION_TIME);
+ String strBlockTimeMillis = (String) m_oConnectionProperties.get(BLOCKING_CONNECTION_TIME);
if (strBlockTimeMillis == null) {
strBlockTimeMillis = System.getProperty(BLOCKING_CONNECTION_TIME, DEFAULT_CONN_BLOCK_TIME_MILLIS);
- this._connBlockTime = Integer.parseInt(strBlockTimeMillis);
+ this.m_lConnBlockTime = Integer.parseInt(strBlockTimeMillis);
}
}
protected long getConnectionBlockTimeInMillis() {
- return _connBlockTime;
+ return m_lConnBlockTime;
}
private void setAutoCommit() {
- String autoCommit = (String) _connectionProperties.get(AUTO_COMMIT);
+ String autoCommit = (String) m_oConnectionProperties.get(AUTO_COMMIT);
if (autoCommit == null || autoCommit.equals("false")) {
- _autoCommit = Boolean.FALSE;
+ m_bAutoCommit = Boolean.FALSE;
} else {
- _autoCommit = Boolean.TRUE;
+ m_bAutoCommit = Boolean.TRUE;
}
}
private void setConnectionPoolClass() {
- _connectionPoolClass = _connectionProperties.getProperty(CONNECTION_POOL_CLASS);
- if (_connectionPoolClass == null) {
- _connectionPoolClass = System.getProperty(CONNECTION_POOL_CLASS, DEFAULT_CONNECTION_POOL_CLASS);
+ m_sConnectionPoolClass = m_oConnectionProperties.getProperty(CONNECTION_POOL_CLASS);
+ if (m_sConnectionPoolClass == null) {
+ m_sConnectionPoolClass = System.getProperty(CONNECTION_POOL_CLASS, DEFAULT_CONNECTION_POOL_CLASS);
}
}
protected String getUser() {
- return _user;
+ return m_sUser;
}
public void setUser() {
- this._user = _connectionProperties.getProperty(USERNAME);
- if (_user == null) {
- _user = System.getProperty(USERNAME);
+ this.m_sUser = m_oConnectionProperties.getProperty(USERNAME);
+ if (m_sUser == null) {
+ m_sUser = System.getProperty(USERNAME);
}
}
protected String getPassword() {
- return _password;
+ return m_sPassword;
}
protected void setPassword() {
- this._password = _connectionProperties.getProperty(PASSWORD);
- if (_password == null) {
- _password = System.getProperty(PASSWORD);
+ this.m_sPassword = m_oConnectionProperties.getProperty(PASSWORD);
+ if (m_sPassword == null) {
+ m_sPassword = System.getProperty(PASSWORD);
}
- String strPasswordDecoder = _connectionProperties.getProperty(PASSWORD_DECODER);
+ String strPasswordDecoder = m_oConnectionProperties.getProperty(PASSWORD_DECODER);
if (strPasswordDecoder == null) {
strPasswordDecoder = System.getProperty(PASSWORD_DECODER);
}
if (strPasswordDecoder != null) {
try {
PasswordDecoder decoder = (PasswordDecoder) Class.forName(strPasswordDecoder).newInstance();
- this._password = decoder.decode(_password);
+ this.m_sPassword = decoder.decode(m_sPassword);
} catch (InstantiationException e) {
- System.err.println("Error in creating instance of Password Decoder Class:-" + strPasswordDecoder);
- System.err.println(e);
+ Log.error("Error in creating instance of Password Decoder Class:-" + strPasswordDecoder,e);
} catch (IllegalAccessException e) {
- System.err.println("Error in creating instance of Password Decoder Class:-" + strPasswordDecoder);
- System.err.println(e);
+ Log.error("Error in creating instance of Password Decoder Class:-" + strPasswordDecoder,e);
} catch (ClassNotFoundException e) {
- System.err.println("Password Decoder Class:-" + strPasswordDecoder + " not found in Classpath");
- System.err.println("Please check the property:-" + PASSWORD_DECODER);
- System.err.println(e);
+ Log.error("Password Decoder Class:-" + strPasswordDecoder + " not found in Classpath");
+ Log.error("Please check the property:-" + PASSWORD_DECODER);
+ Log.error(e);
}
}
}
protected String getConnectionPoolClass() {
- return _connectionPoolClass;
+ return m_sConnectionPoolClass;
}
private void setAbandonedConnectionTimeOut() {
- String strAbandonedConnectionTimeout = _connectionProperties.getProperty(ABANDONED_CONNECTION_TIMEOUT);
+ String strAbandonedConnectionTimeout = m_oConnectionProperties.getProperty(ABANDONED_CONNECTION_TIMEOUT);
if (strAbandonedConnectionTimeout == null) {
strAbandonedConnectionTimeout = System.getProperty(ABANDONED_CONNECTION_TIMEOUT, DEFAULT_ABANDONED_CONNECTION_TIMEOUT);
}
- this._abandonedConnectionTimeout = Long.parseLong(strAbandonedConnectionTimeout);
+ this.m_lAbandonedConnectionTimeout = Long.parseLong(strAbandonedConnectionTimeout);
}
private void setAbandonedConnectionCheckInterval() {
- String strAbandonedConnectionCheckInterval = _connectionProperties.getProperty(ABANDONED_CONNECTION_CHECK_INTERVAL);
+ String strAbandonedConnectionCheckInterval = m_oConnectionProperties.getProperty(ABANDONED_CONNECTION_CHECK_INTERVAL);
if (strAbandonedConnectionCheckInterval == null || strAbandonedConnectionCheckInterval.trim().length() == 0) {
strAbandonedConnectionCheckInterval = System.getProperty(ABANDONED_CONNECTION_CHECK_INTERVAL, DEFAULT_ABANDONED_CONNECTION_CHECK_INTERVAL);
}
- this._abandonedConnectionCheckInterval = Long.parseLong(strAbandonedConnectionCheckInterval);
+ this.m_lAbandonedConnectionCheckInterval = Long.parseLong(strAbandonedConnectionCheckInterval);
}
- protected long getAbandonedConnectionTimeOut(){
- return this._abandonedConnectionTimeout;
+ protected long getAbandonedConnectionTimeOut() {
+ return this.m_lAbandonedConnectionTimeout;
}
- protected long getAbandonedConnectionCheckInterval(){
- return this._abandonedConnectionCheckInterval;
+ protected long getAbandonedConnectionCheckInterval() {
+ return this.m_lAbandonedConnectionCheckInterval;
}
}
Modified: labs/jbossesb/branches/refactor/product/core/common/src/org/jboss/soa/esb/connection/ConnectionWrapper.java
===================================================================
--- labs/jbossesb/branches/refactor/product/core/common/src/org/jboss/soa/esb/connection/ConnectionWrapper.java 2006-08-05 15:07:22 UTC (rev 5494)
+++ labs/jbossesb/branches/refactor/product/core/common/src/org/jboss/soa/esb/connection/ConnectionWrapper.java 2006-08-05 16:13:55 UTC (rev 5495)
@@ -26,7 +26,7 @@
/**
* Wrapper class which encapsulates @link Connection
- * User: MohitK
+ * @author MohitK
* Date: Jul 18, 2006
*/
public class ConnectionWrapper implements Connection {
Modified: labs/jbossesb/branches/refactor/product/core/common/src/org/jboss/soa/esb/connection/DefaultConnectionPoolImpl.java
===================================================================
--- labs/jbossesb/branches/refactor/product/core/common/src/org/jboss/soa/esb/connection/DefaultConnectionPoolImpl.java 2006-08-05 15:07:22 UTC (rev 5494)
+++ labs/jbossesb/branches/refactor/product/core/common/src/org/jboss/soa/esb/connection/DefaultConnectionPoolImpl.java 2006-08-05 16:13:55 UTC (rev 5495)
@@ -21,7 +21,8 @@
*/
package org.jboss.soa.esb.connection;
-import org.jboss.soa.esb.connection.exception.ESBConnectionException;
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.connection.exception.ConnectionException;
import java.sql.Connection;
import java.sql.Driver;
@@ -34,23 +35,25 @@
import java.util.concurrent.ConcurrentHashMap;
/**
- * Default connection pool implementation class when there is none specified by the user in @link ConnectionProperties
- * User: MohitK
- * Date: Jul 18, 2006
+ * Default connection pool implementation class when none is specified by the user in @link ConnectionProperties
+ *
+ * @author MohitK
+ * Date: Jul 18, 2006
*/
public class DefaultConnectionPoolImpl implements ConnectionPool {
+ private static Logger Log = Logger.getLogger(DefaultConnectionPoolImpl.class);
+
private final Stack<ConnectionWrapper> m_oConnectionStack = new Stack<ConnectionWrapper>();
private final ConcurrentHashMap<String, ConnectionWrapper> m_oUsedConnectionMap = new ConcurrentHashMap<String, ConnectionWrapper>();
private int m_iConnCountInPool;
private ConnectionProperties m_oConnProperties;
- private ConnectionFactory _connectionFactory;
+ private ConnectionFactory m_oConnectionFactory;
/**
- * @see org.jboss.soa.esb.connection.ConnectionPool#createPool(ConnectionProperties)
- *
+ * @see ConnectionPool#createPool(ConnectionProperties)
*/
- public void createPool(ConnectionProperties prop) throws ESBConnectionException {
+ public void createPool(ConnectionProperties prop) throws ConnectionException {
this.m_oConnProperties = prop;
try {
initPool();
@@ -58,21 +61,22 @@
Timer abandonedTimer = new Timer(":AbandonedConnectionPoolScheduler:@" + this.toString(), true);
abandonedTimer.schedule(abandonedConnTask, prop.getAbandonedConnectionCheckInterval(), prop.getAbandonedConnectionCheckInterval());
} catch (SQLException e) {
- throw new ESBConnectionException("DefaultConnectionPoolImpl: Error in creating Connection Pool", e);
+ Log.error("DefaultConnectionPoolImpl: Error in creating Connection Pool",e);
+ throw new ConnectionException("DefaultConnectionPoolImpl: Error in creating Connection Pool\n Reason:-" + e.getMessage(), e);
}
}
private void initPool() throws SQLException {
- if (_connectionFactory == null) {
+ if (m_oConnectionFactory == null) {
Properties properties = new Properties();
properties.put("user", m_oConnProperties.getUser());
properties.put("password", m_oConnProperties.getPassword());
- _connectionFactory = new DriverConnectionFactory(getDriver(m_oConnProperties.getDriverClassName()), m_oConnProperties.getConnectionUrl(), properties);
+ m_oConnectionFactory = new DriverConnectionFactory(getDriver(m_oConnProperties.getDriverClassName()), m_oConnProperties.getConnectionUrl(), properties);
}
while (m_iConnCountInPool < m_oConnProperties.getMinPoolSize()) {
synchronized (m_oConnectionStack) {
- m_oConnectionStack.add(new ConnectionWrapper(_connectionFactory.createConnection(), this));
+ m_oConnectionStack.add(new ConnectionWrapper(m_oConnectionFactory.createConnection(), this));
m_iConnCountInPool++;
}
}
@@ -83,8 +87,7 @@
try {
Class.forName(driverClassName);
} catch (Throwable e) {
- System.err.println("DefaultConnectionPoolImpl: Error in loading class " + driverClassName + " to create connection pool");
- System.err.println(e);
+ Log.error("DefaultConnectionPoolImpl: Error in loading class " + driverClassName + " to create connection pool", e);
throw new SQLException("DefaultConnectionPoolImpl: Error in loading class " + driverClassName + " to create connection pool");
}
return DriverManager.getDriver(m_oConnProperties.getConnectionUrl());
@@ -93,8 +96,7 @@
}
/**
- * @see org.jboss.soa.esb.connection.ConnectionPool#getConnection()
- *
+ * @see ConnectionPool#getConnection()
*/
public synchronized Connection getConnection() throws SQLException {
ConnectionWrapper newPoolConnection;
@@ -102,7 +104,7 @@
newPoolConnection = m_oConnectionStack.pop();
m_oUsedConnectionMap.put(newPoolConnection.getName(), newPoolConnection);
} else if (m_iConnCountInPool < m_oConnProperties.getMaxPoolSize()) {
- newPoolConnection = new ConnectionWrapper(_connectionFactory.createConnection(), this);
+ newPoolConnection = new ConnectionWrapper(m_oConnectionFactory.createConnection(), this);
m_oUsedConnectionMap.put(newPoolConnection.getName(), newPoolConnection);
m_iConnCountInPool++;
} else {
@@ -160,8 +162,7 @@
m_oUsedConnectionMap.remove(name);
}
} catch (SQLException e) {
- System.err.println("DefaultConnectionPoolImpl: Error in closing physical Connection");
- System.err.println(e);
+ Log.error("DefaultConnectionPoolImpl: Error in closing physical Connection", e);
}
}
@@ -172,7 +173,6 @@
/**
* This method will release all abandoned connections from the pool.
- *
*/
protected synchronized void releaseAbandonedConnections() {
@@ -183,7 +183,7 @@
long currentTime = System.currentTimeMillis();
if ((currentTime - activedTime) > m_oConnProperties.getAbandonedConnectionTimeOut()) {
try {
- System.out.println("Removing abandoned Connection:-" + connectionWrapper);
+ Log.info("Removing abandoned Connection:-" + connectionWrapper);
Connection actualConnection = connectionWrapper.getActualConnection();
m_oUsedConnectionMap.remove(connectionWrapper.getName());
connectionWrapper.setOriginalConnection(null);
@@ -193,8 +193,7 @@
m_oConnectionStack.push(connectionWrapper);
}
} catch (SQLException e) {
- System.err.println("Error in releasing abandoned connection from Pool");
- e.printStackTrace(System.err);
+ Log.error("Error in releasing abandoned connection from Pool", e);
}
}
}
Modified: labs/jbossesb/branches/refactor/product/core/common/src/org/jboss/soa/esb/connection/DriverConnectionFactory.java
===================================================================
--- labs/jbossesb/branches/refactor/product/core/common/src/org/jboss/soa/esb/connection/DriverConnectionFactory.java 2006-08-05 15:07:22 UTC (rev 5494)
+++ labs/jbossesb/branches/refactor/product/core/common/src/org/jboss/soa/esb/connection/DriverConnectionFactory.java 2006-08-05 16:13:55 UTC (rev 5495)
@@ -22,13 +22,13 @@
package org.jboss.soa.esb.connection;
import java.sql.Connection;
+import java.sql.Driver;
import java.sql.SQLException;
-import java.sql.Driver;
import java.util.Properties;
/**
* Driver implementation of Connection Factory
- * User: MohitK
+ * @author MohitK
* Date: Jul 18, 2006
*/
public class DriverConnectionFactory implements ConnectionFactory{
Modified: labs/jbossesb/branches/refactor/product/core/common/src/org/jboss/soa/esb/connection/FreeConnectionPoolResources.java
===================================================================
--- labs/jbossesb/branches/refactor/product/core/common/src/org/jboss/soa/esb/connection/FreeConnectionPoolResources.java 2006-08-05 15:07:22 UTC (rev 5494)
+++ labs/jbossesb/branches/refactor/product/core/common/src/org/jboss/soa/esb/connection/FreeConnectionPoolResources.java 2006-08-05 16:13:55 UTC (rev 5495)
@@ -21,14 +21,20 @@
*/
package org.jboss.soa.esb.connection;
+import org.apache.log4j.Logger;
+
/**
- * Shutdown Hook into the JVM. The class will be invoked by the JVM when the JVM is shutting down.
+ * Shutdown Hook into the JVM. The class will be invoked by the JVM when JVM is shutting down.
* Used to free connection resources and destroy the connection pool.
- * User: MohitK
+ * This class is will guarantee closing of all connections rather than depending on finalize method.
+ *
+ * @author MohitK
* Date: Jul 22, 2006
*/
public class FreeConnectionPoolResources extends Thread {
+ private static Logger Log = Logger.getLogger(FreeConnectionPoolResources.class);
+
ConnectionPool pool;
public FreeConnectionPoolResources(ConnectionPool pool) {
@@ -39,7 +45,7 @@
try {
pool.releasePool();
} catch (Exception e) {
- System.err.println("Error in freeing resources");
+ Log.error("Error in freeing resources");
}
}
Modified: labs/jbossesb/branches/refactor/product/core/common/src/org/jboss/soa/esb/connection/PasswordDecoder.java
===================================================================
--- labs/jbossesb/branches/refactor/product/core/common/src/org/jboss/soa/esb/connection/PasswordDecoder.java 2006-08-05 15:07:22 UTC (rev 5494)
+++ labs/jbossesb/branches/refactor/product/core/common/src/org/jboss/soa/esb/connection/PasswordDecoder.java 2006-08-05 16:13:55 UTC (rev 5495)
@@ -24,7 +24,7 @@
/**
* Interface to be implemented by classes when they need to return the DB password for the connection by using their own
* algorithm. Called by the connection pool
- * User: MohitK
+ * @author MohitK
* Date: Jul 21, 2006
*/
public interface PasswordDecoder {
Modified: labs/jbossesb/branches/refactor/product/core/common/src/org/jboss/soa/esb/connection/PoolDataSource.java
===================================================================
--- labs/jbossesb/branches/refactor/product/core/common/src/org/jboss/soa/esb/connection/PoolDataSource.java 2006-08-05 15:07:22 UTC (rev 5494)
+++ labs/jbossesb/branches/refactor/product/core/common/src/org/jboss/soa/esb/connection/PoolDataSource.java 2006-08-05 16:13:55 UTC (rev 5495)
@@ -21,7 +21,8 @@
*/
package org.jboss.soa.esb.connection;
-import org.jboss.soa.esb.connection.exception.ESBConnectionException;
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.connection.exception.ConnectionException;
import javax.sql.DataSource;
import java.io.PrintWriter;
@@ -31,39 +32,41 @@
/**
* Implementation if Datasource for getting connections from pool.
- * User: MohitK
+ * @author MohitK
* Date: Jul 19, 2006
*/
public class PoolDataSource implements DataSource {
- private ConnectionPool _pool;
- private PrintWriter _logWriter = new PrintWriter(System.out);
- private int _loginTimeOut;
- private final Properties _connProps = new Properties();
- ConnectionProperties _connectionProperties;
+ private static Logger Log = Logger.getLogger(PoolDataSource.class);
+ private ConnectionPool m_oPool;
+ private PrintWriter m_oLogWriter = new PrintWriter(System.out);
+ private int m_iLoginTimeOut;
+ private final Properties m_oConnProps = new Properties();
+ ConnectionProperties m_oConnectionProperties;
+
private synchronized ConnectionPool createConnectionPool() throws SQLException {
- if (_pool == null) {
+ if (m_oPool == null) {
try {
- if (_connProps != null) {
- _connectionProperties = new ConnectionProperties(_connProps);
- _pool = ConnectionPoolFactory.createPool(_connectionProperties);
+ if (m_oConnProps != null) {
+ m_oConnectionProperties = new ConnectionProperties(m_oConnProps);
+ m_oPool = ConnectionPoolFactory.createPool(m_oConnectionProperties);
}
- } catch (ESBConnectionException e) {
- _logWriter.println("PoolDataSource: Error in creating Connection Pool");
- throw new SQLException("Error in Connection Pool Creation");
+ } catch (ConnectionException e) {
+ Log.error("PoolDataSource: Error in creating Connection Pool",e);
+ throw new SQLException(e.getMessage());
}
}
- return _pool;
+ return m_oPool;
}
public Properties getConnectionProperties() {
- return _connProps;
+ return m_oConnProps;
}
public void setConnectionProperties(Properties _connProperties) {
- _connProps.putAll(_connProperties);
+ m_oConnProps.putAll(_connProperties);
}
/**
@@ -77,9 +80,9 @@
* @see javax.sql.DataSource#getConnection(String, String)
*/
public Connection getConnection(String username, String password) throws SQLException {
- synchronized(_connProps){
- _connProps.setProperty(ConnectionProperties.USERNAME, username);
- _connProps.setProperty(ConnectionProperties.PASSWORD, password);
+ synchronized(m_oConnProps){
+ m_oConnProps.setProperty(ConnectionProperties.USERNAME, username);
+ m_oConnProps.setProperty(ConnectionProperties.PASSWORD, password);
}
return createConnectionPool().getConnection();
}
@@ -94,20 +97,20 @@
* @see javax.sql.DataSource#setLogWriter(java.io.PrintWriter)
*/
public void setLogWriter(PrintWriter out) throws SQLException {
- this._logWriter = out;
+ this.m_oLogWriter = out;
}
/**
* @see javax.sql.DataSource#setLoginTimeout(int)
*/
public void setLoginTimeout(int seconds) throws SQLException {
- this._loginTimeOut = seconds;
+ this.m_iLoginTimeOut = seconds;
}
/**
* @see javax.sql.DataSource#getLoginTimeout()
*/
public int getLoginTimeout() throws SQLException {
- return _loginTimeOut;
+ return m_iLoginTimeOut;
}
}
More information about the jboss-svn-commits
mailing list