INT-3286: Add @EnableMessageHistory

JIRA: https://jira.springsource.org/browse/INT-3286

Introduce `@EnableMessageHistory` and `MessageHistoryRegistrar`.
Refactoring for `MessageHistoryParser` to use `MessageHistoryRegistrar` to follow with DRY
Add test for `@EnableMessageHistory`

INT-3286: Polishing

INT-3286: Enable several MHs with the same value

Previously the Framework allowed only one `<message-history>`
independent of their `tracked-components`.
With introduction of `@EnableMessageHistory` and `MessageHistoryRegistrar`
the `MessageHistoryConfigurer` is improved to allow
several `<message-history>` or `@EnableMessageHistory`
with the same set of `componentNamePatterns`.

INT-3286 Polishing + JMX + Docs

* Allows setComponentNamePatterns and/or setComponentNamePatternsSet to
  be used as long as the settings are consistent.
* Handle the case where the `MHC` was configured as a bean (no managed set exists)
* Add support for changing the component name patterns over JMX + test case
* Docs

INT-3286 More Polishing

* Change bean name to `messageHistoryConfigurer`
* Move constant to `ICU`
* Export the MBean by the `IMBE`
This commit is contained in:
Artem Bilan
2014-02-05 17:29:58 +02:00
committed by Gary Russell
parent d8e4818c5e
commit 2fd27e3a6c
16 changed files with 415 additions and 60 deletions

View File

@@ -57,14 +57,12 @@ import org.springframework.context.ApplicationContextAware;
import org.springframework.context.Lifecycle;
import org.springframework.context.SmartLifecycle;
import org.springframework.core.task.support.ExecutorServiceAdapter;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.MessagingException;
import org.springframework.integration.channel.QueueChannel;
import org.springframework.integration.context.IntegrationContextUtils;
import org.springframework.integration.context.OrderlyShutdownCapable;
import org.springframework.messaging.MessageHandler;
import org.springframework.integration.core.MessageSource;
import org.springframework.messaging.PollableChannel;
import org.springframework.integration.endpoint.AbstractEndpoint;
import org.springframework.integration.history.MessageHistoryConfigurer;
import org.springframework.integration.support.context.NamedComponent;
import org.springframework.jmx.export.MBeanExporter;
import org.springframework.jmx.export.UnableToRegisterMBeanException;
@@ -76,6 +74,10 @@ import org.springframework.jmx.export.annotation.ManagedResource;
import org.springframework.jmx.export.assembler.MetadataMBeanInfoAssembler;
import org.springframework.jmx.export.naming.MetadataNamingStrategy;
import org.springframework.jmx.support.MetricType;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.MessageHandler;
import org.springframework.messaging.MessagingException;
import org.springframework.messaging.PollableChannel;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.util.Assert;
@@ -179,6 +181,8 @@ public class IntegrationMBeanExporter extends MBeanExporter implements BeanPostP
private final AtomicBoolean shuttingDown = new AtomicBoolean();
private MessageHistoryConfigurer messageHistoryConfigurer;
public IntegrationMBeanExporter() {
super();
// Shouldn't be necessary, but to be on the safe side...
@@ -225,6 +229,7 @@ public class IntegrationMBeanExporter extends MBeanExporter implements BeanPostP
this.beanFactory = (ListableBeanFactory) beanFactory;
}
@Override
public void setApplicationContext(ApplicationContext applicationContext)
throws BeansException {
Assert.notNull(applicationContext, "ApplicationContext may not be null");
@@ -236,6 +241,7 @@ public class IntegrationMBeanExporter extends MBeanExporter implements BeanPostP
this.shutdownExecutor = shutdownExecutor;
}
@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
if (bean instanceof Advised) {
@@ -249,6 +255,12 @@ public class IntegrationMBeanExporter extends MBeanExporter implements BeanPostP
}
}
if (IntegrationContextUtils.INTEGRATION_MESSAGE_HISTORY_CONFIGURER.equals(beanName)
&& bean instanceof MessageHistoryConfigurer) {
this.messageHistoryConfigurer = (MessageHistoryConfigurer) bean;
return bean;
}
if (bean instanceof MessageHandler) {
if (this.handlerInAnonymousWrapper(bean) != null) {
if (logger.isDebugEnabled()) {
@@ -364,18 +376,22 @@ public class IntegrationMBeanExporter extends MBeanExporter implements BeanPostP
}
}
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
return bean;
}
@Override
public final boolean isAutoStartup() {
return this.autoStartup;
}
@Override
public final int getPhase() {
return this.phase;
}
@Override
public final boolean isRunning() {
this.lifecycleLock.lock();
try {
@@ -386,6 +402,7 @@ public class IntegrationMBeanExporter extends MBeanExporter implements BeanPostP
}
}
@Override
public final void start() {
this.lifecycleLock.lock();
try {
@@ -402,6 +419,7 @@ public class IntegrationMBeanExporter extends MBeanExporter implements BeanPostP
}
}
@Override
public final void stop() {
this.lifecycleLock.lock();
try {
@@ -418,6 +436,7 @@ public class IntegrationMBeanExporter extends MBeanExporter implements BeanPostP
}
}
@Override
public final void stop(Runnable callback) {
this.lifecycleLock.lock();
try {
@@ -441,6 +460,10 @@ public class IntegrationMBeanExporter extends MBeanExporter implements BeanPostP
registerHandlers();
registerSources();
registerEndpoints();
if (this.messageHistoryConfigurer != null) {
this.registerBeanInstance(this.messageHistoryConfigurer,
IntegrationContextUtils.INTEGRATION_MESSAGE_HISTORY_CONFIGURER);
}
}
@Override
@@ -499,6 +522,7 @@ public class IntegrationMBeanExporter extends MBeanExporter implements BeanPostP
* Perform orderly shutdown - called or executed from
* {@link #stopActiveComponents(boolean, long)}.
*/
@Override
public void run() {
try {
this.orderlyShutdownCapableComponentsBefore();