Class DelegatingConnectionFactory
- java.lang.Object
- org.springframework.jms.connection.DelegatingConnectionFactory
- All Implemented Interfaces:
ConnectionFactory,QueueConnectionFactory,TopicConnectionFactory,InitializingBean,SmartConnectionFactory
public class DelegatingConnectionFactory extends Object implements SmartConnectionFactory, QueueConnectionFactory, TopicConnectionFactory, InitializingBean
ConnectionFactoryimplementation that delegates all calls to a given targetConnectionFactory, adapting specificcreate(Queue/Topic)Connectioncalls 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
JMSContextcalls 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.
- Since:
- 2.0.2
- Author:
- Juergen Hoeller
- See Also:
createConnection(),setShouldStopConnections(boolean),ConnectionFactoryUtils.releaseConnection(javax.jms.Connection, javax.jms.ConnectionFactory, boolean)
Constructor Summary
Constructors Constructor Description DelegatingConnectionFactory()
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidafterPropertiesSet()Invoked by the containingBeanFactoryafter it has set all bean properties and satisfiedBeanFactoryAware,ApplicationContextAwareetc.ConnectioncreateConnection()ConnectioncreateConnection(String username, String password)JMSContextcreateContext()JMSContextcreateContext(int sessionMode)JMSContextcreateContext(String userName, String password)JMSContextcreateContext(String userName, String password, int sessionMode)QueueConnectioncreateQueueConnection()QueueConnectioncreateQueueConnection(String username, String password)TopicConnectioncreateTopicConnection()TopicConnectioncreateTopicConnection(String username, String password)ConnectionFactorygetTargetConnectionFactory()Return the target ConnectionFactory that this ConnectionFactory delegates to.voidsetShouldStopConnections(boolean shouldStopConnections)Indicate whether Connections obtained from the target factory are supposed to be stopped before closed ("true") or simply closed ("false").voidsetTargetConnectionFactory(ConnectionFactory targetConnectionFactory)Set the target ConnectionFactory that this ConnectionFactory should delegate to.booleanshouldStop(Connection con)Should we stop the Connection, obtained from this ConnectionFactory?
Constructor Detail
DelegatingConnectionFactory
public DelegatingConnectionFactory()
Method Detail
setTargetConnectionFactory
public void setTargetConnectionFactory(@Nullable ConnectionFactory targetConnectionFactory)
Set the target ConnectionFactory that this ConnectionFactory should delegate to.
getTargetConnectionFactory
@Nullable public ConnectionFactory getTargetConnectionFactory()
Return the target ConnectionFactory that this ConnectionFactory delegates to.
setShouldStopConnections
public void setShouldStopConnections(boolean shouldStopConnections)
Indicate whether Connections obtained from the target factory are supposed to be stopped before closed ("true") or simply closed ("false"). An extra stop call may be necessary for some connection pools that simply return released connections to the pool, not stopping them while they sit in the pool.Default is "false", simply closing Connections.
afterPropertiesSet
public void afterPropertiesSet()
Description copied from interface:InitializingBeanInvoked by the containingBeanFactoryafter it has set all bean properties and satisfiedBeanFactoryAware,ApplicationContextAwareetc.This method allows the bean instance to perform validation of its overall configuration and final initialization when all bean properties have been set.
- Specified by:
afterPropertiesSetin interfaceInitializingBean
createConnection
public Connection createConnection() throws JMSException
- Specified by:
createConnectionin interfaceConnectionFactory- Throws:
JMSException
createConnection
public Connection createConnection(String username, String password) throws JMSException
- Specified by:
createConnectionin interfaceConnectionFactory- Throws:
JMSException
createQueueConnection
public QueueConnection createQueueConnection() throws JMSException
- Specified by:
createQueueConnectionin interfaceQueueConnectionFactory- Throws:
JMSException
createQueueConnection
public QueueConnection createQueueConnection(String username, String password) throws JMSException
- Specified by:
createQueueConnectionin interfaceQueueConnectionFactory- Throws:
JMSException
createTopicConnection
public TopicConnection createTopicConnection() throws JMSException
- Specified by:
createTopicConnectionin interfaceTopicConnectionFactory- Throws:
JMSException
createTopicConnection
public TopicConnection createTopicConnection(String username, String password) throws JMSException
- Specified by:
createTopicConnectionin interfaceTopicConnectionFactory- Throws:
JMSException
createContext
public JMSContext createContext()
- Specified by:
createContextin interfaceConnectionFactory
createContext
public JMSContext createContext(String userName, String password)
- Specified by:
createContextin interfaceConnectionFactory
createContext
public JMSContext createContext(String userName, String password, int sessionMode)
- Specified by:
createContextin interfaceConnectionFactory
createContext
public JMSContext createContext(int sessionMode)
- Specified by:
createContextin interfaceConnectionFactory
shouldStop
public boolean shouldStop(Connection con)
Description copied from interface:SmartConnectionFactoryShould we stop the Connection, obtained from this ConnectionFactory?- Specified by:
shouldStopin interfaceSmartConnectionFactory- Parameters:
con- the Connection to check- Returns:
- whether a stop call is necessary
- See Also:
Connection.stop()