Top Description Fields Constructors Methods
org.springframework.jms.connection

public Class DelegatingConnectionFactory

extends Object
implements SmartConnectionFactory, QueueConnectionFactory, TopicConnectionFactory, InitializingBean
Class Inheritance
All Implemented Interfaces
org.springframework.beans.factory.InitializingBean, jakarta.jms.TopicConnectionFactory, jakarta.jms.ConnectionFactory, jakarta.jms.QueueConnectionFactory, org.springframework.jms.connection.SmartConnectionFactory
Imports
jakarta.jms.Connection, .ConnectionFactory, .JMSContext, .JMSException, .QueueConnection, .QueueConnectionFactory, .TopicConnection, .TopicConnectionFactory, org.springframework.beans.factory.InitializingBean, org.springframework.lang.Nullable, org.springframework.util.Assert

jakarta.jms.ConnectionFactory implementation that delegates all calls to a given target jakarta.jms.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.

Author
Juergen Hoeller
Since
2.0.2
See Also
createConnection(), setShouldStopConnections, ConnectionFactoryUtils#releaseConnection

Field Summary

Modifier and TypeField and Description
private boolean
private ConnectionFactory

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
afterPropertiesSet()

Implements org.springframework.beans.factory.InitializingBean.afterPropertiesSet.

Invoked by the containing BeanFactory 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.

public Connection
createConnection()

Implements jakarta.jms.ConnectionFactory.createConnection.

Creates a connection with the default user identity.

public Connection
createConnection(String
the caller's user name
username
,
String
the caller's password
password
)

Implements jakarta.jms.ConnectionFactory.createConnection.

Creates a connection with the specified user identity.

public JMSContext
createContext()

Implements jakarta.jms.ConnectionFactory.createContext.

Creates a JMSContext with the default user identity and an unspecified sessionMode.

public JMSContext
createContext(String
the caller's user name
userName
,
String
the caller's password
password
)

Implements jakarta.jms.ConnectionFactory.createContext.

Creates a JMSContext with the specified user identity and an unspecified sessionMode.

public JMSContext
createContext(String
the caller's user name
userName
,
String
the caller's password
password
,
int
indicates which of four possible session modes will be used.
  • If this method is called in a Java SE environment or in the Jakarta EE application client container, the permitted values are JMSContext.SESSION_TRANSACTED, JMSContext.CLIENT_ACKNOWLEDGE, JMSContext.AUTO_ACKNOWLEDGE and JMSContext.DUPS_OK_ACKNOWLEDGE.
  • If this method is called in the Jakarta EE web or EJB container when there is an active JTA transaction in progress then this argument is ignored.
  • If this method is called in the Jakarta EE web or EJB container when there is no active JTA transaction in progress, the permitted values are JMSContext.AUTO_ACKNOWLEDGE and JMSContext.DUPS_OK_ACKNOWLEDGE. In this case the values JMSContext.TRANSACTED and JMSContext.CLIENT_ACKNOWLEDGE are not permitted.
sessionMode
)

Implements jakarta.jms.ConnectionFactory.createContext.

Creates a JMSContext with the specified user identity and the specified session mode.

public JMSContext
createContext(int
indicates which of four possible session modes will be used.
  • If this method is called in a Java SE environment or in the Jakarta EE application client container, the permitted values are JMSContext.SESSION_TRANSACTED, JMSContext.CLIENT_ACKNOWLEDGE, JMSContext.AUTO_ACKNOWLEDGE and JMSContext.DUPS_OK_ACKNOWLEDGE.
  • If this method is called in the Jakarta EE web or EJB container when there is an active JTA transaction in progress then this argument is ignored.
  • If this method is called in the Jakarta EE web or EJB container when there is no active JTA transaction in progress, the permitted values are JMSContext.AUTO_ACKNOWLEDGE and JMSContext.DUPS_OK_ACKNOWLEDGE. In this case the values JMSContext.TRANSACTED and JMSContext.CLIENT_ACKNOWLEDGE are not permitted.
sessionMode
)

Implements jakarta.jms.ConnectionFactory.createContext.

Creates a JMSContext with the default user identity and the specified session mode.

public QueueConnection
createQueueConnection()

Implements jakarta.jms.QueueConnectionFactory.createQueueConnection.

Creates a queue connection with the default user identity.

public QueueConnection
createQueueConnection(String
the caller's user name
username
,
String
the caller's password
password
)

Implements jakarta.jms.QueueConnectionFactory.createQueueConnection.

Creates a queue connection with the specified user identity.

public TopicConnection
createTopicConnection()

Implements jakarta.jms.TopicConnectionFactory.createTopicConnection.

Creates a topic connection with the default user identity.

public TopicConnection
createTopicConnection(String
the caller's user name
username
,
String
the caller's password
password
)

Implements jakarta.jms.TopicConnectionFactory.createTopicConnection.

Creates a topic connection with the specified user identity.

public ConnectionFactory
getTargetConnectionFactory()

Return the target ConnectionFactory that this ConnectionFactory delegates to.

private ConnectionFactory
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").

public void
setTargetConnectionFactory(ConnectionFactory targetConnectionFactory)

Set the target ConnectionFactory that this ConnectionFactory should delegate to.

public boolean
shouldStop(Connection
the Connection to check
con
)

Implements org.springframework.jms.connection.SmartConnectionFactory.shouldStop.

Should we stop the Connection, obtained from this ConnectionFactory?

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

shouldStopConnectionsback to summary
private boolean shouldStopConnections
targetConnectionFactoryback to summary
private ConnectionFactory targetConnectionFactory
Annotations
@Nullable

Constructor Detail

DelegatingConnectionFactoryback to summary
public DelegatingConnectionFactory()

Method Detail

afterPropertiesSetback to summary
public void afterPropertiesSet()

Implements org.springframework.beans.factory.InitializingBean.afterPropertiesSet.

Doc from org.springframework.beans.factory.InitializingBean.afterPropertiesSet.

Invoked by the containing BeanFactory 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.

Annotations
@Override
createConnectionback to summary
public Connection createConnection() throws JMSException

Implements jakarta.jms.ConnectionFactory.createConnection.

Doc from jakarta.jms.ConnectionFactory.createConnection.

Creates a connection with the default user identity. The connection is created in stopped mode. No messages will be delivered until the Connection.start method is explicitly called.

Returns:Connection

a newly created connection

Annotations
@Override
Exceptions
JMSException:
if the Jakarta Messaging provider fails to create the connection due to some internal error.
createConnectionback to summary
public Connection createConnection(String username, String password) throws JMSException

Implements jakarta.jms.ConnectionFactory.createConnection.

Doc from jakarta.jms.ConnectionFactory.createConnection.

Creates a connection with the specified user identity. The connection is created in stopped mode. No messages will be delivered until the Connection.start method is explicitly called.

Parameters
username:String

the caller's user name

password:String

the caller's password

Returns:Connection

a newly created connection

Annotations
@Override
Exceptions
JMSException:
if the Jakarta Messaging provider fails to create the connection due to some internal error.
createContextback to summary
public JMSContext createContext()

Implements jakarta.jms.ConnectionFactory.createContext.

Doc from jakarta.jms.ConnectionFactory.createContext.

Creates a JMSContext with the default user identity and an unspecified sessionMode.

A connection and session are created for use by the new JMSContext. The connection is created in stopped mode but will be automatically started when a JMSConsumer is created.

The behaviour of the session that is created depends on whether this method is called in a Java SE environment, in the Jakarta EE application client container, or in the Jakarta EE web or EJB container. If this method is called in the Jakarta EE web or EJB container then the behaviour of the session also depends on whether or not there is an active JTA transaction in progress.

In a Java SE environment or in the Jakarta EE application client container:

  • The session will be non-transacted and received messages will be acknowledged automatically using an acknowledgement mode of JMSContext.AUTO_ACKNOWLEDGE For a definition of the meaning of this acknowledgement mode see the link below.

In a Jakarta EE web or EJB container, when there is an active JTA transaction in progress:

  • The session will participate in the JTA transaction and will be committed or rolled back when that transaction is committed or rolled back, not by calling the JMSContext's commit or rollback methods.

In the Jakarta EE web or EJB container, when there is no active JTA transaction in progress:

  • The session will be non-transacted and received messages will be acknowledged automatically using an acknowledgement mode of JMSContext.AUTO_ACKNOWLEDGE For a definition of the meaning of this acknowledgement mode see the link below.
Returns:JMSContext

a newly created JMSContext

Annotations
@Override
createContextback to summary
public JMSContext createContext(String userName, String password)

Implements jakarta.jms.ConnectionFactory.createContext.

Doc from jakarta.jms.ConnectionFactory.createContext.

Creates a JMSContext with the specified user identity and an unspecified sessionMode.

A connection and session are created for use by the new JMSContext. The connection is created in stopped mode but will be automatically started when a JMSConsumer.

The behaviour of the session that is created depends on whether this method is called in a Java SE environment, in the Jakarta EE application client container, or in the Jakarta EE web or EJB container. If this method is called in the Jakarta EE web or EJB container then the behaviour of the session also depends on whether or not there is an active JTA transaction in progress.

In a Java SE environment or in the Jakarta EE application client container:

  • The session will be non-transacted and received messages will be acknowledged automatically using an acknowledgement mode of JMSContext.AUTO_ACKNOWLEDGE For a definition of the meaning of this acknowledgement mode see the link below.

In a Jakarta EE web or EJB container, when there is an active JTA transaction in progress:

  • The session will participate in the JTA transaction and will be committed or rolled back when that transaction is committed or rolled back, not by calling the JMSContext's commit or rollback methods.

In the Jakarta EE web or EJB container, when there is no active JTA transaction in progress:

  • The session will be non-transacted and received messages will be acknowledged automatically using an acknowledgement mode of JMSContext.AUTO_ACKNOWLEDGE For a definition of the meaning of this acknowledgement mode see the link below.
Parameters
userName:String

the caller's user name

password:String

the caller's password

Returns:JMSContext

a newly created JMSContext

Annotations
@Override
createContextback to summary
public JMSContext createContext(String userName, String password, int sessionMode)

Implements jakarta.jms.ConnectionFactory.createContext.

Doc from jakarta.jms.ConnectionFactory.createContext.

Creates a JMSContext with the specified user identity and the specified session mode.

A connection and session are created for use by the new JMSContext. The JMSContext is created in stopped mode but will be automatically started when a JMSConsumer is created.

The effect of setting the sessionMode argument depends on whether this method is called in a Java SE environment, in the Jakarta EE application client container, or in the Jakarta EE web or EJB container. If this method is called in the Jakarta EE web or EJB container then the effect of setting the sessionMode argument also depends on whether or not there is an active JTA transaction in progress.

In a Java SE environment or in the Jakarta EE application client container:

  • If sessionMode is set to JMSContext.SESSION_TRANSACTED then the session will use a local transaction which may subsequently be committed or rolled back by calling the JMSContext's commit or rollback methods.
  • If sessionMode is set to any of JMSContext.CLIENT_ACKNOWLEDGE, JMSContext.AUTO_ACKNOWLEDGE or JMSContext.DUPS_OK_ACKNOWLEDGE. then the session will be non-transacted and messages received by this session will be acknowledged according to the value of sessionMode. For a definition of the meaning of these acknowledgement modes see the links below.

In a Jakarta EE web or EJB container, when there is an active JTA transaction in progress:

  • The argument sessionMode is ignored. The session will participate in the JTA transaction and will be committed or rolled back when that transaction is committed or rolled back, not by calling the JMSContext's commit or rollback methods. Since the argument is ignored, developers are recommended to use createContext(String userName, String password) instead of this method.

In the Jakarta EE web or EJB container, when there is no active JTA transaction in progress:

  • The argument acknowledgeMode must be set to either of JMSContext.AUTO_ACKNOWLEDGE or JMSContext.DUPS_OK_ACKNOWLEDGE. The session will be non-transacted and messages received by this session will be acknowledged automatically according to the value of acknowledgeMode. For a definition of the meaning of these acknowledgement modes see the links below. The values JMSContext.SESSION_TRANSACTED and JMSContext.CLIENT_ACKNOWLEDGE may not be used.
Parameters
userName:String

the caller's user name

password:String

the caller's password

sessionMode:int

indicates which of four possible session modes will be used.

  • If this method is called in a Java SE environment or in the Jakarta EE application client container, the permitted values are JMSContext.SESSION_TRANSACTED, JMSContext.CLIENT_ACKNOWLEDGE, JMSContext.AUTO_ACKNOWLEDGE and JMSContext.DUPS_OK_ACKNOWLEDGE.
  • If this method is called in the Jakarta EE web or EJB container when there is an active JTA transaction in progress then this argument is ignored.
  • If this method is called in the Jakarta EE web or EJB container when there is no active JTA transaction in progress, the permitted values are JMSContext.AUTO_ACKNOWLEDGE and JMSContext.DUPS_OK_ACKNOWLEDGE. In this case the values JMSContext.TRANSACTED and JMSContext.CLIENT_ACKNOWLEDGE are not permitted.
Returns:JMSContext

a newly created JMSContext

Annotations
@Override
createContextback to summary
public JMSContext createContext(int sessionMode)

Implements jakarta.jms.ConnectionFactory.createContext.

Doc from jakarta.jms.ConnectionFactory.createContext.

Creates a JMSContext with the default user identity and the specified session mode.

A connection and session are created for use by the new JMSContext. The JMSContext is created in stopped mode but will be automatically started when a JMSConsumer is created.

The effect of setting the sessionMode argument depends on whether this method is called in a Java SE environment, in the Jakarta EE application client container, or in the Jakarta EE web or EJB container. If this method is called in the Jakarta EE web or EJB container then the effect of setting the sessionMode argument also depends on whether or not there is an active JTA transaction in progress.

In a Java SE environment or in the Jakarta EE application client container:

  • If sessionMode is set to JMSContext.SESSION_TRANSACTED then the session will use a local transaction which may subsequently be committed or rolled back by calling the JMSContext's commit or rollback methods.
  • If sessionMode is set to any of JMSContext.CLIENT_ACKNOWLEDGE, JMSContext.AUTO_ACKNOWLEDGE or JMSContext.DUPS_OK_ACKNOWLEDGE. then the session will be non-transacted and messages received by this session will be acknowledged according to the value of sessionMode. For a definition of the meaning of these acknowledgement modes see the links below.

In a Jakarta EE web or EJB container, when there is an active JTA transaction in progress:

  • The argument sessionMode is ignored. The session will participate in the JTA transaction and will be committed or rolled back when that transaction is committed or rolled back, not by calling the JMSContext's commit or rollback methods. Since the argument is ignored, developers are recommended to use createContext() instead of this method.

In the Jakarta EE web or EJB container, when there is no active JTA transaction in progress:

  • The argument acknowledgeMode must be set to either of JMSContext.AUTO_ACKNOWLEDGE or JMSContext.DUPS_OK_ACKNOWLEDGE. The session will be non-transacted and messages received by this session will be acknowledged automatically according to the value of acknowledgeMode. For a definition of the meaning of these acknowledgement modes see the links below. The values JMSContext.SESSION_TRANSACTED and JMSContext.CLIENT_ACKNOWLEDGE may not be used.
Parameters
sessionMode:int

indicates which of four possible session modes will be used.

  • If this method is called in a Java SE environment or in the Jakarta EE application client container, the permitted values are JMSContext.SESSION_TRANSACTED, JMSContext.CLIENT_ACKNOWLEDGE, JMSContext.AUTO_ACKNOWLEDGE and JMSContext.DUPS_OK_ACKNOWLEDGE.
  • If this method is called in the Jakarta EE web or EJB container when there is an active JTA transaction in progress then this argument is ignored.
  • If this method is called in the Jakarta EE web or EJB container when there is no active JTA transaction in progress, the permitted values are JMSContext.AUTO_ACKNOWLEDGE and JMSContext.DUPS_OK_ACKNOWLEDGE. In this case the values JMSContext.TRANSACTED and JMSContext.CLIENT_ACKNOWLEDGE are not permitted.
Returns:JMSContext

a newly created JMSContext

Annotations
@Override
createQueueConnectionback to summary
public QueueConnection createQueueConnection() throws JMSException

Implements jakarta.jms.QueueConnectionFactory.createQueueConnection.

Doc from jakarta.jms.QueueConnectionFactory.createQueueConnection.

Creates a queue connection with the default user identity. The connection is created in stopped mode. No messages will be delivered until the Connection.start method is explicitly called.

Returns:QueueConnection

a newly created queue connection

Annotations
@Override
Exceptions
JMSException:
if the Jakarta Messaging provider fails to create the queue connection due to some internal error.
createQueueConnectionback to summary
public QueueConnection createQueueConnection(String username, String password) throws JMSException

Implements jakarta.jms.QueueConnectionFactory.createQueueConnection.

Doc from jakarta.jms.QueueConnectionFactory.createQueueConnection.

Creates a queue connection with the specified user identity. The connection is created in stopped mode. No messages will be delivered until the Connection.start method is explicitly called.

Parameters
username:String

the caller's user name

password:String

the caller's password

Returns:QueueConnection

a newly created queue connection

Annotations
@Override
Exceptions
JMSException:
if the Jakarta Messaging provider fails to create the queue connection due to some internal error.
createTopicConnectionback to summary
public TopicConnection createTopicConnection() throws JMSException

Implements jakarta.jms.TopicConnectionFactory.createTopicConnection.

Doc from jakarta.jms.TopicConnectionFactory.createTopicConnection.

Creates a topic connection with the default user identity. The connection is created in stopped mode. No messages will be delivered until the Connection.start method is explicitly called.

Returns:TopicConnection

a newly created topic connection

Annotations
@Override
Exceptions
JMSException:
if the Jakarta Messaging provider fails to create a topic connection due to some internal error.
createTopicConnectionback to summary
public TopicConnection createTopicConnection(String username, String password) throws JMSException

Implements jakarta.jms.TopicConnectionFactory.createTopicConnection.

Doc from jakarta.jms.TopicConnectionFactory.createTopicConnection.

Creates a topic connection with the specified user identity. The connection is created in stopped mode. No messages will be delivered until the Connection.start method is explicitly called.

Parameters
username:String

the caller's user name

password:String

the caller's password

Returns:TopicConnection

a newly created topic connection

Annotations
@Override
Exceptions
JMSException:
if the Jakarta Messaging provider fails to create a topic connection due to some internal error.
getTargetConnectionFactoryback to summary
public ConnectionFactory getTargetConnectionFactory()

Return the target ConnectionFactory that this ConnectionFactory delegates to.

Annotations
@Nullable
obtainTargetConnectionFactoryback to summary
private ConnectionFactory obtainTargetConnectionFactory()
setShouldStopConnectionsback to summary
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.

See Also
ConnectionFactoryUtils#releaseConnection
setTargetConnectionFactoryback to summary
public void setTargetConnectionFactory(ConnectionFactory targetConnectionFactory)

Set the target ConnectionFactory that this ConnectionFactory should delegate to.

shouldStopback to summary
public boolean shouldStop(Connection con)

Implements org.springframework.jms.connection.SmartConnectionFactory.shouldStop.

Doc from org.springframework.jms.connection.SmartConnectionFactory.shouldStop.

Should we stop the Connection, obtained from this ConnectionFactory?

Parameters
con:Connection

the Connection to check

Returns:boolean

whether a stop call is necessary

Annotations
@Override