org.apache.aries.transaction.jms
Class PooledConnectionFactory

java.lang.Object
  extended by org.apache.aries.transaction.jms.PooledConnectionFactory
All Implemented Interfaces:
javax.jms.ConnectionFactory
Direct Known Subclasses:
XaPooledConnectionFactory

public class PooledConnectionFactory
extends Object
implements javax.jms.ConnectionFactory

A JMS provider which pools Connection, Session and MessageProducer instances so it can be used with tools like Camel and Spring's JmsTemplate and MessagListenerContainer. Connections, sessions and producers are returned to a pool after use so that they can be reused later without having to undergo the cost of creating them again. b>NOTE: while this implementation does allow the creation of a collection of active consumers, it does not 'pool' consumers. Pooling makes sense for connections, sessions and producers, which are expensive to create and can remain idle a minimal cost. Consumers, on the other hand, are usually just created at startup and left active, handling incoming messages as they come. When a consumer is complete, it is best to close it rather than return it to a pool for later reuse: this is because, even if a consumer is idle, ActiveMQ will keep delivering messages to the consumer's prefetch buffer, where they'll get held until the consumer is active again. If you are creating a collection of consumers (for example, for multi-threaded message consumption), you might want to consider using a lower prefetch value for each consumer (e.g. 10 or 20), to ensure that all messages don't end up going to just one of the consumers. See this FAQ entry for more detail: http://activemq.apache.org/i-do-not-receive-messages-in-my-second-consumer.html


Constructor Summary
PooledConnectionFactory()
           
 
Method Summary
 javax.jms.Connection createConnection()
           
protected  javax.jms.Connection createConnection(ConnectionKey key)
           
 javax.jms.Connection createConnection(String userName, String password)
           
protected  ConnectionPool createConnectionPool(javax.jms.Connection connection)
           
protected  org.apache.commons.pool.ObjectPoolFactory createPoolFactory()
          Creates an ObjectPoolFactory.
 javax.jms.ConnectionFactory getConnectionFactory()
           
 long getExpiryTimeout()
           
 int getIdleTimeout()
           
 int getMaxConnections()
           
 int getMaximumActive()
           
 org.apache.commons.pool.ObjectPoolFactory getPoolFactory()
           
 void setBlockIfSessionPoolIsFull(boolean block)
          Controls the behavior of the internal session pool.
 void setConnectionFactory(javax.jms.ConnectionFactory connectionFactory)
          The actual JMS ConnectionFactory that will be pooled.
 void setExpiryTimeout(long expiryTimeout)
          Allow connections to expire, irrespective of load or idle time.
 void setIdleTimeout(int idleTimeout)
          Specifies the amount of milliseconds after which an idle connection is discarded.
 void setMaxConnections(int maxConnections)
          Number of JMS connections to use.
 void setMaximumActive(int maximumActive)
          Sets the maximum number of active sessions per connection
 void setPoolFactory(org.apache.commons.pool.ObjectPoolFactory poolFactory)
          Sets the object pool factory used to create individual session pools for each connection
 void start()
           
 void stop()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PooledConnectionFactory

public PooledConnectionFactory()
Method Detail

getConnectionFactory

public javax.jms.ConnectionFactory getConnectionFactory()

setConnectionFactory

public void setConnectionFactory(javax.jms.ConnectionFactory connectionFactory)
The actual JMS ConnectionFactory that will be pooled.


createConnection

public javax.jms.Connection createConnection()
                                      throws javax.jms.JMSException
Specified by:
createConnection in interface javax.jms.ConnectionFactory
Throws:
javax.jms.JMSException

createConnection

public javax.jms.Connection createConnection(String userName,
                                             String password)
                                      throws javax.jms.JMSException
Specified by:
createConnection in interface javax.jms.ConnectionFactory
Throws:
javax.jms.JMSException

createConnectionPool

protected ConnectionPool createConnectionPool(javax.jms.Connection connection)
                                       throws javax.jms.JMSException
Throws:
javax.jms.JMSException

createConnection

protected javax.jms.Connection createConnection(ConnectionKey key)
                                         throws javax.jms.JMSException
Throws:
javax.jms.JMSException

start

public void start()

stop

public void stop()

getPoolFactory

public org.apache.commons.pool.ObjectPoolFactory getPoolFactory()

setPoolFactory

public void setPoolFactory(org.apache.commons.pool.ObjectPoolFactory poolFactory)
Sets the object pool factory used to create individual session pools for each connection


getMaximumActive

public int getMaximumActive()

setMaximumActive

public void setMaximumActive(int maximumActive)
Sets the maximum number of active sessions per connection


setBlockIfSessionPoolIsFull

public void setBlockIfSessionPoolIsFull(boolean block)
Controls the behavior of the internal session pool. By default the call to Connection.getSession() will block if the session pool is full. If the argument false is given, it will change the default behavior and instead the call to getSession() will throw a JMSException. The size of the session pool is controlled by the @see #maximumActive property.

Parameters:
block - - if true, the call to getSession() blocks if the pool is full until a session object is available. defaults to true.

getMaxConnections

public int getMaxConnections()
Returns:
the maxConnections

setMaxConnections

public void setMaxConnections(int maxConnections)
Number of JMS connections to use. The default is 1 to use a single connection to the broker. For high throughput, it may be interesting to raise this number a bit.

Parameters:
maxConnections - the maxConnections to set

createPoolFactory

protected org.apache.commons.pool.ObjectPoolFactory createPoolFactory()
Creates an ObjectPoolFactory. Its behavior is controlled by the two properties @see #maximumActive and @see #blockIfSessionPoolIsFull.

Returns:
the newly created but empty ObjectPoolFactory

getIdleTimeout

public int getIdleTimeout()

setIdleTimeout

public void setIdleTimeout(int idleTimeout)
Specifies the amount of milliseconds after which an idle connection is discarded. Defaults to 30 seconds.

Parameters:
idleTimeout - non zero in milliseconds

setExpiryTimeout

public void setExpiryTimeout(long expiryTimeout)
Allow connections to expire, irrespective of load or idle time. This is useful with failover to force a reconnect from the pool, to reestablish load balancing or use of the master post recovery.

Parameters:
expiryTimeout - non zero in milliseconds

getExpiryTimeout

public long getExpiryTimeout()


Copyright © 2009-2012 The Apache Software Foundation. All Rights Reserved.