public class JmsListenerEndpointRegistry extends java.lang.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 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.
JmsListenerEndpoint
,
MessageListenerContainer
,
JmsListenerContainerFactory
Modifier and Type | Field and Description |
---|---|
protected Log |
logger |
DEFAULT_PHASE
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(java.lang.String id)
Return the
MessageListenerContainer with the specified id or
null if no such container exists. |
java.util.Set<java.lang.String> |
getListenerContainerIds()
Return the ids of the managed
MessageListenerContainer instance(s). |
java.util.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(java.lang.Runnable callback)
Indicates that a Lifecycle component must stop if it is currently running.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
isAutoStartup
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(java.lang.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 java.util.Set<java.lang.String> getListenerContainerIds()
MessageListenerContainer
instance(s).getListenerContainer(String)
public java.util.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 int getPhase()
SmartLifecycle
The default implementation returns SmartLifecycle.DEFAULT_PHASE
in order to
let stop callbacks execute after regular Lifecycle
implementations.
getPhase
in interface Phased
getPhase
in interface SmartLifecycle
SmartLifecycle.isAutoStartup()
,
Lifecycle.start()
,
SmartLifecycle.stop(Runnable)
,
DefaultLifecycleProcessor.getPhase(Lifecycle)
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(java.lang.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.
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).
stop
in interface SmartLifecycle
Lifecycle.stop()
,
SmartLifecycle.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