java.lang.Object | |||
↳ | org.springframework.jms.support.JmsAccessor | ||
↳ | org.springframework.jms.support.destination.JmsDestinationAccessor | ||
↳ | org.springframework.jms.listener.AbstractJmsListeningContainer |
![]() |
![]() |
Common base class for all containers which need to implement listening
based on a JMS Connection (either shared or freshly obtained for each attempt).
Inherits basic Connection and Session configuration handling from the
JmsAccessor
base class.
This class provides basic lifecycle management, in particular management
of a shared JMS Connection. Subclasses are supposed to plug into this
lifecycle, implementing the sharedConnectionEnabled()
as well
as the doInitialize()
and doShutdown()
template methods.
This base class does not assume any specific listener programming model or listener invoker mechanism. It just provides the general runtime lifecycle management needed for any kind of JMS-based listening mechanism that operates on a JMS Connection/Session.
For a concrete listener programming model, check out the
AbstractMessageListenerContainer
subclass. For a concrete listener
invoker mechanism, check out the DefaultMessageListenerContainer
class.
Nested Classes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
AbstractJmsListeningContainer.SharedConnectionNotInitializedException | Exception that indicates that the initial setup of this container's shared JMS Connection failed. |
Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
lifecycleMonitor | |||||||||||
sharedConnectionMonitor |
[Expand]
Inherited Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Delegates to
validateConfiguration() and initialize() . | |||||||||||
Calls
shutdown() when the BeanFactory destroys the container instance. | |||||||||||
Return the JMS client ID for the shared Connection created and used
by this container, if any.
| |||||||||||
Determine the number of currently paused tasks, if any.
| |||||||||||
Return the phase in which this container will be started and stopped.
| |||||||||||
Initialize this container.
| |||||||||||
Return whether this container is currently active,
that is, whether it has been set up but not shut down yet.
| |||||||||||
Return whether this Lifecycle component should be started automatically
by the container when the ApplicationContext is refreshed.
| |||||||||||
Determine whether this container is currently running,
that is, whether it has been started and not stopped yet.
| |||||||||||
Set whether to automatically start the container after initialization.
| |||||||||||
Set the name of the bean in the bean factory that created this bean.
| |||||||||||
Specify the JMS client id for a shared Connection created and used
by this container.
| |||||||||||
Specify the phase in which this container should be started and
stopped.
| |||||||||||
Stop the shared Connection, call
doShutdown() ,
and close this container. | |||||||||||
Start this container.
| |||||||||||
Stop this container.
| |||||||||||
Indicates that a Lifecycle component must stop if it is currently running.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Create a shared Connection for this container.
| |||||||||||
Register any invokers within this container.
| |||||||||||
Reschedule the given task object immediately.
| |||||||||||
Close the registered invokers.
| |||||||||||
Start the shared Connection, if any, and notify all invoker tasks.
| |||||||||||
Notify all invoker tasks and stop the shared Connection, if any.
| |||||||||||
Establish a shared Connection for this container.
| |||||||||||
Return the bean name that this listener container has been assigned
in its containing bean factory, if any.
| |||||||||||
Return the shared JMS Connection maintained by this container.
| |||||||||||
Log a task that has been rejected by
doRescheduleTask(Object) . | |||||||||||
Prepare the given Connection, which is about to be registered
as shared Connection for this container.
| |||||||||||
Refresh the shared Connection that this container holds.
| |||||||||||
Take the given task object and reschedule it, either immediately if
this container is currently running, or later once this container
has been restarted.
| |||||||||||
Try to resume all paused tasks.
| |||||||||||
Check whether this container's listeners are generally allowed to run.
| |||||||||||
Return whether a shared JMS Connection should be maintained
by this container base class.
| |||||||||||
Start the shared Connection.
| |||||||||||
Stop the shared Connection.
| |||||||||||
Validate the configuration of this container.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() | |||||||||||
![]() | |||||||||||
![]() | |||||||||||
![]() | |||||||||||
![]() | |||||||||||
![]() | |||||||||||
![]() | |||||||||||
![]() | |||||||||||
![]() |
Calls shutdown()
when the BeanFactory destroys the container instance.
Return the JMS client ID for the shared Connection created and used by this container, if any.
Determine the number of currently paused tasks, if any.
Return the phase in which this container will be started and stopped.
Initialize this container.
Creates a JMS Connection, starts the javax.jms.Connection
(if "autoStartup"
hasn't been turned off),
and calls doInitialize()
.
JmsException | if startup failed |
---|
Return whether this container is currently active, that is, whether it has been set up but not shut down yet.
Return whether this Lifecycle component should be started automatically by the container when the ApplicationContext is refreshed. A value of "false" indicates that the component is intended to be started manually.
Determine whether this container is currently running, that is, whether it has been started and not stopped yet.
Set whether to automatically start the container after initialization.
Default is "true"; set this to "false" to allow for manual startup
through the start()
method.
Set the name of the bean in the bean factory that created this bean.
Invoked after population of normal bean properties but before an
init callback such as afterPropertiesSet()
or a custom init-method.
beanName | the name of the bean in the factory. Note that this name is the actual bean name used in the factory, which may differ from the originally specified name: in particular for inner bean names, the actual bean name might have been made unique through appending "#..." suffixes. Use the BeanFactoryUtils#originalBeanName(String) method to extract the original bean name (without suffix), if desired. |
---|
Specify the JMS client id for a shared Connection created and used by this container.
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.
setConnectionFactory(ConnectionFactory)
Specify the phase in which this container should be started and stopped. The startup order proceeds from lowest to highest, and the shutdown order is the reverse of that. By default this value is Integer.MAX_VALUE meaning that this container starts as late as possible and stops as soon as possible.
Stop the shared Connection, call doShutdown()
,
and close this container.
JmsException | if shutdown failed |
---|
Indicates that a Lifecycle component must stop if it is currently running.
The provided callback is used by the LifecycleProcessor to support an ordered, and potentially concurrent, shutdown of all components having a common shutdown order value. The callback must be executed after the SmartLifecycle component does indeed stop.
Create a shared Connection for this container.
The default implementation creates a standard Connection
and prepares it through prepareSharedConnection(Connection)
.
if the creation failed | |
JMSException |
Register any invokers within this container.
Subclasses need to implement this method for their specific invoker management process.
A shared JMS Connection, if any, will already have been started at this point.
if registration failed | |
JMSException |
Reschedule the given task object immediately.
To be implemented by subclasses if they ever call
rescheduleTaskIfNecessary
.
This implementation throws an UnsupportedOperationException.
task | the task object to reschedule |
---|
Close the registered invokers.
Subclasses need to implement this method for their specific invoker management process.
A shared JMS Connection, if any, will automatically be closed afterwards.
if shutdown failed | |
JMSException |
Start the shared Connection, if any, and notify all invoker tasks.
if thrown by JMS API methods | |
JMSException |
Notify all invoker tasks and stop the shared Connection, if any.
if thrown by JMS API methods | |
JMSException |
Establish a shared Connection for this container.
The default implementation delegates to createSharedConnection()
,
which does one immediate attempt and throws an exception if it fails.
Can be overridden to have a recovery process in place, retrying
until a Connection can be successfully established.
if thrown by JMS API methods | |
JMSException |
Return the bean name that this listener container has been assigned in its containing bean factory, if any.
Return the shared JMS Connection maintained by this container. Available after initialization.
null
)IllegalStateException | if this container does not maintain a shared Connection, or if the Connection hasn't been initialized yet |
---|
Log a task that has been rejected by doRescheduleTask(Object)
.
The default implementation simply logs a corresponding message at debug level.
task | the rejected task object |
---|---|
ex | the exception thrown from doRescheduleTask(Object)
|
Prepare the given Connection, which is about to be registered as shared Connection for this container.
The default implementation sets the specified client id, if any. Subclasses can override this to apply further settings.
connection | the Connection to prepare |
---|
if the preparation efforts failed | |
JMSException |
Refresh the shared Connection that this container holds.
Called on startup and also after an infrastructure exception that occurred during invoker setup and/or execution.
if thrown by JMS API methods | |
JMSException |
Take the given task object and reschedule it, either immediately if this container is currently running, or later once this container has been restarted.
If this container has already been shut down, the task will not get rescheduled at all.
task | the task object to reschedule |
---|
Try to resume all paused tasks. Tasks for which rescheduling failed simply remain in paused mode.
Check whether this container's listeners are generally allowed to run.
This implementation always returns true
; the default 'running'
state is purely determined by start()
/ stop()
.
Subclasses may override this method to check against temporary
conditions that prevent listeners from actually running. In other words,
they may apply further restrictions to the 'running' state, returning
false
if such a restriction prevents listeners from running.
Return whether a shared JMS Connection should be maintained by this container base class.
Start the shared Connection.
if thrown by JMS API methods | |
JMSException |
Stop the shared Connection.
if thrown by JMS API methods | |
JMSException |
Validate the configuration of this container.
The default implementation is empty. To be overridden in subclasses.