public class JmsListenerEndpointRegistry extends Object implements DisposableBean, SmartLifecycle, ApplicationContextAware, ApplicationListener<ContextRefreshedEvent>
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 MessageListenerContainer
s 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.
JmsListenerEndpoint
,
MessageListenerContainer
,
JmsListenerContainerFactory
Constructor and Description |
---|
JmsListenerEndpointRegistry() |
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 value of this object.
|
boolean |
isAutoStartup()
Returns
true if this Lifecycle component should get
started automatically by the container at the time that the containing
ApplicationContext 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 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.
|
protected final Log logger
public void setApplicationContext(ApplicationContext applicationContext)
ApplicationContextAware
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.
setApplicationContext
in interface ApplicationContextAware
applicationContext
- the ApplicationContext object to be used by this objectBeanInitializationException
public void onApplicationEvent(ContextRefreshedEvent event)
ApplicationListener
onApplicationEvent
in interface ApplicationListener<ContextRefreshedEvent>
event
- the event to respond to@Nullable public MessageListenerContainer getListenerContainer(String id)
MessageListenerContainer
with the specified id or
null
if no such container exists.id
- the id of the containernull
if no container with that id existsJmsListenerEndpoint.getId()
,
getListenerContainerIds()
public Set<String> getListenerContainerIds()
MessageListenerContainer
instance(s).getListenerContainer(String)
public Collection<MessageListenerContainer> getListenerContainers()
MessageListenerContainer
instance(s).public void registerListenerContainer(JmsListenerEndpoint endpoint, JmsListenerContainerFactory<?> factory, boolean startImmediately)
JmsListenerEndpoint
.
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.
endpoint
- the endpoint to addfactory
- the listener factory to usestartImmediately
- start the container immediately if necessarygetListenerContainers()
,
getListenerContainer(String)
public void registerListenerContainer(JmsListenerEndpoint endpoint, JmsListenerContainerFactory<?> factory)
JmsListenerEndpoint
.
This create the necessary infrastructure to honor that endpoint with regards to its configuration.
endpoint
- the endpoint to addfactory
- the listener factory to useregisterListenerContainer(JmsListenerEndpoint, JmsListenerContainerFactory, boolean)
protected MessageListenerContainer createListenerContainer(JmsListenerEndpoint endpoint, JmsListenerContainerFactory<?> factory)
public boolean isAutoStartup()
SmartLifecycle
true
if this Lifecycle
component should get
started automatically by the container at the time that the containing
ApplicationContext
gets refreshed.
A value of false
indicates that the component is intended to
be started through an explicit Lifecycle.start()
call instead, analogous
to a plain Lifecycle
implementation.
isAutoStartup
in interface SmartLifecycle
Lifecycle.start()
,
Phased.getPhase()
,
LifecycleProcessor.onRefresh()
,
ConfigurableApplicationContext.refresh()
public int getPhase()
Phased
public void start()
Lifecycle
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.
start
in interface Lifecycle
SmartLifecycle.isAutoStartup()
public void stop()
Lifecycle
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.
stop
in interface Lifecycle
SmartLifecycle.stop(Runnable)
,
DisposableBean.destroy()
public void stop(Runnable callback)
SmartLifecycle
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.
stop
in interface SmartLifecycle
Lifecycle.stop()
,
Phased.getPhase()
public boolean isRunning()
Lifecycle
In the case of a container, this will return true
only if all
components that apply are currently running.
public void destroy()
DisposableBean
BeanFactory
on destruction of a bean.destroy
in interface DisposableBean