public class DelegatingConnectionFactory extends Object implements SmartConnectionFactory, QueueConnectionFactory, 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).
As of Spring Framework 5, this class supports JMS 2.0 JMSContext
calls and therefore requires the JMS 2.0 API to be present at runtime.
It may nevertheless run against a JMS 1.1 driver (bound to the JMS 2.0 API)
as long as no actual JMS 2.0 calls are triggered by the application's setup.
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 the containing
BeanFactory after it has set all bean properties
and satisfied BeanFactoryAware, ApplicationContextAware etc. |
Connection |
createConnection() |
Connection |
createConnection(String username,
String password) |
JMSContext |
createContext() |
JMSContext |
createContext(int sessionMode) |
JMSContext |
createContext(String userName,
String password) |
JMSContext |
createContext(String userName,
String password,
int sessionMode) |
QueueConnection |
createQueueConnection() |
QueueConnection |
createQueueConnection(String username,
String password) |
TopicConnection |
createTopicConnection() |
TopicConnection |
createTopicConnection(String username,
String password) |
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(ConnectionFactory targetConnectionFactory)
Set the target ConnectionFactory that this ConnectionFactory should delegate to.
|
boolean |
shouldStop(Connection con)
Should we stop the Connection, obtained from this ConnectionFactory?
|
public void setTargetConnectionFactory(@Nullable ConnectionFactory targetConnectionFactory)
@Nullable public ConnectionFactory getTargetConnectionFactory()
public void setShouldStopConnections(boolean shouldStopConnections)
Default is "false", simply closing Connections.
public void afterPropertiesSet()
InitializingBeanBeanFactory after it has set all bean properties
and satisfied BeanFactoryAware, ApplicationContextAware etc.
This method allows the bean instance to perform validation of its overall configuration and final initialization when all bean properties have been set.
afterPropertiesSet in interface InitializingBeanpublic Connection createConnection() throws JMSException
createConnection in interface ConnectionFactoryJMSExceptionpublic Connection createConnection(String username, String password) throws JMSException
createConnection in interface ConnectionFactoryJMSExceptionpublic QueueConnection createQueueConnection() throws JMSException
createQueueConnection in interface QueueConnectionFactoryJMSExceptionpublic QueueConnection createQueueConnection(String username, String password) throws JMSException
createQueueConnection in interface QueueConnectionFactoryJMSExceptionpublic TopicConnection createTopicConnection() throws JMSException
createTopicConnection in interface TopicConnectionFactoryJMSExceptionpublic TopicConnection createTopicConnection(String username, String password) throws JMSException
createTopicConnection in interface TopicConnectionFactoryJMSExceptionpublic JMSContext createContext()
createContext in interface ConnectionFactorypublic JMSContext createContext(String userName, String password)
createContext in interface ConnectionFactorypublic JMSContext createContext(String userName, String password, int sessionMode)
createContext in interface ConnectionFactorypublic JMSContext createContext(int sessionMode)
createContext in interface ConnectionFactorypublic boolean shouldStop(Connection con)
SmartConnectionFactoryshouldStop in interface SmartConnectionFactorycon - the Connection to checkConnection.stop()