类 AbstractJmsListeningContainer
- java.lang.Object
- org.springframework.jms.support.JmsAccessor
- org.springframework.jms.support.destination.JmsDestinationAccessor
- org.springframework.jms.listener.AbstractJmsListeningContainer
- 所有已实现的接口:
Aware
,BeanNameAware
,DisposableBean
,InitializingBean
,Lifecycle
,Phased
,SmartLifecycle
public abstract class AbstractJmsListeningContainer extends JmsDestinationAccessor implements BeanNameAware, DisposableBean, SmartLifecycle
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 theJmsAccessor
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 thedoInitialize()
anddoShutdown()
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 theDefaultMessageListenerContainer
class.- 从以下版本开始:
- 2.0.3
- 作者:
- Juergen Hoeller
- 另请参阅:
sharedConnectionEnabled()
,doInitialize()
,doShutdown()
嵌套类概要
嵌套类 修饰符和类型 类 说明 static class
AbstractJmsListeningContainer.SharedConnectionNotInitializedException
Exception that indicates that the initial setup of this container's shared JMS Connection failed.
字段概要
字段 修饰符和类型 字段 说明 protected Object
lifecycleMonitor
protected Object
sharedConnectionMonitor
从类继承的字段 org.springframework.jms.support.destination.JmsDestinationAccessor
RECEIVE_TIMEOUT_INDEFINITE_WAIT, RECEIVE_TIMEOUT_NO_WAIT
从类继承的字段 org.springframework.jms.support.JmsAccessor
logger
构造器概要
构造器 构造器 说明 AbstractJmsListeningContainer()
方法概要
所有方法 实例方法 抽象方法 具体方法 修饰符和类型 方法 说明 void
afterPropertiesSet()
Delegates tovalidateConfiguration()
andinitialize()
.protected Connection
createSharedConnection()
Create a shared Connection for this container.void
destroy()
Callsshutdown()
when the BeanFactory destroys the container instance.protected abstract void
doInitialize()
Register any invokers within this container.protected void
doRescheduleTask(Object task)
Reschedule the given task object immediately.protected abstract void
doShutdown()
Close the registered invokers.protected void
doStart()
Start the shared Connection, if any, and notify all invoker tasks.protected void
doStop()
Notify all invoker tasks and stop the shared Connection, if any.protected void
establishSharedConnection()
Establish a shared Connection for this container.protected String
getBeanName()
Return the bean name that this listener container has been assigned in its containing bean factory, if any.String
getClientId()
Return the JMS client ID for the shared Connection created and used by this container, if any.int
getPausedTaskCount()
Determine the number of currently paused tasks, if any.int
getPhase()
Return the phase in which this container will be started and stopped.protected Connection
getSharedConnection()
Return the shared JMS Connection maintained by this container.void
initialize()
Initialize this container.boolean
isActive()
Return whether this container is currently active, that is, whether it has been set up but not shut down yet.boolean
isAutoStartup()
Returnstrue
if thisLifecycle
component should get started automatically by the container at the time that the containingApplicationContext
gets refreshed.boolean
isRunning()
Determine whether this container is currently running, that is, whether it has been started and not stopped yet.protected void
logRejectedTask(Object task, RuntimeException ex)
Log a task that has been rejected bydoRescheduleTask(java.lang.Object)
.protected void
prepareSharedConnection(Connection connection)
Prepare the given Connection, which is about to be registered as shared Connection for this container.protected void
refreshSharedConnection()
Refresh the shared Connection that this container holds.protected boolean
rescheduleTaskIfNecessary(Object task)
Take the given task object and reschedule it, either immediately if this container is currently running, or later once this container has been restarted.protected void
resumePausedTasks()
Try to resume all paused tasks.protected boolean
runningAllowed()
Check whether this container's listeners are generally allowed to run.void
setAutoStartup(boolean autoStartup)
Set whether to automatically start the container after initialization.void
setBeanName(String beanName)
Set the name of the bean in the bean factory that created this bean.void
setClientId(String clientId)
Specify the JMS client ID for a shared Connection created and used by this container.void
setPhase(int phase)
Specify the phase in which this container should be started and stopped.protected abstract boolean
sharedConnectionEnabled()
Return whether a shared JMS Connection should be maintained by this container base class.void
shutdown()
Stop the shared Connection, calldoShutdown()
, and close this container.void
start()
Start this container.protected void
startSharedConnection()
Start the shared Connection.void
stop()
Stop this container.void
stop(Runnable callback)
Indicates that a Lifecycle component must stop if it is currently running.protected void
stopSharedConnection()
Stop the shared Connection.protected void
validateConfiguration()
Validate the configuration of this container.从类继承的方法 org.springframework.jms.support.destination.JmsDestinationAccessor
getDestinationResolver, isPubSubDomain, receiveFromConsumer, resolveDestinationName, setDestinationResolver, setPubSubDomain
从类继承的方法 org.springframework.jms.support.JmsAccessor
convertJmsAccessException, createConnection, createSession, getConnectionFactory, getSessionAcknowledgeMode, isClientAcknowledge, isSessionTransacted, setConnectionFactory, setSessionAcknowledgeMode, setSessionAcknowledgeModeName, setSessionTransacted
字段详细资料
sharedConnectionMonitor
protected final Object sharedConnectionMonitor
lifecycleMonitor
protected final Object lifecycleMonitor
构造器详细资料
AbstractJmsListeningContainer
public AbstractJmsListeningContainer()
方法详细资料
setClientId
public void setClientId(String clientId)
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
public String 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()
从接口复制的说明:SmartLifecycle
Returnstrue
if thisLifecycle
component should get started automatically by the container at the time that the containingApplicationContext
gets refreshed.A value of
false
indicates that the component is intended to be started through an explicitLifecycle.start()
call instead, analogous to a plainLifecycle
implementation.
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.
setBeanName
public void setBeanName(String beanName)
从接口复制的说明:BeanNameAware
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
InitializingBean.afterPropertiesSet()
or a custom init-method.- 指定者:
setBeanName
在接口中BeanNameAware
- 参数:
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
protected final String 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()
.- 指定者:
afterPropertiesSet
在接口中InitializingBean
- 覆盖:
afterPropertiesSet
在类中JmsAccessor
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.- 指定者:
destroy
在接口中DisposableBean
- 另请参阅:
shutdown()
initialize
public void initialize() throws JmsException
Initialize this container.Creates a JMS Connection, starts the
Connection
(if"autoStartup"
hasn't been turned off), and callsdoInitialize()
.- 抛出:
JmsException
- if startup failed
shutdown
public void shutdown() throws JmsException
Stop the shared Connection, calldoShutdown()
, and close this container.- 抛出:
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
public void start() throws JmsException
Start this container.- 指定者:
start
在接口中Lifecycle
- 抛出:
JmsException
- if starting failed- 另请参阅:
doStart()
doStart
protected void doStart() throws JMSException
Start the shared Connection, if any, and notify all invoker tasks.- 抛出:
JMSException
- if thrown by JMS API methods- 另请参阅:
startSharedConnection()
stop
public void stop() throws JmsException
Stop this container.- 指定者:
stop
在接口中Lifecycle
- 抛出:
JmsException
- if stopping failed- 另请参阅:
doStop()
stop
public void stop(Runnable callback)
从接口复制的说明:SmartLifecycle
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 theSmartLifecycle
component does indeed stop.The
LifecycleProcessor
will call only this variant of thestop
method; i.e.Lifecycle.stop()
will not be called forSmartLifecycle
implementations unless explicitly delegated to within the implementation of this method.- 指定者:
stop
在接口中SmartLifecycle
- 另请参阅:
Lifecycle.stop()
,Phased.getPhase()
doStop
protected void doStop() throws JMSException
Notify all invoker tasks and stop the shared Connection, if any.- 抛出:
JMSException
- if thrown by JMS API methods- 另请参阅:
stopSharedConnection()
isRunning
public final boolean isRunning()
Determine whether this container is currently running, that is, whether it has been started and not stopped yet.- 指定者:
isRunning
在接口中Lifecycle
- 返回:
- whether the component is currently running
- 另请参阅:
start()
,stop()
,runningAllowed()
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
false
if such a restriction prevents listeners from running.
establishSharedConnection
protected void establishSharedConnection() throws 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.- 抛出:
JMSException
- if thrown by JMS API methods
refreshSharedConnection
protected final void refreshSharedConnection() throws 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.
- 抛出:
JMSException
- if thrown by JMS API methods
createSharedConnection
protected Connection createSharedConnection() throws JMSException
Create a shared Connection for this container.The default implementation creates a standard Connection and prepares it through
prepareSharedConnection(javax.jms.Connection)
.- 返回:
- the prepared Connection
- 抛出:
JMSException
- if the creation failed
prepareSharedConnection
protected void prepareSharedConnection(Connection connection) throws JMSException
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- 抛出:
JMSException
- if the preparation efforts failed- 另请参阅:
getClientId()
startSharedConnection
protected void startSharedConnection() throws JMSException
Start the shared Connection.- 抛出:
JMSException
- if thrown by JMS API methods- 另请参阅:
Connection.start()
stopSharedConnection
protected void stopSharedConnection() throws JMSException
Stop the shared Connection.- 抛出:
JMSException
- if thrown by JMS API methods- 另请参阅:
Connection.start()
getSharedConnection
protected final Connection getSharedConnection()
Return the shared JMS Connection maintained by this container. Available after initialization.- 返回:
- the shared Connection (never
null
) - 抛出:
IllegalStateException
- if this container does not maintain a shared Connection, or if the Connection hasn't been initialized yet- 另请参阅:
sharedConnectionEnabled()
rescheduleTaskIfNecessary
protected final boolean rescheduleTaskIfNecessary(Object task)
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- 返回:
- whether the task has been rescheduled (either immediately or for a restart of this container)
- 另请参阅:
doRescheduleTask(java.lang.Object)
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
protected void doRescheduleTask(Object task)
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- 另请参阅:
rescheduleTaskIfNecessary(java.lang.Object)
logRejectedTask
protected void logRejectedTask(Object task, RuntimeException ex)
Log a task that has been rejected bydoRescheduleTask(java.lang.Object)
.The default implementation simply logs a corresponding message at debug level.
- 参数:
task
- the rejected task objectex
- the exception thrown fromdoRescheduleTask(java.lang.Object)
sharedConnectionEnabled
protected abstract boolean sharedConnectionEnabled()
Return whether a shared JMS Connection should be maintained by this container base class.
doInitialize
protected abstract void doInitialize() throws 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.
- 抛出:
JMSException
- if registration failed- 另请参阅:
getSharedConnection()
doShutdown
protected abstract void doShutdown() throws JMSException
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.
- 抛出:
JMSException
- if shutdown failed- 另请参阅:
shutdown()