Save This Page
Home » spring-framework-2.5.5-with-dependencies » org.springframework » jms » listener » [javadoc | source]
org.springframework.jms.listener
abstract public class: AbstractJmsListeningContainer [javadoc | source]
java.lang.Object
   org.springframework.jms.support.JmsAccessor
      org.springframework.jms.support.destination.JmsDestinationAccessor
         org.springframework.jms.listener.AbstractJmsListeningContainer

All Implemented Interfaces:
    DisposableBean, BeanNameAware, Lifecycle, InitializingBean

Direct Known Subclasses:
    ServerSessionMessageListenerContainer, SimpleMessageListenerContainer, AbstractPollingMessageListenerContainer, DefaultMessageListenerContainer, DefaultMessageListenerContainer102, AbstractMessageListenerContainer, ServerSessionMessageListenerContainer102, SimpleMessageListenerContainer102

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 org.springframework.jms.support.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 Class Summary:
public static class  AbstractJmsListeningContainer.SharedConnectionNotInitializedException  Exception that indicates that the initial setup of this container's shared JMS Connection failed. This is indicating to invokers that they need to establish the shared Connection themselves on first access. 
Field Summary
protected final  Object sharedConnectionMonitor     
protected final  Object lifecycleMonitor     
Fields inherited from org.springframework.jms.support.JmsAccessor:
logger
Method from org.springframework.jms.listener.AbstractJmsListeningContainer Summary:
afterPropertiesSet,   createSharedConnection,   destroy,   doInitialize,   doRescheduleTask,   doShutdown,   doStart,   doStop,   establishSharedConnection,   getBeanName,   getClientId,   getPausedTaskCount,   getSharedConnection,   initialize,   isActive,   isRunning,   logRejectedTask,   prepareSharedConnection,   refreshSharedConnection,   rescheduleTaskIfNecessary,   resumePausedTasks,   runningAllowed,   setAutoStartup,   setBeanName,   setClientId,   sharedConnectionEnabled,   shutdown,   start,   startSharedConnection,   stop,   stopSharedConnection,   validateConfiguration,   waitWhileNotRunning
Methods from org.springframework.jms.support.destination.JmsDestinationAccessor:
getDestinationResolver,   isPubSubDomain,   resolveDestinationName,   setDestinationResolver,   setPubSubDomain
Methods from org.springframework.jms.support.JmsAccessor:
afterPropertiesSet,   convertJmsAccessException,   createConnection,   createSession,   getConnectionFactory,   getSessionAcknowledgeMode,   isClientAcknowledge,   isSessionTransacted,   setConnectionFactory,   setSessionAcknowledgeMode,   setSessionAcknowledgeModeName,   setSessionTransacted
Methods from java.lang.Object:
equals,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from org.springframework.jms.listener.AbstractJmsListeningContainer Detail:
 public  void afterPropertiesSet() 
 protected Connection createSharedConnection() throws JMSException 
    Create a shared Connection for this container.

    The default implementation creates a standard Connection and prepares it through #prepareSharedConnection .

 public  void destroy() 
    Calls #shutdown() when the BeanFactory destroys the container instance.
 abstract protected  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.

 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.

 abstract protected  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.

 protected  void doStart() throws JMSException 
    Start the shared Connection, if any, and notify all invoker tasks.
 protected  void doStop() throws JMSException 
    Notify all invoker tasks and stop the shared Connection, if any.
 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.

 protected final String getBeanName() 
    Return the bean name that this listener container has been assigned in its containing bean factory, if any.
 public String getClientId() 
    Return the JMS client ID for the shared Connection created and used by this container, if any.
 public int getPausedTaskCount() 
 protected final Connection getSharedConnection() 
    Return the shared JMS Connection maintained by this container. Available after initialization.
 public  void initialize() throws JmsException 
 public final boolean isActive() 
    Return whether this container is currently active, that is, whether it has been set up but not shut down yet.
 public final 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 by #doRescheduleTask .

    The default implementation simply logs a corresponding message at debug level.

 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.

 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.

 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.

 protected  void resumePausedTasks() 
    Try to resume all paused tasks. Tasks for which rescheduling failed simply remain in paused mode.
 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 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.

 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.

 public  void setBeanName(String beanName) 
 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.

 abstract protected boolean sharedConnectionEnabled()
    Return whether a shared JMS Connection should be maintained by this container base class.
 public  void shutdown() throws JmsException 
    Stop the shared Connection, call #doShutdown() , and close this container.
 public  void start() throws JmsException 
    Start this container.
 protected  void startSharedConnection() throws JMSException 
    Start the shared Connection.
 public  void stop() throws JmsException 
    Stop this container.
 protected  void stopSharedConnection() throws JMSException 
    Stop the shared Connection.
 protected  void validateConfiguration() 
    Validate the configuration of this container.

    The default implementation is empty. To be overridden in subclasses.

 protected final  void waitWhileNotRunning() 
    Wait while this container is not running.

    To be called by asynchronous tasks that want to block while the container is in stopped state.