updateDomain(registrator, cache.getComponentRegistry().getGlobalComponentRegistry(), mBeanServer);
return registrator;
}
protected void updateDomain(ComponentsJmxRegistration registrator, GlobalComponentRegistry componentRegistry, MBeanServer mBeanServer) {
GlobalConfiguration gc = componentRegistry.getComponent(GlobalConfiguration.class);
CacheManagerJmxRegistration managerJmxReg = componentRegistry.getComponent(CacheManagerJmxRegistration.class);
if (!gc.isExposeGlobalJmxStatistics() && jmxDomain == null) {
String tmpJmxDomain = getJmxDomain(gc.getJmxDomain(), mBeanServer);
synchronized (managerJmxReg) {
if (managerJmxReg.jmxDomain == null) {
if (!tmpJmxDomain.equals(gc.getJmxDomain()) && !gc.isAllowDuplicateDomains()) {
String message = "There's already an cache manager instance registered under '" + gc.getJmxDomain() +
"' JMX domain. If you want to allow multiple instances configured with same JMX domain enable " +
"'allowDuplicateDomains' attribute in 'globalJmxStatistics' config element";
if (log.isErrorEnabled()) log.error(message);
throw new JmxDomainConflictException(message);
}
// Set manager component's jmx domain so that other caches under same manager
// can see it, particularly important when jmx is only enabled at the cache level
managerJmxReg.jmxDomain = tmpJmxDomain;
}
// So that all caches share the same domain, regardless of whether dups are
// allowed or not, simply assign the manager's calculated jmxDomain
jmxDomain = managerJmxReg.jmxDomain;
}
} else {
// If global stats were enabled, manager's jmxDomain would have been populated
// when cache manager was started, so no need for synchronization here.
jmxDomain = managerJmxReg.jmxDomain == null ? gc.getJmxDomain() : managerJmxReg.jmxDomain;
}
registrator.setJmxDomain(jmxDomain);
}