@Role(value=2) @Component public class MatsSpringAnnotationRegistration extends java.lang.Object implements org.springframework.beans.factory.config.BeanPostProcessor, org.springframework.context.ApplicationContextAware
BeanPostProcessor-class specified by the
@EnableMatsannotation. It checks all Spring beans in the current Spring
ApplicationContextfor whether their classes are annotated with
@MatsClassMapping, or if they have methods annotated with
@MatsEndpointSetup, and if so configures Mats endpoints for them on the (possibly specified)
MatsFactory. It will also control any registered
MatsFactory.holdEndpointsUntilFactoryIsStarted()early in the startup procedure before adding the endpoints, and then
MatsFactory.start()as late as possible in the startup procedure. Upon Spring context shutdown, it invokes
MatsFactory.stop(..)as early as possible in the shutdown procedure.
MatsSpringAnnotationRegistration(which is a
BeanPostProcessor) will have each bean in the Spring ApplicationContext presented:
MatsFactorybean will have their
MatsFactory.start()method invoked, which will "release" the configured Mats endpoints, so that they will start (which in turn fires up their "stage processor" threads, which will each go and get a connection to the underlying MQ (which probably is JMS-based) and start to listen for messages).
ContextRefreshedEvent is invoked late in the Spring ApplicationContext startup procedure. This means
that all beans have been fully injected, and any
@PostConstruct and lifecycle events have been run. Thus, if
the Endpoint depends on any bean/service, it is now running. This is important as the Endpoint's Stage Processors
will start picking messages of the queue pretty much immediately. And this is important again if you have any cache
that takes time to be populated - it might be of interest to instead use programmatic registration and implement
delayed start for Endpoints which depends on caches that take a substantial time to load.
Notice: All MatsFactories found in the Spring ApplicationContext are started, regardless of whether they had
any Mats endpoints registered using the Mats SpringConfig. This implies that if you register any Mats endpoints
programmatically using e.g.
@PostConstruct or similar functionality, these will also be started - unless
they have not had their
MatsEndpoint.finishSetup() method invoked, ref. "delayed start" mentioned above.
ContextClosedEvent, all MatsFactories in the ApplicationContext will have their
stopped, which releases the connection to the underlying MQ and stops the stage processor threads.
ContextClosedEvent is fired rather early in the Spring ApplicationContext shutdown procedure. When
running in integration testing mode, which typically will involve starting an in-vm ActiveMQ in the same JVM as the
endpoints, this early stopping and releasing of connections is beneficial so that when the in-vm ActiveMQ is stopped
somewhat later, one won't get a load of connection failures from the Mats endpoints which otherwise would have their
connections shut down under their feet.
|Modifier and Type||Class and Description|
Thrown if the setup of a Mats Spring endpoint fails.
Thrown if the invocation of a
|Constructor and Description|
|Modifier and Type||Method and Description|
public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext) throws org.springframework.beans.BeansException
public java.lang.Object postProcessBeforeInitialization(java.lang.Object bean, java.lang.String beanName) throws org.springframework.beans.BeansException
public java.lang.Object postProcessAfterInitialization(java.lang.Object bean, java.lang.String beanName) throws org.springframework.beans.BeansException
@EventListener public void onContextRefreshedEvent(org.springframework.context.event.ContextRefreshedEvent e)
ContextRefreshedEventruns pretty much as the latest step in the Spring life cycle starting process: Processes all
MatsEndpointSetupannotations, then starts the MatsFactory, which will start any "hanging" MATS Endpoints, which will then start consuming messages.
@EventListener public void onContextClosedEvent(org.springframework.context.event.ContextClosedEvent e)
ContextClosedEventruns pretty much as the first step in the Spring life cycle stopping process: Stop the MatsFactory, which will stop all MATS Endpoints, which will have them release their JMS resources - and then the MatsFactory will clean out the JmsMatsJmsSessionHandler.