INT-1806: fix duplicate MBeans

This commit is contained in:
Dave Syer
2011-05-04 17:54:58 +01:00
parent 52c0ceaf4c
commit 225f4a3b84
3 changed files with 64 additions and 0 deletions

View File

@@ -570,6 +570,7 @@ public class IntegrationMBeanExporter extends MBeanExporter implements BeanPostP
private void registerEndpoints() {
String[] names = beanFactory.getBeanNamesForType(AbstractEndpoint.class);
Set<String> endpointNames = new HashSet<String>();
for (String name : names) {
if (!beansByEndpointName.values().contains(name)) {
AbstractEndpoint endpoint = beanFactory.getBean(name, AbstractEndpoint.class);
@@ -587,6 +588,15 @@ public class IntegrationMBeanExporter extends MBeanExporter implements BeanPostP
if (!PatternMatchUtils.simpleMatch(this.componentNamePatterns, name)) {
continue;
}
if (endpointNames.contains(name)) {
int count = 0;
String unique = name+"#"+count;
while (endpointNames.contains(unique)) {
unique = name + "#" + (++count);
}
name = unique;
}
endpointNames.add(name);
beanKey = getEndpointBeanKey(endpoint, name, source);
ObjectName objectName = registerBeanInstance(new ManagedEndpoint(endpoint), beanKey);
logger.info("Registered endpoint without MessageSource: " + objectName);