org.springframework.jms.listener

Class AbstractJmsListeningContainer

    • Field Detail

      • sharedConnectionMonitor

        protected final java.lang.Object sharedConnectionMonitor
      • lifecycleMonitor

        protected final java.lang.Object lifecycleMonitor
    • Constructor Detail

      • AbstractJmsListeningContainer

        public AbstractJmsListeningContainer()
    • Method Detail

      • getClientId

        @Nullable
        public java.lang.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.

      • 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.
      • setBeanName

        public void setBeanName(@Nullable
                                java.lang.String beanName)
        Description copied from interface: 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.

        Specified by:
        setBeanName in interface BeanNameAware
        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 the BeanFactoryUtils.originalBeanName(String) method to extract the original bean name (without suffix), if desired.
      • getBeanName

        @Nullable
        protected final java.lang.String getBeanName()
        Return the bean name that this listener container has been assigned in its containing bean factory, if any.
      • validateConfiguration

        protected void validateConfiguration()
        Validate the configuration of this container.

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

      • 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.
      • isRunning

        public final boolean isRunning()
        Determine whether this container is currently running, that is, whether it has been started and not stopped yet.
        Specified by:
        isRunning in interface Lifecycle
        Returns:
        whether the component is currently running
        See Also:
        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 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.

      • 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.

        Throws:
        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.

        Throws:
        JMSException - if thrown by JMS API methods
      • 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.

        Parameters:
        connection - the Connection to prepare
        Throws:
        JMSException - if the preparation efforts failed
        See Also:
        getClientId()
      • getSharedConnection

        protected final Connection getSharedConnection()
        Return the shared JMS Connection maintained by this container. Available after initialization.
        Returns:
        the shared Connection (never null)
        Throws:
        java.lang.IllegalStateException - if this container does not maintain a shared Connection, or if the Connection hasn't been initialized yet
        See Also:
        sharedConnectionEnabled()
      • rescheduleTaskIfNecessary

        protected final boolean rescheduleTaskIfNecessary(java.lang.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.

        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:
        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(java.lang.Object task)
        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:
        rescheduleTaskIfNecessary(java.lang.Object)
      • logRejectedTask

        protected void logRejectedTask(java.lang.Object task,
                                       java.lang.RuntimeException ex)
        Log a task that has been rejected by doRescheduleTask(java.lang.Object).

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

        Parameters:
        task - the rejected task object
        ex - the exception thrown from doRescheduleTask(java.lang.Object)
      • sharedConnectionEnabled

        protected abstract boolean sharedConnectionEnabled()
        Return whether a shared JMS Connection should be maintained by this container base class.
        See Also:
        getSharedConnection()
      • 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.

        Throws:
        JMSException - if registration failed
        See Also:
        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.

        Throws:
        JMSException - if shutdown failed
        See Also:
        shutdown()