Prior to this commit, MBeans were registered in a post construct
call of MBeanExporter. This commit moves that logic after the
initialization phase using the SmartLifecycle callback.
Issue: SPR-8045
pull/556/merge
Marten Deinum12 years agocommitted byStephane Nicoll
@ -178,6 +180,14 @@ public class MBeanExporter extends MBeanRegistrationSupport
@@ -178,6 +180,14 @@ public class MBeanExporter extends MBeanRegistrationSupport
/** Stores the BeanFactory for use in autodetection process */
privateListableBeanFactorybeanFactory;
privatebooleanautoStartup=true;
privatevolatilebooleanrunning=false;
privateintphase=Integer.MAX_VALUE;
privatefinalObjectlifecycleMonitor=newObject();
/**
*Supplya{@codeMap}ofbeanstoberegisteredwiththeJMX
@ -412,17 +422,6 @@ public class MBeanExporter extends MBeanRegistrationSupport
@@ -412,17 +422,6 @@ public class MBeanExporter extends MBeanRegistrationSupport
if(this.server==null){
this.server=JmxUtils.locateMBeanServer();
}
try{
logger.info("Registering beans for JMX exposure on startup");
registerBeans();
registerNotificationListeners();
}
catch(RuntimeExceptionex){
// Unregister beans already registered by this exporter.
unregisterNotificationListeners();
unregisterBeans();
throwex;
}
}
/**
@ -1054,6 +1053,78 @@ public class MBeanExporter extends MBeanRegistrationSupport
@@ -1054,6 +1053,78 @@ public class MBeanExporter extends MBeanRegistrationSupport
@ -116,6 +117,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@@ -116,6 +117,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
fail("Must have thrown an MBeanExportException when registering a NotificationListener on a non-existent MBean.");
}
catch(MBeanExportExceptionexpected){
@ -129,6 +131,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@@ -129,6 +131,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
exporter.setBeans(getBeanMap());
exporter.setServer(server);
exporter.afterPropertiesSet();
exporter.start();
assertIsRegistered("The bean was not registered with the MBeanServer",
ObjectNameManager.getInstance(OBJECT_NAME));
}
@ -156,6 +159,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@@ -156,6 +159,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
assertEquals("The name attribute is incorrect","Rob Harrop",name);
@ -164,11 +168,12 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@@ -164,11 +168,12 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@ -176,17 +181,18 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@@ -176,17 +181,18 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@ -196,17 +202,18 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@@ -196,17 +202,18 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@ -218,18 +225,19 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@@ -218,18 +225,19 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
name=(String)server.getAttribute(oname,"Name");
assertEquals("Invalid name returned","Juergen Hoeller",name);
@ -243,6 +251,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@@ -243,6 +251,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@ -289,6 +298,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@@ -289,6 +298,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@ -318,6 +328,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@@ -318,6 +328,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@ -349,6 +360,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@@ -349,6 +360,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@ -374,6 +386,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@@ -374,6 +386,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
assertIsRegistered("Bean instance not registered",objectName);
@ -404,6 +417,8 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@@ -404,6 +417,8 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
// MBean has a bad ObjectName, so if said MBean is autodetected, an exception will be thrown...
exporter.afterPropertiesSet();
exporter.start();
}
@Test
@ -420,6 +435,8 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@@ -420,6 +435,8 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
assertIsRegistered("Bona fide MBean not autodetected in AUTODETECT_MBEAN mode",
ObjectNameManager.getInstance(OBJECT_NAME));
assertIsNotRegistered("Bean autodetected and (only) AUTODETECT_MBEAN mode is on",
@ -442,6 +459,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@@ -442,6 +459,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
assertIsRegistered("Bona fide MBean not autodetected in (AUTODETECT_ALL) mode",
ObjectNameManager.getInstance(OBJECT_NAME));
assertIsRegistered("Bean not autodetected in (AUTODETECT_ALL) mode",
@ -464,6 +482,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@@ -464,6 +482,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
assertIsNotRegistered("Bona fide MBean was autodetected in AUTODETECT_ASSEMBLER mode - must not have been",
ObjectNameManager.getInstance(OBJECT_NAME));
assertIsRegistered("Bean not autodetected in AUTODETECT_ASSEMBLER mode",
@ -488,6 +507,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@@ -488,6 +507,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
assertIsRegistered("Explicitly exported bona fide MBean obviously not exported.",
ObjectNameManager.getInstance(OBJECT_NAME));
}
@ -566,6 +586,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@@ -566,6 +586,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
beans.put(OBJECT_NAME,"beanName");
exporter.setBeans(beans);
exporter.afterPropertiesSet();
exporter.start();
fail("Expecting exception because MBeanExporter is not running in a BeanFactory and was passed bean name to (lookup and then) export");
}
catch(MBeanExportExceptionexpected){
@ -578,6 +599,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@@ -578,6 +599,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
fail("Expecting exception because MBeanExporter is not running in a BeanFactory and was configured to autodetect beans");
}
catch(MBeanExportExceptionexpected){
@ -595,6 +617,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@@ -595,6 +617,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
assertIsRegistered("The bean was not registered with the MBeanServer",
ObjectNameManager.getInstance(OBJECT_NAME));
@ -677,6 +700,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@@ -677,6 +700,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
try{
exporter.afterPropertiesSet();
exporter.start();
fail("Must have failed during creation of RuntimeExceptionThrowingConstructorBean");