activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r399702 - in /incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/pool: ConnectionPool.java PooledConnectionFactory.java SessionPool.java
Date Thu, 04 May 2006 13:58:55 GMT
Author: jstrachan
Date: Thu May  4 06:58:43 2006
New Revision: 399702

URL: http://svn.apache.org/viewcvs?rev=399702&view=rev
Log:
patched the pooled JMS provider to make it easier to configure the size and implementation
of the underlying session pool

Modified:
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/pool/ConnectionPool.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/pool/PooledConnectionFactory.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/pool/SessionPool.java

Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/pool/ConnectionPool.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/pool/ConnectionPool.java?rev=399702&r1=399701&r2=399702&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/pool/ConnectionPool.java
(original)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/pool/ConnectionPool.java
Thu May  4 06:58:43 2006
@@ -20,6 +20,7 @@
 
 import org.apache.activemq.ActiveMQConnection;
 import org.apache.activemq.util.JMSExceptionSupport;
+import org.apache.commons.pool.ObjectPoolFactory;
 
 import javax.jms.JMSException;
 import javax.jms.Session;
@@ -37,14 +38,16 @@
     private ActiveMQConnection connection;
     private Map cache;
     private AtomicBoolean started = new AtomicBoolean(false);
+    private ObjectPoolFactory poolFactory;
 
-    public ConnectionPool(ActiveMQConnection connection) {
-        this(connection, new HashMap());
+    public ConnectionPool(ActiveMQConnection connection, ObjectPoolFactory poolFactory) {
+        this(connection, new HashMap(), poolFactory);
     }
 
-    public ConnectionPool(ActiveMQConnection connection, Map cache) {
+    public ConnectionPool(ActiveMQConnection connection, Map cache, ObjectPoolFactory poolFactory)
{
         this.connection = connection;
         this.cache = cache;
+        this.poolFactory = poolFactory;
     }
 
     public void start() throws JMSException {
@@ -61,7 +64,7 @@
         SessionKey key = new SessionKey(transacted, ackMode);
         SessionPool pool = (SessionPool) cache.get(key);
         if (pool == null) {
-            pool = new SessionPool(this, key);
+            pool = new SessionPool(this, key, poolFactory.createPool());
             cache.put(key, pool);
         }
         return pool.borrowSession();

Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/pool/PooledConnectionFactory.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/pool/PooledConnectionFactory.java?rev=399702&r1=399701&r2=399702&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/pool/PooledConnectionFactory.java
(original)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/pool/PooledConnectionFactory.java
Thu May  4 06:58:43 2006
@@ -21,6 +21,9 @@
 import org.apache.activemq.Service;
 import org.apache.activemq.util.IOExceptionSupport;
 import org.apache.activemq.util.ServiceStopper;
+import org.apache.commons.pool.ObjectPoolFactory;
+import org.apache.commons.pool.impl.GenericObjectPoolFactory;
+import org.apache.commons.pool.impl.GenericObjectPool.Config;
 
 import javax.jms.Connection;
 import javax.jms.ConnectionFactory;
@@ -36,16 +39,17 @@
  * href="http://activemq.org/Spring+Support">JmsTemplate</a>.
  * 
  * <b>NOTE</b> this implementation is only intended for use when sending
- * messages.
- * It does not deal with pooling of consumers; for that look at a library like 
- * <a href="http://jencks.org/">Jencks</a> such as in
- * <a href="http://jencks.org/Message+Driven+POJOs">this example</a>
+ * messages. It does not deal with pooling of consumers; for that look at a
+ * library like <a href="http://jencks.org/">Jencks</a> such as in <a
+ * href="http://jencks.org/Message+Driven+POJOs">this example</a>
  * 
  * @version $Revision: 1.1 $
  */
 public class PooledConnectionFactory implements ConnectionFactory, Service {
     private ActiveMQConnectionFactory connectionFactory;
     private Map cache = new HashMap();
+    private ObjectPoolFactory poolFactory;
+    private int maximumActive = 5000;
 
     public PooledConnectionFactory() {
         this(new ActiveMQConnectionFactory());
@@ -76,7 +80,7 @@
         ConnectionPool connection = (ConnectionPool) cache.get(key);
         if (connection == null) {
             ActiveMQConnection delegate = createConnection(key);
-            connection = new ConnectionPool(delegate);
+            connection = new ConnectionPool(delegate, getPoolFactory());
             cache.put(key, connection);
         }
         return new PooledConnection(connection);
@@ -115,5 +119,35 @@
             }
         }
         stopper.throwFirstException();
+    }
+
+    public ObjectPoolFactory getPoolFactory() {
+        if (poolFactory == null) {
+            poolFactory = createPoolFactory();
+        }
+        return poolFactory;
+    }
+
+    /**
+     * Sets the object pool factory used to create individual session pools for
+     * each connection
+     */
+    public void setPoolFactory(ObjectPoolFactory poolFactory) {
+        this.poolFactory = poolFactory;
+    }
+
+    public int getMaximumActive() {
+        return maximumActive;
+    }
+
+    /**
+     * Sets the maximum number of active sessions per connection
+     */
+    public void setMaximumActive(int maximumActive) {
+        this.maximumActive = maximumActive;
+    }
+
+    protected ObjectPoolFactory createPoolFactory() {
+        return new GenericObjectPoolFactory(null, maximumActive);
     }
 }

Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/pool/SessionPool.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/pool/SessionPool.java?rev=399702&r1=399701&r2=399702&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/pool/SessionPool.java
(original)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/pool/SessionPool.java
Thu May  4 06:58:43 2006
@@ -36,10 +36,6 @@
     private SessionKey key;
     private ObjectPool sessionPool;
 
-    public SessionPool(ConnectionPool connectionPool, SessionKey key) {
-        this(connectionPool, key, new GenericObjectPool());
-    }
-
     public SessionPool(ConnectionPool connectionPool, SessionKey key, ObjectPool sessionPool)
{
         this.connectionPool = connectionPool;
         this.key = key;



Mime
View raw message