org.springframework.jms.config

## Class JmsListenerEndpointRegistry

- java.lang.Object
- - org.springframework.jms.config.JmsListenerEndpointRegistry

- All Implemented Interfaces:
    EventListener, Aware, DisposableBean, ApplicationContextAware, ApplicationListener<ContextRefreshedEvent>, Lifecycle, Phased, SmartLifecycle

      public class JmsListenerEndpointRegistry
      extends Object
      implements DisposableBean, SmartLifecycle, ApplicationContextAware, ApplicationListener<ContextRefreshedEvent>

  Creates the necessary `MessageListenerContainer` instances for the registered endpoints. Also manages the lifecycle of the listener containers, in particular within the lifecycle of the application context.

  Contrary to `MessageListenerContainers` created manually, listener containers managed by registry are not beans in the application context and are not candidates for autowiring. Use `getListenerContainers()` if you need to access this registry's listener containers for management purposes. If you need to access to a specific message listener container, use `getListenerContainer(String)` with the id of the endpoint.

  Since:
    4.1
  Author:
    Stephane Nicoll, Juergen Hoeller
  See Also:
    `JmsListenerEndpoint`, `MessageListenerContainer`, `JmsListenerContainerFactory`

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected Log` | `logger`

    - ### Fields inherited from interface org.springframework.context.SmartLifecycle

      `DEFAULT_PHASE`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `JmsListenerEndpointRegistry()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected MessageListenerContainer` | `createListenerContainer(JmsListenerEndpoint endpoint, JmsListenerContainerFactory<?> factory)` Create and start a new container using the specified factory.
    `void` | `destroy()` Invoked by the containing `BeanFactory` on destruction of a bean.
    `MessageListenerContainer` | `getListenerContainer(String id)` Return the `MessageListenerContainer` with the specified id or `null` if no such container exists.
    `Set<String>` | `getListenerContainerIds()` Return the ids of the managed `MessageListenerContainer` instance(s).
    `Collection<MessageListenerContainer>` | `getListenerContainers()` Return the managed `MessageListenerContainer` instance(s).
    `int` | `getPhase()` Return the phase that this lifecycle object is supposed to run in.
    `boolean` | `isRunning()` Check whether this component is currently running.
    `void` | `onApplicationEvent(ContextRefreshedEvent event)` Handle an application event.
    `void` | `registerListenerContainer(JmsListenerEndpoint endpoint, JmsListenerContainerFactory<?> factory)` Create a message listener container for the given `JmsListenerEndpoint`.
    `void` | `registerListenerContainer(JmsListenerEndpoint endpoint, JmsListenerContainerFactory<?> factory, boolean startImmediately)` Create a message listener container for the given `JmsListenerEndpoint`.
    `void` | `setApplicationContext(ApplicationContext applicationContext)` Set the ApplicationContext that this object runs in.
    `void` | `start()` Start this component.
    `void` | `stop()` Stop this component, typically in a synchronous fashion, such that the component is fully stopped upon return of this method.
    `void` | `stop(Runnable callback)` Indicates that a Lifecycle component must stop if it is currently running.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface org.springframework.context.SmartLifecycle

      `isAutoStartup`

    - ### Methods inherited from interface org.springframework.context.ApplicationListener

      `forPayload`

- - ### Field Detail

    - #### logger

          protected final Log logger

  - ### Constructor Detail

    - #### JmsListenerEndpointRegistry

          public JmsListenerEndpointRegistry()

  - ### Method Detail

    - #### setApplicationContext

          public void setApplicationContext(ApplicationContext applicationContext)

      Description copied from interface: `ApplicationContextAware`
      Set the ApplicationContext that this object runs in. Normally this call will be used to initialize the object.

      Invoked after population of normal bean properties but before an init callback such as `InitializingBean.afterPropertiesSet()` or a custom init-method. Invoked after `ResourceLoaderAware.setResourceLoader(org.springframework.core.io.ResourceLoader)`, `ApplicationEventPublisherAware.setApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher)` and `MessageSourceAware`, if applicable.

      Specified by:
        `setApplicationContext` in interface `ApplicationContextAware`
      Parameters:
        `applicationContext` - the ApplicationContext object to be used by this object
      See Also:
        `BeanInitializationException`

    - #### onApplicationEvent

          public void onApplicationEvent(ContextRefreshedEvent event)

      Description copied from interface: `ApplicationListener`
      Handle an application event.
      Specified by:
        `onApplicationEvent` in interface `ApplicationListener<ContextRefreshedEvent>`
      Parameters:
        `event` - the event to respond to

    - #### getListenerContainer

          @Nullable
          public MessageListenerContainer getListenerContainer(String id)

      Return the `MessageListenerContainer` with the specified id or `null` if no such container exists.
      Parameters:
        `id` - the id of the container
      Returns:
        the container or `null` if no container with that id exists
      See Also:
        `JmsListenerEndpoint.getId()`, `getListenerContainerIds()`

    - #### getListenerContainerIds

          public Set<String> getListenerContainerIds()

      Return the ids of the managed `MessageListenerContainer` instance(s).
      Since:
        4.2.3
      See Also:
        `getListenerContainer(String)`

    - #### getListenerContainers

          public Collection<MessageListenerContainer> getListenerContainers()

      Return the managed `MessageListenerContainer` instance(s).

    - #### registerListenerContainer

          public void registerListenerContainer(JmsListenerEndpoint endpoint,
                                                JmsListenerContainerFactory<?> factory,
                                                boolean startImmediately)

      Create a message listener container for the given `JmsListenerEndpoint`.

      This create the necessary infrastructure to honor that endpoint with regard to its configuration.

      The `startImmediately` flag determines if the container should be started immediately.

      Parameters:
        `endpoint` - the endpoint to add
        `factory` - the listener factory to use
        `startImmediately` - start the container immediately if necessary
      See Also:
        `getListenerContainers()`, `getListenerContainer(String)`

    - #### registerListenerContainer

          public void registerListenerContainer(JmsListenerEndpoint endpoint,
                                                JmsListenerContainerFactory<?> factory)

      Create a message listener container for the given `JmsListenerEndpoint`.

      This create the necessary infrastructure to honor that endpoint with regard to its configuration.

      Parameters:
        `endpoint` - the endpoint to add
        `factory` - the listener factory to use
      See Also:
        `registerListenerContainer(JmsListenerEndpoint, JmsListenerContainerFactory, boolean)`

    - #### createListenerContainer

          protected MessageListenerContainer createListenerContainer(JmsListenerEndpoint endpoint,
                                                                     JmsListenerContainerFactory<?> factory)

      Create and start a new container using the specified factory.

    - #### getPhase

          public int getPhase()

      Description copied from interface: `SmartLifecycle`
      Return the phase that this lifecycle object is supposed to run in.

      The default implementation returns `SmartLifecycle.DEFAULT_PHASE` in order to let `stop()` callbacks execute before regular `Lifecycle` implementations.

      Specified by:
        `getPhase` in interface `Phased`
      Specified by:
        `getPhase` in interface `SmartLifecycle`
      See Also:
        `SmartLifecycle.isAutoStartup()`, `Lifecycle.start()`, `SmartLifecycle.stop(Runnable)`, `DefaultLifecycleProcessor.getPhase(Lifecycle)`

    - #### start

          public void start()

      Description copied from interface: `Lifecycle`
      Start this component.

      Should not throw an exception if the component is already running.

      In the case of a container, this will propagate the start signal to all components that apply.

      Specified by:
        `start` in interface `Lifecycle`
      See Also:
        `SmartLifecycle.isAutoStartup()`

    - #### stop

          public void stop()

      Description copied from interface: `Lifecycle`
      Stop this component, typically in a synchronous fashion, such that the component is fully stopped upon return of this method. Consider implementing `SmartLifecycle` and its `stop(Runnable)` variant when asynchronous stop behavior is necessary.

      Note that this stop notification is not guaranteed to come before destruction: On regular shutdown, `Lifecycle` beans will first receive a stop notification before the general destruction callbacks are being propagated; however, on hot refresh during a context's lifetime or on aborted refresh attempts, a given bean's destroy method will be called without any consideration of stop signals upfront.

      Should not throw an exception if the component is not running (not started yet).

      In the case of a container, this will propagate the stop signal to all components that apply.

      Specified by:
        `stop` in interface `Lifecycle`
      See Also:
        `SmartLifecycle.stop(Runnable)`, `DisposableBean.destroy()`

    - #### stop

          public void stop(Runnable callback)

      Description copied from interface: `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 the `SmartLifecycle` component does indeed stop.

      The `LifecycleProcessor` will call only this variant of the `stop` method; i.e. `Lifecycle.stop()` will not be called for `SmartLifecycle` implementations unless explicitly delegated to within the implementation of this method.

      The default implementation delegates to `Lifecycle.stop()` and immediately triggers the given callback in the calling thread. Note that there is no synchronization between the two, so custom implementations may at least want to put the same steps within their common lifecycle monitor (if any).

      Specified by:
        `stop` in interface `SmartLifecycle`
      See Also:
        `Lifecycle.stop()`, `SmartLifecycle.getPhase()`

    - #### isRunning

          public boolean isRunning()

      Description copied from interface: `Lifecycle`
      Check whether this component is currently running.

      In the case of a container, this will return `true` only if all components that apply are currently running.

      Specified by:
        `isRunning` in interface `Lifecycle`
      Returns:
        whether the component is currently running

    - #### destroy

          public void destroy()

      Description copied from interface: `DisposableBean`
      Invoked by the containing `BeanFactory` on destruction of a bean.
      Specified by:
        `destroy` in interface `DisposableBean`