1 10 package org.mule.management.support; 11 12 import org.mule.MuleManager; 13 import org.mule.util.StringUtils; 14 15 import javax.management.MBeanServer ; 16 import javax.management.MBeanServerFactory ; 17 import java.util.Arrays ; 18 import java.util.List ; 19 20 public abstract class AbstractJmxSupport implements JmxSupport 21 { 22 23 33 protected String resolveDomainClash(String domain) 34 { 35 List servers = MBeanServerFactory.findMBeanServer(null); 36 if (servers.isEmpty()) 37 { 38 throw new IllegalStateException ("MBeanServer is not available."); 39 } 40 MBeanServer server = (MBeanServer ) servers.get(0); 41 List registeredDomains = Arrays.asList(server.getDomains()); 42 int counter = 1; 43 if (registeredDomains.contains(domain)) 45 { 46 domain += "." + counter; 47 } 48 while (registeredDomains.contains(domain)) 50 { 51 domain = domain.substring(0, domain.lastIndexOf(".") + 1) + ++counter; 53 } 54 55 return domain; 56 } 57 58 59 public String getDomainName() 60 { 61 String domain = DEFAULT_JMX_DOMAIN_PREFIX; 63 String instanceId = StringUtils.defaultIfEmpty(MuleManager.getInstance().getId(), StringUtils.EMPTY); 64 if (instanceId.length() > 0) 65 { 66 domain += "." + instanceId; 67 } 68 69 JmxRegistrationContext ctx = JmxRegistrationContext.getCurrent(); 70 71 String resolvedDomain = ctx.getResolvedDomain(); 72 if (StringUtils.isBlank(resolvedDomain)) 73 { 74 domain = resolveDomainClash(domain); 75 ctx.setResolvedDomain(domain); 76 } 77 78 return domain; 79 } 80 } 81 | Popular Tags |