Class AbstractJmsListeningContainer
- All Implemented Interfaces:
Aware,BeanNameAware,DisposableBean,InitializingBean,Lifecycle,Phased,SmartLifecycle
- Direct Known Subclasses:
AbstractMessageListenerContainer
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.
- Since:
- 2.0.3
- Author:
- Juergen Hoeller
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classException that indicates that the initial setup of this container's shared JMS Connection failed. -
Field Summary
FieldsFields inherited from class org.springframework.jms.support.destination.JmsDestinationAccessor
RECEIVE_TIMEOUT_INDEFINITE_WAIT, RECEIVE_TIMEOUT_NO_WAITFields inherited from class org.springframework.jms.support.JmsAccessor
loggerFields inherited from interface org.springframework.context.SmartLifecycle
DEFAULT_PHASE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidDelegates tovalidateConfiguration()andinitialize().protected ConnectionCreate a shared Connection for this container.voiddestroy()Callsshutdown()when the BeanFactory destroys the container instance.protected abstract voidRegister any invokers within this container.protected voiddoRescheduleTask(Object task) Reschedule the given task object immediately.protected abstract voidClose the registered invokers.protected voiddoStart()Start the shared Connection, if any, and notify all invoker tasks.protected voiddoStop()Notify all invoker tasks and stop the shared Connection, if any.protected voidEstablish a shared Connection for this container.protected final StringReturn the bean name that this listener container has been assigned in its containing bean factory, if any.Return the JMS client ID for the shared Connection created and used by this container, if any.intDetermine the number of currently paused tasks, if any.intgetPhase()Return the phase in which this container will be started and stopped.protected final ConnectionReturn the shared JMS Connection maintained by this container.voidInitialize this container.final booleanisActive()Return whether this container is currently active, that is, whether it has been set up but not shut down yet.booleanReturnstrueif thisLifecyclecomponent should get started automatically by the container at the time that the containingApplicationContextgets refreshed.final booleanDetermine whether this container is currently running, that is, whether it has been started and not stopped yet.protected voidlogRejectedTask(Object task, RuntimeException ex) Log a task that has been rejected bydoRescheduleTask(java.lang.Object).protected voidprepareSharedConnection(Connection connection) Prepare the given Connection, which is about to be registered as shared Connection for this container.protected final voidRefresh the shared Connection that this container holds.protected final booleanTake the given task object and reschedule it, either immediately if this container is currently running, or later once this container has been restarted.protected voidTry to resume all paused tasks.protected booleanCheck whether this container's listeners are generally allowed to run.voidsetAutoStartup(boolean autoStartup) Set whether to automatically start the container after initialization.voidsetBeanName(String beanName) Set the name of the bean in the bean factory that created this bean.voidsetClientId(String clientId) Specify the JMS client ID for a shared Connection created and used by this container.voidsetPhase(int phase) Specify the phase in which this container should be started and stopped.protected abstract booleanReturn whether a shared JMS Connection should be maintained by this container base class.voidshutdown()Stop the shared Connection, calldoShutdown(), and close this container.voidstart()Start this container.protected voidStart the shared Connection.voidstop()Stop this container.protected voidStop the shared Connection.protected voidValidate the configuration of this container.Methods inherited from class org.springframework.jms.support.destination.JmsDestinationAccessor
getDestinationResolver, isPubSubDomain, receiveFromConsumer, resolveDestinationName, setDestinationResolver, setPubSubDomainMethods inherited from class org.springframework.jms.support.JmsAccessor
convertJmsAccessException, createConnection, createSession, getConnectionFactory, getSessionAcknowledgeMode, isClientAcknowledge, isSessionTransacted, obtainConnectionFactory, setConnectionFactory, setSessionAcknowledgeMode, setSessionAcknowledgeModeName, setSessionTransactedMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.context.SmartLifecycle
stop
-
Field Details
-
lifecycleMonitor
-
Constructor Details
-
AbstractJmsListeningContainer
public AbstractJmsListeningContainer()
-
-
Method Details
-
setClientId
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.
-
getClientId
Return the JMS client ID for the shared Connection created and used by this container, if any. -
setAutoStartup
public void setAutoStartup(boolean autoStartup) 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. -
isAutoStartup
public boolean isAutoStartup()Description copied from interface:SmartLifecycleReturnstrueif thisLifecyclecomponent should get started automatically by the container at the time that the containingApplicationContextgets refreshed.A value of
falseindicates that the component is intended to be started through an explicitLifecycle.start()call instead, analogous to a plainLifecycleimplementation.The default implementation returns
true.- Specified by:
isAutoStartupin interfaceSmartLifecycle- See Also:
-
setPhase
public void setPhase(int phase) 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. -
getPhase
public int getPhase()Return the phase in which this container will be started and stopped.- Specified by:
getPhasein interfacePhased- Specified by:
getPhasein interfaceSmartLifecycle- See Also:
-
setBeanName
Description copied from interface:BeanNameAwareSet 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
InitializingBean.afterPropertiesSet()or a custom init-method.- Specified by:
setBeanNamein interfaceBeanNameAware- Parameters:
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 theBeanFactoryUtils.originalBeanName(String)method to extract the original bean name (without suffix), if desired.
-
getBeanName
Return the bean name that this listener container has been assigned in its containing bean factory, if any. -
afterPropertiesSet
public void afterPropertiesSet()Delegates tovalidateConfiguration()andinitialize().- Specified by:
afterPropertiesSetin interfaceInitializingBean- Overrides:
afterPropertiesSetin classJmsAccessor
-
validateConfiguration
protected void validateConfiguration()Validate the configuration of this container.The default implementation is empty. To be overridden in subclasses.
-
destroy
public void destroy()Callsshutdown()when the BeanFactory destroys the container instance.- Specified by:
destroyin interfaceDisposableBean- See Also:
-
initialize
Initialize this container.Creates a JMS Connection, starts the
Connection(if"autoStartup"hasn't been turned off), and callsdoInitialize().- Throws:
JmsException- if startup failed
-
shutdown
Stop the shared Connection, calldoShutdown(), and close this container.- Throws:
JmsException- if shutdown failed
-
isActive
public final boolean isActive()Return whether this container is currently active, that is, whether it has been set up but not shut down yet. -
start
Start this container.- Specified by:
startin interfaceLifecycle- Throws:
JmsException- if starting failed- See Also:
-
doStart
Start the shared Connection, if any, and notify all invoker tasks.- Throws:
JMSException- if thrown by JMS API methods- See Also:
-
stop
Stop this container.- Specified by:
stopin interfaceLifecycle- Throws:
JmsException- if stopping failed- See Also:
-
doStop
Notify all invoker tasks and stop the shared Connection, if any.- Throws:
JMSException- if thrown by JMS API methods- See Also:
-
isRunning
public final boolean isRunning()Determine whether this container is currently running, that is, whether it has been started and not stopped yet. -
runningAllowed
protected boolean runningAllowed()Check whether this container's listeners are generally allowed to run.This implementation always returns
true; the default 'running' state is purely determined bystart()/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
falseif such a restriction prevents listeners from running. -
rescheduleTaskIfNecessary
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.
- Parameters:
task- the task object to reschedule- Returns:
- whether the task has been rescheduled (either immediately or for a restart of this container)
- See Also:
-
resumePausedTasks
protected void resumePausedTasks()Try to resume all paused tasks. Tasks for which rescheduling failed simply remain in paused mode. -
getPausedTaskCount
public int getPausedTaskCount()Determine the number of currently paused tasks, if any. -
doRescheduleTask
Reschedule the given task object immediately.To be implemented by subclasses if they ever call
rescheduleTaskIfNecessary. This implementation throws an UnsupportedOperationException.- Parameters:
task- the task object to reschedule- See Also:
-
logRejectedTask
Log a task that has been rejected bydoRescheduleTask(java.lang.Object).The default implementation simply logs a corresponding message at warn level.
- Parameters:
task- the rejected task objectex- the exception thrown fromdoRescheduleTask(java.lang.Object)
-
doInitialize
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.
- Throws:
JMSException- if registration failed- See Also:
-
doShutdown
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.
- Throws:
JMSException- if shutdown failed- See Also:
-