Class JmsListenerEndpointRegistry
- All Implemented Interfaces:
EventListener
,Aware
,DisposableBean
,ApplicationContextAware
,ApplicationListener<ContextRefreshedEvent>
,Lifecycle
,Phased
,SmartLifecycle
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:
-
Field Summary
Fields inherited from interface org.springframework.context.SmartLifecycle
DEFAULT_PHASE
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected 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.Return theMessageListenerContainer
with the specified id ornull
if no such container exists.Return the ids of the managedMessageListenerContainer
instance(s).Return the managedMessageListenerContainer
instance(s).int
getPhase()
Return the phase that this lifecycle object is supposed to run in.boolean
Check whether this component is currently running.void
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
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.ApplicationListener
supportsAsyncExecution
Methods inherited from interface org.springframework.context.SmartLifecycle
isAutoStartup
-
Field Details
-
logger
-
-
Constructor Details
-
JmsListenerEndpointRegistry
public JmsListenerEndpointRegistry()
-
-
Method Details
-
setApplicationContext
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:
-
onApplicationEvent
Description copied from interface:ApplicationListener
Handle an application event.- Specified by:
onApplicationEvent
in interfaceApplicationListener<ContextRefreshedEvent>
- Parameters:
event
- the event to respond to
-
getListenerContainer
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:
-
getListenerContainerIds
Return the ids of the managedMessageListenerContainer
instance(s).- Since:
- 4.2.3
- See Also:
-
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 regard 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:
-
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 regard to its configuration.
- Parameters:
endpoint
- the endpoint to addfactory
- the listener factory to use- See Also:
-
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 letstop()
callbacks execute before regularLifecycle
implementations.- Specified by:
getPhase
in interfacePhased
- Specified by:
getPhase
in interfaceSmartLifecycle
- See Also:
-
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.
-
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.
-
stop
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.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 interfaceSmartLifecycle
- See Also:
-
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
-