java.lang.Object | |
↳ | org.springframework.jms.connection.SingleConnectionFactory |
Known Direct Subclasses |
A JMS ConnectionFactory adapter that returns the same Connection
from all createConnection()
calls, and ignores calls to
javax.jms.Connection#close(). According to the JMS Connection
model, this is perfectly thread-safe (in contrast to e.g. JDBC). The
shared Connection can be automatically recovered in case of an Exception.
You can either pass in a specific JMS Connection directly or let this factory lazily create a Connection via a given target ConnectionFactory. This factory generally works with JMS 1.1 as well as the JMS 1.0.2 API.
Note that when using the JMS 1.0.2 API, this ConnectionFactory will switch
into queue/topic mode according to the JMS API methods used at runtime:
createQueueConnection
and createTopicConnection
will
lead to queue/topic mode, respectively; generic createConnection
calls will lead to a JMS 1.1 connection which is able to serve both modes.
Useful for testing and standalone environments in order to keep using the
same Connection for multiple JmsTemplate
calls, without having a pooling ConnectionFactory underneath. This may span
any number of transactions, even concurrently executing transactions.
Note that Spring's message listener containers support the use of a shared Connection within each listener container instance. Using SingleConnectionFactory in combination only really makes sense for sharing a single JMS Connection across multiple listener containers.
Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
logger |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Create a new SingleConnectionFactory for bean-style usage.
| |||||||||||
Create a new SingleConnectionFactory that always returns the given Connection.
| |||||||||||
Create a new SingleConnectionFactory that always returns a single
Connection that it will lazily create via the given target
ConnectionFactory.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Make sure a Connection or ConnectionFactory has been set.
| |||||||||||
Close the underlying shared connection.
| |||||||||||
Return the target ConnectionFactory which will be used to lazily
create a single Connection, if any.
| |||||||||||
Initialize the underlying shared Connection.
| |||||||||||
Exception listener callback that renews the underlying single Connection.
| |||||||||||
Reset the underlying shared Connection, to be reinitialized on next access.
| |||||||||||
Specify a JMS client ID for the single Connection created and exposed
by this ConnectionFactory.
| |||||||||||
Specify an JMS ExceptionListener implementation that should be
registered with with the single Connection created by this factory.
| |||||||||||
Specify whether the single Connection should be reset (to be subsequently renewed)
when a JMSException is reported by the underlying Connection.
| |||||||||||
Set the target ConnectionFactory which will be used to lazily
create a single Connection.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Close the given Connection.
| |||||||||||
Create a default Session for this ConnectionFactory,
adaptign to JMS 1.0.2 style queue/topic mode if necessary.
| |||||||||||
Create a JMS Connection via this template's ConnectionFactory.
| |||||||||||
Return a JMS client ID for the single Connection created and exposed
by this ConnectionFactory, if any.
| |||||||||||
Return the JMS ExceptionListener implementation that should be registered
with with the single Connection created by this factory, if any.
| |||||||||||
Template method for obtaining a (potentially cached) Session.
| |||||||||||
Wrap the given Connection with a proxy that delegates every method call to it
but suppresses close calls.
| |||||||||||
Return whether the single Connection should be renewed when
a JMSException is reported by the underlying Connection.
| |||||||||||
Prepare the given Connection before it is exposed.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
| |||||||||||
From interface
org.springframework.beans.factory.DisposableBean
| |||||||||||
From interface
org.springframework.beans.factory.InitializingBean
|
Create a new SingleConnectionFactory for bean-style usage.
Create a new SingleConnectionFactory that always returns the given Connection.
target | the single Connection |
---|
Create a new SingleConnectionFactory that always returns a single Connection that it will lazily create via the given target ConnectionFactory.
targetConnectionFactory | the target ConnectionFactory |
---|
Make sure a Connection or ConnectionFactory has been set.
JMSException |
---|
JMSException |
---|
JMSException |
---|
Close the underlying shared connection. The provider of this ConnectionFactory needs to care for proper shutdown.
As this bean implements DisposableBean, a bean factory will automatically invoke this on destruction of its cached singletons.
Return the target ConnectionFactory which will be used to lazily create a single Connection, if any.
Initialize the underlying shared Connection.
Closes and reinitializes the Connection if an underlying Connection is present already.
if thrown by JMS API methods | |
JMSException |
Exception listener callback that renews the underlying single Connection.
Reset the underlying shared Connection, to be reinitialized on next access.
Specify a JMS client ID for the single Connection created and exposed by this ConnectionFactory.
Note that client IDs need to be unique among all active Connections of the underlying JMS provider. Furthermore, a client ID can only be assigned if the original ConnectionFactory hasn't already assigned one.
setTargetConnectionFactory(ConnectionFactory)
Specify an JMS ExceptionListener implementation that should be registered with with the single Connection created by this factory.
Specify whether the single Connection should be reset (to be subsequently renewed) when a JMSException is reported by the underlying Connection.
Default is "false". Switch this to "true" to automatically trigger recovery based on your JMS provider's exception notifications.
Internally, this will lead to a special JMS ExceptionListener (this SingleConnectionFactory itself) being registered with the underlying Connection. This can also be combined with a user-specified ExceptionListener, if desired.
Set the target ConnectionFactory which will be used to lazily create a single Connection.
Close the given Connection.
con | the Connection to close |
---|
Create a default Session for this ConnectionFactory, adaptign to JMS 1.0.2 style queue/topic mode if necessary.
con | the JMS Connection to operate on |
---|---|
mode | the Session acknowledgement mode
(Session.TRANSACTED or one of the common modes) |
if thrown by the JMS API | |
JMSException |
Create a JMS Connection via this template's ConnectionFactory.
if thrown by JMS API methods | |
JMSException |
Return a JMS client ID for the single Connection created and exposed by this ConnectionFactory, if any.
Return the JMS ExceptionListener implementation that should be registered with with the single Connection created by this factory, if any.
Template method for obtaining a (potentially cached) Session.
The default implementation always returns null
.
Subclasses may override this for exposing specific Session handles,
possibly delegating to createSession(Connection, Integer)
for the creation of raw
Session objects that will then get wrapped and returned from here.
con | the JMS Connection to operate on |
---|---|
mode | the Session acknowledgement mode
(Session.TRANSACTED or one of the common modes) |
null
to indicate
creation of a raw standard Sessionif thrown by the JMS API | |
JMSException |
Wrap the given Connection with a proxy that delegates every method call to it but suppresses close calls. This is useful for allowing application code to handle a special framework Connection just like an ordinary Connection from a JMS ConnectionFactory.
target | the original Connection to wrap |
---|
Return whether the single Connection should be renewed when a JMSException is reported by the underlying Connection.
Prepare the given Connection before it is exposed.
The default implementation applies ExceptionListener and client id. Can be overridden in subclasses.
con | the Connection to prepare |
---|
if thrown by JMS API methods | |
JMSException |