polish
Project: http://git-wip-us.apache.org/repos/asf/activemq/repo Commit: http://git-wip-us.apache.org/repos/asf/activemq/commit/971d924f Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/971d924f Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/971d924f Branch: refs/heads/activemq-5.9 Commit: 971d924f940eeb847a87686f9333d151639f8004 Parents: 533e252 Author: Timothy Bish <[email protected]> Authored: Mon Nov 4 16:50:37 2013 -0500 Committer: Hadrian Zbarcea <[email protected]> Committed: Wed Mar 12 09:00:59 2014 -0400 ---------------------------------------------------------------------- .../jms/pool/PooledConnectionFactory.java | 96 ++++++++++---------- 1 file changed, 48 insertions(+), 48 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/activemq/blob/971d924f/activemq-jms-pool/src/main/java/org/apache/activemq/jms/pool/PooledConnectionFactory.java ---------------------------------------------------------------------- diff --git a/activemq-jms-pool/src/main/java/org/apache/activemq/jms/pool/PooledConnectionFactory.java b/activemq-jms-pool/src/main/java/org/apache/activemq/jms/pool/PooledConnectionFactory.java index bf49f2d..64eaad2 100644 --- a/activemq-jms-pool/src/main/java/org/apache/activemq/jms/pool/PooledConnectionFactory.java +++ b/activemq-jms-pool/src/main/java/org/apache/activemq/jms/pool/PooledConnectionFactory.java @@ -21,8 +21,8 @@ import java.util.concurrent.atomic.AtomicBoolean; import javax.jms.Connection; import javax.jms.ConnectionFactory; import javax.jms.JMSException; - import javax.jms.XAConnectionFactory; + import org.apache.commons.pool.KeyedPoolableObjectFactory; import org.apache.commons.pool.impl.GenericKeyedObjectPool; import org.slf4j.Logger; @@ -71,62 +71,61 @@ public class PooledConnectionFactory implements ConnectionFactory { private long expiryTimeout = 0l; private boolean createConnectionOnStartup = true; - public void initConnectionsPool() { if (this.connectionsPool == null) { this.connectionsPool = new GenericKeyedObjectPool<ConnectionKey, ConnectionPool>( - new KeyedPoolableObjectFactory<ConnectionKey, ConnectionPool>() { + new KeyedPoolableObjectFactory<ConnectionKey, ConnectionPool>() { - @Override - public void activateObject(ConnectionKey key, ConnectionPool connection) throws Exception { - } + @Override + public void activateObject(ConnectionKey key, ConnectionPool connection) throws Exception { + } - @Override - public void destroyObject(ConnectionKey key, ConnectionPool connection) throws Exception { - try { - if (LOG.isTraceEnabled()) { - LOG.trace("Destroying connection: {}", connection); - } - connection.close(); - } catch (Exception e) { - LOG.warn("Close connection failed for connection: " + connection + ". This exception will be ignored.",e); + @Override + public void destroyObject(ConnectionKey key, ConnectionPool connection) throws Exception { + try { + if (LOG.isTraceEnabled()) { + LOG.trace("Destroying connection: {}", connection); } + connection.close(); + } catch (Exception e) { + LOG.warn("Close connection failed for connection: " + connection + ". This exception will be ignored.",e); } + } - @Override - public ConnectionPool makeObject(ConnectionKey key) throws Exception { - Connection delegate = createConnection(key); + @Override + public ConnectionPool makeObject(ConnectionKey key) throws Exception { + Connection delegate = createConnection(key); - ConnectionPool connection = createConnectionPool(delegate); - connection.setIdleTimeout(getIdleTimeout()); - connection.setExpiryTimeout(getExpiryTimeout()); - connection.setMaximumActiveSessionPerConnection(getMaximumActiveSessionPerConnection()); - connection.setBlockIfSessionPoolIsFull(isBlockIfSessionPoolIsFull()); + ConnectionPool connection = createConnectionPool(delegate); + connection.setIdleTimeout(getIdleTimeout()); + connection.setExpiryTimeout(getExpiryTimeout()); + connection.setMaximumActiveSessionPerConnection(getMaximumActiveSessionPerConnection()); + connection.setBlockIfSessionPoolIsFull(isBlockIfSessionPoolIsFull()); - if (LOG.isTraceEnabled()) { - LOG.trace("Created new connection: {}", connection); - } - - return connection; + if (LOG.isTraceEnabled()) { + LOG.trace("Created new connection: {}", connection); } - @Override - public void passivateObject(ConnectionKey key, ConnectionPool connection) throws Exception { - } + return connection; + } - @Override - public boolean validateObject(ConnectionKey key, ConnectionPool connection) { - if (connection != null && connection.expiredCheck()) { - if (LOG.isTraceEnabled()) { - LOG.trace("Connection has expired: {} and will be destroyed", connection); - } + @Override + public void passivateObject(ConnectionKey key, ConnectionPool connection) throws Exception { + } - return false; + @Override + public boolean validateObject(ConnectionKey key, ConnectionPool connection) { + if (connection != null && connection.expiredCheck()) { + if (LOG.isTraceEnabled()) { + LOG.trace("Connection has expired: {} and will be destroyed", connection); } - return true; + return false; } - }); + + return true; + } + }); // Set max idle (not max active) since our connections always idle in the pool. this.connectionsPool.setMaxIdle(1); @@ -157,13 +156,15 @@ public class PooledConnectionFactory implements ConnectionFactory { public void setConnectionFactory(final ConnectionFactory toUse) { if (toUse instanceof XAConnectionFactory) { connectionFactory = new ConnectionFactory() { - public Connection createConnection() throws JMSException { - return ((XAConnectionFactory)toUse).createXAConnection(); - } - public Connection createConnection(String userName, String password) throws JMSException { - return ((XAConnectionFactory)toUse).createXAConnection(userName, password); - } - }; + @Override + public Connection createConnection() throws JMSException { + return ((XAConnectionFactory)toUse).createXAConnection(); + } + @Override + public Connection createConnection(String userName, String password) throws JMSException { + return ((XAConnectionFactory)toUse).createXAConnection(userName, password); + } + }; } else { this.connectionFactory = toUse; } @@ -475,5 +476,4 @@ public class PooledConnectionFactory implements ConnectionFactory { protected ConnectionPool createConnectionPool(Connection connection) { return new ConnectionPool(connection); } - }
