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 necessaryMessageListenerContainer
instances for the registered endpoints. Also manages the lifecycle of the listener containers, in particular within the lifecycle of the application context.Contrary to
MessageListenerContainer
s created manually, listener containers managed by registry are not beans in the application context and are not candidates for autowiring. UsegetListenerContainers()
if you need to access this registry's listener containers for management purposes. If you need to access to a specific message listener container, usegetListenerContainer(String)
with the id of the endpoint.- Since:
- 4.1
- Author:
- Stephane Nicoll, Juergen Hoeller
- See Also:
JmsListenerEndpoint
,MessageListenerContainer
,JmsListenerContainerFactory
Constructor Summary
Constructors Constructor Description JmsListenerEndpointRegistry()
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected MessageListenerContainer
createListenerContainer(JmsListenerEndpoint endpoint, JmsListenerContainerFactory<?> factory)
Create and start a new container using the specified factory.void
destroy()
Invoked by the containingBeanFactory
on destruction of a bean.MessageListenerContainer
getListenerContainer(String id)
Return theMessageListenerContainer
with the specified id ornull
if no such container exists.Set<String>
getListenerContainerIds()
Return the ids of the managedMessageListenerContainer
instance(s).Collection<MessageListenerContainer>
getListenerContainers()
Return the managedMessageListenerContainer
instance(s).int
getPhase()
Return the phase value of this object.boolean
isAutoStartup()
Returnstrue
if thisLifecycle
component should get started automatically by the container at the time that the containingApplicationContext
gets refreshed.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 givenJmsListenerEndpoint
.void
registerListenerContainer(JmsListenerEndpoint endpoint, JmsListenerContainerFactory<?> factory, boolean startImmediately)
Create a message listener container for the givenJmsListenerEndpoint
.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.
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 afterResourceLoaderAware.setResourceLoader(org.springframework.core.io.ResourceLoader)
,ApplicationEventPublisherAware.setApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher)
andMessageSourceAware
, if applicable.- Specified by:
setApplicationContext
in interfaceApplicationContextAware
- 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 interfaceApplicationListener<ContextRefreshedEvent>
- Parameters:
event
- the event to respond to
getListenerContainer
public MessageListenerContainer getListenerContainer(String id)
Return theMessageListenerContainer
with the specified id ornull
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 managedMessageListenerContainer
instance(s).- Since:
- 4.2.3
- See Also:
getListenerContainer(String)
getListenerContainers
public Collection<MessageListenerContainer> getListenerContainers()
Return the managedMessageListenerContainer
instance(s).
registerListenerContainer
public void registerListenerContainer(JmsListenerEndpoint endpoint, JmsListenerContainerFactory<?> factory, boolean startImmediately)
Create a message listener container for the givenJmsListenerEndpoint
.This create the necessary infrastructure to honor that endpoint with regards to its configuration.
The
startImmediately
flag determines if the container should be started immediately.- Parameters:
endpoint
- the endpoint to addfactory
- the listener factory to usestartImmediately
- 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 givenJmsListenerEndpoint
.This create the necessary infrastructure to honor that endpoint with regards to its configuration.
- Parameters:
endpoint
- the endpoint to addfactory
- 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.
isAutoStartup
public boolean isAutoStartup()
Description copied from interface: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.- Specified by:
isAutoStartup
in interfaceSmartLifecycle
- See Also:
Lifecycle.start()
,Phased.getPhase()
,LifecycleProcessor.onRefresh()
,ConfigurableApplicationContext.refresh()
getPhase
public int getPhase()
Description copied from interface:Phased
Return the phase value of this object.
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 interfaceLifecycle
- 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 implementingSmartLifecycle
and itsstop(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 interfaceLifecycle
- 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 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.- Specified by:
stop
in interfaceSmartLifecycle
- See Also:
Lifecycle.stop()
,Phased.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.
destroy
public void destroy()
Description copied from interface:DisposableBean
Invoked by the containingBeanFactory
on destruction of a bean.- Specified by:
destroy
in interfaceDisposableBean