INT-1675: force initialization of other MBeanExporter instances before the integration monitor components are created

This commit is contained in:
Dave Syer
2010-12-10 12:20:05 +01:00
parent c293edc7fa
commit e23e478e9e
6 changed files with 117 additions and 46 deletions

View File

@@ -31,7 +31,11 @@ import org.w3c.dom.Element;
*/
public class MBeanExporterParser extends AbstractSingleBeanDefinitionParser {
private static final String ILLEGAL_NAME = "mbeanExporter";
/**
*
*/
private static final String MBEAN_EXPORTER_NAME = "mbeanExporter";
private static final String ILLEGAL_NAME = MBEAN_EXPORTER_NAME;
@Override
protected boolean shouldGenerateIdAsFallback() {

View File

@@ -83,14 +83,13 @@ import org.springframework.util.ReflectionUtils;
* @author Oleg Zhurakousky
*/
@ManagedResource
public class IntegrationMBeanExporter extends MBeanExporter
implements BeanPostProcessor, BeanFactoryAware, BeanClassLoaderAware, SmartLifecycle {
public class IntegrationMBeanExporter extends MBeanExporter implements BeanPostProcessor, BeanFactoryAware,
BeanClassLoaderAware, SmartLifecycle {
private static final Log logger = LogFactory.getLog(IntegrationMBeanExporter.class);
public static final String DEFAULT_DOMAIN = "org.springframework.integration";
private final AnnotationJmxAttributeSource attributeSource = new AnnotationJmxAttributeSource();
private ListableBeanFactory beanFactory;
@@ -125,7 +124,6 @@ public class IntegrationMBeanExporter extends MBeanExporter
private final Map<String, String> objectNameStaticProperties = new HashMap<String, String>();
public IntegrationMBeanExporter() {
super();
// Shouldn't be necessary, but to be on the safe side...
@@ -134,7 +132,6 @@ public class IntegrationMBeanExporter extends MBeanExporter
setAssembler(new MetadataMBeanInfoAssembler(attributeSource));
}
@Override
public void setBeanClassLoader(ClassLoader classLoader) {
this.beanClassLoader = classLoader;
@@ -183,8 +180,7 @@ public class IntegrationMBeanExporter extends MBeanExporter
Object advised = applyHandlerInterceptor(bean, monitor, beanClassLoader);
handlers.add(monitor);
return advised;
}
else if (bean instanceof MessageSource<?>) {
} else if (bean instanceof MessageSource<?>) {
SimpleMessageSourceMetrics monitor = new SimpleMessageSourceMetrics((MessageSource<?>) bean);
Object advised = applySourceInterceptor(bean, monitor, beanClassLoader);
sources.add(monitor);
@@ -197,12 +193,10 @@ public class IntegrationMBeanExporter extends MBeanExporter
Object target = extractTarget(bean);
if (target instanceof QueueChannel) {
monitor = new QueueChannelMetrics((QueueChannel) target, beanName);
}
else {
} else {
monitor = new PollableChannelMetrics(beanName);
}
}
else {
} else {
monitor = new DirectChannelMetrics(beanName);
}
Object advised = applyChannelInterceptor(bean, monitor, beanClassLoader);
@@ -233,8 +227,7 @@ public class IntegrationMBeanExporter extends MBeanExporter
this.lifecycleLock.lock();
try {
return this.running;
}
finally {
} finally {
this.lifecycleLock.unlock();
}
}
@@ -249,8 +242,7 @@ public class IntegrationMBeanExporter extends MBeanExporter
logger.info("started " + this);
}
}
}
finally {
} finally {
this.lifecycleLock.unlock();
}
}
@@ -265,8 +257,7 @@ public class IntegrationMBeanExporter extends MBeanExporter
logger.info("stopped " + this);
}
}
}
finally {
} finally {
this.lifecycleLock.unlock();
}
}
@@ -276,8 +267,7 @@ public class IntegrationMBeanExporter extends MBeanExporter
try {
this.stop();
callback.run();
}
finally {
} finally {
this.lifecycleLock.unlock();
}
}
@@ -295,6 +285,16 @@ public class IntegrationMBeanExporter extends MBeanExporter
registerSources();
}
@Override
public void afterPropertiesSet() {
super.afterPropertiesSet();
/*
* Force early initialization of other MBeanExporters. Workaround for possible bug in Spring (see INT-1675) for
* more details.
*/
beanFactory.getBeansOfType(MBeanExporter.class);
}
@Override
public void destroy() {
super.destroy();
@@ -457,8 +457,7 @@ public class IntegrationMBeanExporter extends MBeanExporter
}
try {
return extractTarget(advised.getTargetSource().getTarget());
}
catch (Exception e) {
} catch (Exception e) {
logger.error("Could not extract target", e);
return null;
}
@@ -470,8 +469,7 @@ public class IntegrationMBeanExporter extends MBeanExporter
if (bean instanceof Advised) {
((Advised) bean).addAdvisor(advisor);
return bean;
}
else {
} else {
ProxyFactory proxyFactory = new ProxyFactory(bean);
proxyFactory.addAdvisor(advisor);
return proxyFactory.getProxy(beanClassLoader);
@@ -531,8 +529,7 @@ public class IntegrationMBeanExporter extends MBeanExporter
Object field = null;
try {
field = extractTarget(getField(endpoint, "handler"));
}
catch (Exception e) {
} catch (Exception e) {
logger.trace("Could not get handler from bean = " + beanName);
}
if (field == monitor.getMessageHandler()) {
@@ -551,8 +548,7 @@ public class IntegrationMBeanExporter extends MBeanExporter
if (targetSource != null) {
try {
target = targetSource.getTarget();
}
catch (Exception e) {
} catch (Exception e) {
logger.debug("Could not get handler from bean = " + name);
}
}