public class DelegatingConnectionFactory extends Object implements SmartConnectionFactory, javax.jms.QueueConnectionFactory, javax.jms.TopicConnectionFactory, InitializingBean
ConnectionFactory
implementation that delegates all calls
to a given target ConnectionFactory
, adapting specific
create(Queue/Topic)Connection
calls to the target ConnectionFactory
if necessary (e.g. when running JMS 1.0.2 API based code against a generic
JMS 1.1 ConnectionFactory, such as ActiveMQ's PooledConnectionFactory).
This class allows for being subclassed, with subclasses overriding only
those methods (such as createConnection()
) that should not simply
delegate to the target ConnectionFactory.
Can also be defined as-is, wrapping a specific target ConnectionFactory, using the "shouldStopConnections" flag to indicate whether Connections obtained from the target factory are supposed to be stopped before closed. The latter may be necessary for some connection pools that simply return released connections to the pool, not stopping them while they sit in the pool.
createConnection()
,
setShouldStopConnections(boolean)
,
ConnectionFactoryUtils.releaseConnection(javax.jms.Connection, javax.jms.ConnectionFactory, boolean)
Constructor and Description |
---|
DelegatingConnectionFactory() |
Modifier and Type | Method and Description |
---|---|
void |
afterPropertiesSet()
Invoked by a BeanFactory after it has set all bean properties supplied
(and satisfied BeanFactoryAware and ApplicationContextAware).
|
javax.jms.Connection |
createConnection() |
javax.jms.Connection |
createConnection(String username,
String password) |
javax.jms.QueueConnection |
createQueueConnection() |
javax.jms.QueueConnection |
createQueueConnection(String username,
String password) |
javax.jms.TopicConnection |
createTopicConnection() |
javax.jms.TopicConnection |
createTopicConnection(String username,
String password) |
javax.jms.ConnectionFactory |
getTargetConnectionFactory()
Return the target ConnectionFactory that this ConnectionFactory delegates to.
|
void |
setShouldStopConnections(boolean shouldStopConnections)
Indicate whether Connections obtained from the target factory are supposed
to be stopped before closed ("true") or simply closed ("false").
|
void |
setTargetConnectionFactory(javax.jms.ConnectionFactory targetConnectionFactory)
Set the target ConnectionFactory that this ConnectionFactory should delegate to.
|
boolean |
shouldStop(javax.jms.Connection con)
Should we stop the Connection, obtained from this ConnectionFactory?
|
public void setTargetConnectionFactory(javax.jms.ConnectionFactory targetConnectionFactory)
public javax.jms.ConnectionFactory getTargetConnectionFactory()
public void setShouldStopConnections(boolean shouldStopConnections)
Default is "false", simply closing Connections.
public void afterPropertiesSet()
InitializingBean
This method allows the bean instance to perform initialization only possible when all bean properties have been set and to throw an exception in the event of misconfiguration.
afterPropertiesSet
in interface InitializingBean
public javax.jms.Connection createConnection() throws javax.jms.JMSException
createConnection
in interface javax.jms.ConnectionFactory
javax.jms.JMSException
public javax.jms.Connection createConnection(String username, String password) throws javax.jms.JMSException
createConnection
in interface javax.jms.ConnectionFactory
javax.jms.JMSException
public javax.jms.QueueConnection createQueueConnection() throws javax.jms.JMSException
createQueueConnection
in interface javax.jms.QueueConnectionFactory
javax.jms.JMSException
public javax.jms.QueueConnection createQueueConnection(String username, String password) throws javax.jms.JMSException
createQueueConnection
in interface javax.jms.QueueConnectionFactory
javax.jms.JMSException
public javax.jms.TopicConnection createTopicConnection() throws javax.jms.JMSException
createTopicConnection
in interface javax.jms.TopicConnectionFactory
javax.jms.JMSException
public javax.jms.TopicConnection createTopicConnection(String username, String password) throws javax.jms.JMSException
createTopicConnection
in interface javax.jms.TopicConnectionFactory
javax.jms.JMSException
public boolean shouldStop(javax.jms.Connection con)
SmartConnectionFactory
shouldStop
in interface SmartConnectionFactory
con
- the Connection to checkConnection.stop()
Copyright © 2015. All rights reserved.