diff --git a/spring-integration-jmx/src/main/java/org/springframework/integration/monitor/IntegrationMBeanExporter.java b/spring-integration-jmx/src/main/java/org/springframework/integration/monitor/IntegrationMBeanExporter.java index 91c86aac06..c273666272 100644 --- a/spring-integration-jmx/src/main/java/org/springframework/integration/monitor/IntegrationMBeanExporter.java +++ b/spring-integration-jmx/src/main/java/org/springframework/integration/monitor/IntegrationMBeanExporter.java @@ -1,11 +1,11 @@ /* * Copyright 2002-2012 the original author or authors. - * + * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. @@ -37,6 +37,7 @@ import javax.management.modelmbean.ModelMBean; import org.aopalliance.aop.Advice; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; + import org.springframework.aop.Advisor; import org.springframework.aop.PointcutAdvisor; import org.springframework.aop.TargetSource; @@ -46,7 +47,6 @@ import org.springframework.aop.support.AopUtils; import org.springframework.aop.support.NameMatchMethodPointcutAdvisor; import org.springframework.beans.BeansException; import org.springframework.beans.factory.BeanClassLoaderAware; -import org.springframework.beans.factory.BeanCreationException; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactoryAware; import org.springframework.beans.factory.ListableBeanFactory; @@ -100,7 +100,7 @@ import org.springframework.util.ReflectionUtils; * handlers. It doesn't register itself to avoid conflicts with the standard <context:mbean-export/> * from Spring (which should therefore be used any time you need to expose those features). *

- * + * * @author Dave Syer * @author Helena Edelson * @author Oleg Zhurakousky @@ -120,31 +120,31 @@ public class IntegrationMBeanExporter extends MBeanExporter implements BeanPostP private ApplicationContext applicationContext; - private Map anonymousHandlerCounters = new HashMap(); + private final Map anonymousHandlerCounters = new HashMap(); - private Map anonymousSourceCounters = new HashMap(); + private final Map anonymousSourceCounters = new HashMap(); - private Set handlers = new HashSet(); + private final Set handlers = new HashSet(); - private Set sources = new HashSet(); + private final Set sources = new HashSet(); - private Set channels = new HashSet(); + private final Set channels = new HashSet(); - private Map exposedBeans = new HashMap(); + private final Map exposedBeans = new HashMap(); - private Map channelsByName = new HashMap(); + private final Map channelsByName = new HashMap(); - private Map handlersByName = new HashMap(); + private final Map handlersByName = new HashMap(); - private Map sourcesByName = new HashMap(); + private final Map sourcesByName = new HashMap(); - private Map allChannelsByName = new HashMap(); + private final Map allChannelsByName = new HashMap(); - private Map allHandlersByName = new HashMap(); + private final Map allHandlersByName = new HashMap(); - private Map allSourcesByName = new HashMap(); + private final Map allSourcesByName = new HashMap(); - private Map beansByEndpointName = new HashMap(); + private final Map beansByEndpointName = new HashMap(); private ClassLoader beanClassLoader; @@ -158,8 +158,6 @@ public class IntegrationMBeanExporter extends MBeanExporter implements BeanPostP private String domain = DEFAULT_DOMAIN; - private boolean initialized = false; - private final Properties objectNameStaticProperties = new Properties(); private final MetadataMBeanInfoAssembler assembler = new MetadataMBeanInfoAssembler(attributeSource); @@ -192,7 +190,7 @@ public class IntegrationMBeanExporter extends MBeanExporter implements BeanPostP /** * Static properties that will be added to all object names. - * + * * @param objectNameStaticProperties the objectNameStaticProperties to set */ public void setObjectNameStaticProperties(Map objectNameStaticProperties) { @@ -202,7 +200,7 @@ public class IntegrationMBeanExporter extends MBeanExporter implements BeanPostP /** * The JMX domain to use for MBeans registered. Defaults to spring.application (which is useful in * SpringSource HQ). - * + * * @param domain the domain name to set */ public void setDefaultDomain(String domain) { @@ -215,6 +213,7 @@ public class IntegrationMBeanExporter extends MBeanExporter implements BeanPostP this.componentNamePatterns = componentNamePatterns; } + @Override public void setBeanFactory(BeanFactory beanFactory) throws BeansException { super.setBeanFactory(beanFactory); Assert.isTrue(beanFactory instanceof ListableBeanFactory, "A ListableBeanFactory is required."); @@ -245,13 +244,10 @@ public class IntegrationMBeanExporter extends MBeanExporter implements BeanPostP } } - boolean foundMetrics = false; - if (bean instanceof MessageHandler) { SimpleMessageHandlerMetrics monitor = new SimpleMessageHandlerMetrics((MessageHandler) bean); Object advised = applyHandlerInterceptor(bean, monitor, beanClassLoader); handlers.add(monitor); - foundMetrics = true; bean = advised; } @@ -259,7 +255,6 @@ public class IntegrationMBeanExporter extends MBeanExporter implements BeanPostP SimpleMessageSourceMetrics monitor = new SimpleMessageSourceMetrics((MessageSource) bean); Object advised = applySourceInterceptor(bean, monitor, beanClassLoader); sources.add(monitor); - foundMetrics = true; bean = advised; } @@ -279,27 +274,9 @@ public class IntegrationMBeanExporter extends MBeanExporter implements BeanPostP } Object advised = applyChannelInterceptor(bean, monitor, beanClassLoader); channels.add(monitor); - foundMetrics = true; bean = advised; } - if (foundMetrics) { - // Only force the other exporters to initialize if we are sure we need to... - if (!initialized) { - try { - collectMBeanExporters(); - initialized = true; - } - catch (BeanCreationException e) { - // Ignore - if (logger.isDebugEnabled()) { - logger.debug("Ignoring BeanCreationException while instantiating MBeanExporter during creation of metrics for beanName=[" - + beanName + "]"); - } - } - } - } - return bean; } @@ -307,7 +284,7 @@ public class IntegrationMBeanExporter extends MBeanExporter implements BeanPostP /** * Copy of private method in super class. Needed so we can avoid using the bean factory to extract the bean again, * and risk it being a proxy (which it almost certainly is by now). - * + * * @param bean the bean instance to register * @param beanKey the bean name or human readable version if autogenerated * @return the JMX object name of the MBean that was registered @@ -428,17 +405,6 @@ public class IntegrationMBeanExporter extends MBeanExporter implements BeanPostP registerEndpoints(); } - /** - * Force early initialization of other MBean exporters to ensure that they don't try to register the same beans that - * this exporter is covering. - */ - private void collectMBeanExporters() { - String[] beanNames = beanFactory.getBeanNamesForType(MBeanExporter.class, false, false); - for (String beanName : beanNames) { - beanFactory.getBean(beanName, MBeanExporter.class); - } - } - @Override public void destroy() { super.destroy();