| java.lang.Object org.springframework.jms.connection.SingleConnectionFactory
All known Subclasses: org.springframework.jms.connection.SingleConnectionFactory102,
SingleConnectionFactory | public class SingleConnectionFactory implements ConnectionFactory,QueueConnectionFactory,TopicConnectionFactory,ExceptionListener,InitializingBean,DisposableBean(Code) | | A JMS ConnectionFactory adapter that returns the same Connection on all
createConnection calls, and ignores calls to
Connection.close() . According to the JMS Connection model,
this is even thread-safe.
Useful for testing and standalone environments, to keep using the same
Connection for multiple JmsTemplate calls, without having a pooling
ConnectionFactory, also spanning any number of transactions.
You can either pass in a JMS Connection directly, or let this
factory lazily create a Connection via a given target ConnectionFactory.
In the latter case, this factory just works with JMS 1.1; use
SingleConnectionFactory102 for JMS 1.0.2.
author: Mark Pollack author: Juergen Hoeller since: 1.1 See Also: SingleConnectionFactory.createConnection() See Also: javax.jms.Connection.close See Also: SingleConnectionFactory102 See Also: org.springframework.jms.core.JmsTemplate |
Field Summary | |
final protected Log | logger |
Constructor Summary | |
public | SingleConnectionFactory() Create a new SingleConnectionFactory for bean-style usage. | public | SingleConnectionFactory(Connection target) Create a new SingleConnectionFactory that always returns the
given Connection. | public | SingleConnectionFactory(ConnectionFactory targetConnectionFactory) Create a new SingleConnectionFactory that always returns a single
Connection that it will lazily create via the given target
ConnectionFactory. |
Method Summary | |
public void | afterPropertiesSet() Make sure a Connection or ConnectionFactory has been set. | protected void | closeConnection(Connection con) Close the given Connection. | public Connection | createConnection() | public Connection | createConnection(String username, String password) | public QueueConnection | createQueueConnection() | public QueueConnection | createQueueConnection(String username, String password) | public TopicConnection | createTopicConnection() | public TopicConnection | createTopicConnection(String username, String password) | public void | destroy() Close the underlying shared connection. | protected Connection | doCreateConnection() Create a JMS Connection via this template's ConnectionFactory. | protected String | getClientId() Return a JMS client ID for the single Connection created and exposed
by this ConnectionFactory, if any. | protected ExceptionListener | getExceptionListener() Return the JMS ExceptionListener implementation that should be registered
with with the single Connection created by this factory, if any. | protected Connection | getSharedConnectionProxy(Connection target) Wrap the given Connection with a proxy that delegates every method call to it
but suppresses close calls. | public ConnectionFactory | getTargetConnectionFactory() Return the target ConnectionFactory which will be used to lazily
create a single Connection, if any. | public void | initConnection() Initialize the underlying shared Connection. | protected boolean | isReconnectOnException() Return whether the single Connection should be renewed when
a JMSException is reported by the underlying Connection. | public void | onException(JMSException ex) Exception listener callback that renews the underlying single Connection. | protected void | prepareConnection(Connection con) Prepare the given Connection before it is exposed. | public void | resetConnection() Reset the underlying shared Connection, to be reinitialized on next access. | public void | setClientId(String clientId) 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. | public void | setExceptionListener(ExceptionListener exceptionListener) Specify an JMS ExceptionListener implementation that should be
registered with with the single Connection created by this factory. | public void | setReconnectOnException(boolean reconnectOnException) Specify whether the single Connection should be reset (to be subsequently renewed)
when a JMSException is reported by the underlying Connection.
Default is "false". | public void | setTargetConnectionFactory(ConnectionFactory targetConnectionFactory) Set the target ConnectionFactory which will be used to lazily
create a single Connection. |
logger | final protected Log logger(Code) | | |
SingleConnectionFactory | public SingleConnectionFactory(Connection target)(Code) | | Create a new SingleConnectionFactory that always returns the
given Connection. Works with both JMS 1.1 and 1.0.2.
Parameters: target - the single Connection |
SingleConnectionFactory | public SingleConnectionFactory(ConnectionFactory targetConnectionFactory)(Code) | | Create a new SingleConnectionFactory that always returns a single
Connection that it will lazily create via the given target
ConnectionFactory.
Parameters: targetConnectionFactory - the target ConnectionFactory |
afterPropertiesSet | public void afterPropertiesSet()(Code) | | Make sure a Connection or ConnectionFactory has been set.
|
closeConnection | protected void closeConnection(Connection con)(Code) | | Close the given Connection.
Parameters: con - the Connection to close |
createConnection | public Connection createConnection() throws JMSException(Code) | | |
createConnection | public Connection createConnection(String username, String password) throws JMSException(Code) | | |
createQueueConnection | public QueueConnection createQueueConnection() throws JMSException(Code) | | |
createQueueConnection | public QueueConnection createQueueConnection(String username, String password) throws JMSException(Code) | | |
createTopicConnection | public TopicConnection createTopicConnection() throws JMSException(Code) | | |
createTopicConnection | public TopicConnection createTopicConnection(String username, String password) throws JMSException(Code) | | |
destroy | public void destroy()(Code) | | 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.
|
doCreateConnection | protected Connection doCreateConnection() throws JMSException(Code) | | Create a JMS Connection via this template's ConnectionFactory.
This implementation uses JMS 1.1 API.
the new JMS Connection throws: javax.jms.JMSException - if thrown by JMS API methods |
getClientId | protected String getClientId()(Code) | | Return a JMS client ID for the single Connection created and exposed
by this ConnectionFactory, if any.
|
getExceptionListener | protected ExceptionListener getExceptionListener()(Code) | | Return the JMS ExceptionListener implementation that should be registered
with with the single Connection created by this factory, if any.
|
getSharedConnectionProxy | protected Connection getSharedConnectionProxy(Connection target)(Code) | | 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.
Parameters: target - the original Connection to wrap the wrapped Connection |
getTargetConnectionFactory | public ConnectionFactory getTargetConnectionFactory()(Code) | | Return the target ConnectionFactory which will be used to lazily
create a single Connection, if any.
|
initConnection | public void initConnection() throws JMSException(Code) | | Initialize the underlying shared Connection.
Closes and reinitializes the Connection if an underlying
Connection is present already.
throws: javax.jms.JMSException - if thrown by JMS API methods |
isReconnectOnException | protected boolean isReconnectOnException()(Code) | | Return whether the single Connection should be renewed when
a JMSException is reported by the underlying Connection.
|
onException | public void onException(JMSException ex)(Code) | | Exception listener callback that renews the underlying single Connection.
|
resetConnection | public void resetConnection()(Code) | | Reset the underlying shared Connection, to be reinitialized on next access.
|
setClientId | public void setClientId(String clientId)(Code) | | 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.
See Also: javax.jms.Connection.setClientID See Also: SingleConnectionFactory.setTargetConnectionFactory |
setExceptionListener | public void setExceptionListener(ExceptionListener exceptionListener)(Code) | | Specify an JMS ExceptionListener implementation that should be
registered with with the single Connection created by this factory.
See Also: SingleConnectionFactory.setReconnectOnException |
setReconnectOnException | public void setReconnectOnException(boolean reconnectOnException)(Code) | | 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.
See Also: SingleConnectionFactory.setExceptionListener |
setTargetConnectionFactory | public void setTargetConnectionFactory(ConnectionFactory targetConnectionFactory)(Code) | | Set the target ConnectionFactory which will be used to lazily
create a single Connection.
|
|
|