|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.apache.activemq.pool.PooledConnectionFactory
public class PooledConnectionFactory
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
Optionally, one may configure the pool to examine and possibly evict objects as they sit idle in the
pool. This is performed by an "idle object eviction" thread, which runs asynchronously. Caution should
be used when configuring this optional feature. Eviction runs contend with client threads for access
to objects in the pool, so if they run too frequently performance issues may result. The idle object
eviction thread may be configured using the setTimeBetweenExpirationCheckMillis method. By
default the value is -1 which means no eviction thread will be run. Set to a non-negative value to
configure the idle eviction thread to run.
| Constructor Summary | |
|---|---|
PooledConnectionFactory()
Creates new PooledConnectionFactory with a default ActiveMQConnectionFactory instance. |
|
PooledConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory connectionFactory)
Creates a new PooledConnectionFactory that will use the given ActiveMQConnectionFactory to create new ActiveMQConnection instances that will be pooled. |
|
PooledConnectionFactory(String brokerURL)
Creates a new PooledConnectionFactory that will use the given broker URI to connect to ActiveMQ. |
|
| Method Summary | |
|---|---|
void |
clear()
Clears all connections from the pool. |
javax.jms.Connection |
createConnection()
|
protected org.apache.activemq.ActiveMQConnection |
createConnection(ConnectionKey key)
|
javax.jms.Connection |
createConnection(String userName,
String password)
|
javax.jms.ConnectionFactory |
getConnectionFactory()
|
long |
getExpiryTimeout()
|
int |
getIdleTimeout()
Gets the Idle timeout value applied to new Connection's that are created by this pool. |
int |
getMaxConnections()
Returns the maximum number to pooled Connections that this factory will allow before it begins to return connections from the pool on calls to ( createConnection. |
int |
getMaximumActive()
Deprecated. use getMaximumActiveSessionPerConnection() |
int |
getMaximumActiveSessionPerConnection()
Returns the currently configured maximum number of sessions a pooled Connection will create before it either blocks or throws an exception when a new session is requested, depending on configuration. |
int |
getNumConnections()
|
org.apache.commons.pool.ObjectPoolFactory<?> |
getPoolFactory()
Deprecated. |
boolean |
isBlockIfSessionPoolIsFull()
Returns whether a pooled Connection will enter a blocked state or will throw an Exception once the maximum number of sessions has been borrowed from the the Session Pool. |
boolean |
isCreateConnectionOnStartup()
|
void |
setBlockIfSessionPoolIsFull(boolean block)
Controls the behavior of the internal session pool. |
void |
setConnectionFactory(javax.jms.ConnectionFactory connectionFactory)
Sets the ConnectionFactory used to create new pooled Connections. |
void |
setCreateConnectionOnStartup(boolean createConnectionOnStartup)
Whether to create a connection on starting this PooledConnectionFactory. |
void |
setExpiryTimeout(long expiryTimeout)
allow connections to expire, irrespective of load or idle time. |
void |
setIdleTimeout(int idleTimeout)
Sets the idle timeout value for Connection's that are created by this pool, defaults to 30 seconds. |
void |
setMaxConnections(int maxConnections)
Sets the maximum number of pooled Connections (defaults to one). |
void |
setMaximumActive(int maximumActive)
Deprecated. use setMaximumActiveSessionPerConnection(int) |
void |
setMaximumActiveSessionPerConnection(int maximumActiveSessionPerConnection)
Sets the maximum number of active sessions per connection |
void |
setPoolFactory(org.apache.commons.pool.ObjectPoolFactory<?> factory)
Deprecated. |
long |
setTimeBetweenExpirationCheckMillis()
|
void |
setTimeBetweenExpirationCheckMillis(long timeBetweenExpirationCheckMillis)
Sets the number of milliseconds to sleep between runs of the idle Connection eviction thread. |
void |
start()
|
void |
stop()
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public PooledConnectionFactory()
public PooledConnectionFactory(String brokerURL)
brokerURL - The URI to use to configure the internal ActiveMQConnectionFactory.public PooledConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory connectionFactory)
connectionFactory - The ActiveMQConnectionFactory to create new Connections for this pool.| Method Detail |
|---|
public javax.jms.ConnectionFactory getConnectionFactory()
public void setConnectionFactory(javax.jms.ConnectionFactory connectionFactory)
clear the pooled Connections.
connectionFactory - The factory to use to create pooled Connections.
public javax.jms.Connection createConnection()
throws javax.jms.JMSException
createConnection in interface javax.jms.ConnectionFactoryjavax.jms.JMSException
public javax.jms.Connection createConnection(String userName,
String password)
throws javax.jms.JMSException
createConnection in interface javax.jms.ConnectionFactoryjavax.jms.JMSExceptionpublic org.apache.commons.pool.ObjectPoolFactory<?> getPoolFactory()
protected org.apache.activemq.ActiveMQConnection createConnection(ConnectionKey key)
throws javax.jms.JMSException
javax.jms.JMSExceptionpublic void start()
start in interface org.apache.activemq.Servicepublic void stop()
stop in interface org.apache.activemq.Servicepublic void clear()
createConnection. Care should be taken when using this method as Connections that
are in use be client's will be closed.
@Deprecated public int getMaximumActive()
getMaximumActiveSessionPerConnection()
@Deprecated public void setMaximumActive(int maximumActive)
setMaximumActiveSessionPerConnection(int)
public int getMaximumActiveSessionPerConnection()
public void setMaximumActiveSessionPerConnection(int maximumActiveSessionPerConnection)
maximumActiveSessionPerConnection - The maximum number of active session per connection in the pool.public void setBlockIfSessionPoolIsFull(boolean block)
block - - if true, the call to getSession() blocks if the pool is full
until a session object is available. defaults to true.public boolean isBlockIfSessionPoolIsFull()
setBlockIfSessionPoolIsFullpublic int getMaxConnections()
createConnection.
public void setMaxConnections(int maxConnections)
createConnection will result in a new Connection being create up to the max
connections value.
maxConnections - the maxConnections to setpublic int getIdleTimeout()
public void setIdleTimeout(int idleTimeout)
idleTimeout - The maximum time a pooled Connection can sit unused before it is eligible for removal.public void setExpiryTimeout(long expiryTimeout)
expiryTimeout - non zero in millisecondspublic long getExpiryTimeout()
public boolean isCreateConnectionOnStartup()
start.public void setCreateConnectionOnStartup(boolean createConnectionOnStartup)
PooledConnectionFactory.
This can be used to warm-up the pool on startup. Notice that any kind of exception
happens during startup is logged at WARN level and ignored.
createConnectionOnStartup - true to create a connection on startuppublic void setTimeBetweenExpirationCheckMillis(long timeBetweenExpirationCheckMillis)
timeBetweenExpirationCheckMillis - The time to wait between runs of the idle Connection eviction thread.public long setTimeBetweenExpirationCheckMillis()
public int getNumConnections()
public void setPoolFactory(org.apache.commons.pool.ObjectPoolFactory<?> factory)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||