Reorganized class structure to match our code style (setter for
properties at the top of the class, public method before private
implementation).
Removed DisposableBean as it the lifecycle is already taking care
of removing MBeans on stop.
Cleaned test suite
Issue: SPR-8045
@ -405,16 +405,31 @@ public class MBeanExporter extends MBeanRegistrationSupport
@@ -405,16 +405,31 @@ public class MBeanExporter extends MBeanRegistrationSupport
// If no server was provided then try to find one. This is useful in an environment
@ -424,15 +439,56 @@ public class MBeanExporter extends MBeanRegistrationSupport
@@ -424,15 +439,56 @@ public class MBeanExporter extends MBeanRegistrationSupport
logger.info("Unregistering JMX-exposed beans on shutdown");
unregisterNotificationListeners();
unregisterBeans();
publicvoidstart(){
logger.info("Registering beans for JMX exposure");
synchronized(this.lifecycleMonitor){
try{
registerBeans();
registerNotificationListeners();
}catch(RuntimeExceptionex){
// Unregister beans already registered by this exporter.
unregisterNotificationListeners();
unregisterBeans();
throwex;
}
}
running=true;
}
@Override
publicvoidstop(){
logger.info("Unregistering JMX-exposed beans on stop");
synchronized(this.lifecycleMonitor){
unregisterNotificationListeners();
unregisterBeans();
running=false;
}
}
@Override
publicvoidstop(Runnablecallback){
synchronized(this.lifecycleMonitor){
stop();
callback.run();
}
}
@Override
publicbooleanisRunning(){
synchronized(this.lifecycleMonitor){
returnthis.running;
}
}
@Override
publicbooleanisAutoStartup(){
returnthis.autoStartup;
}
@Override
publicintgetPhase(){
returnthis.phase;
}
@ -1053,79 +1109,6 @@ public class MBeanExporter extends MBeanRegistrationSupport
@@ -1053,79 +1109,6 @@ public class MBeanExporter extends MBeanRegistrationSupport
@ -67,7 +67,7 @@ public class MBeanClientInterceptorTests extends AbstractMBeanServerTests {
@@ -67,7 +67,7 @@ public class MBeanClientInterceptorTests extends AbstractMBeanServerTests {
@ -76,12 +85,9 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@@ -76,12 +85,9 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
// put a non-NotificationListener instance in as a value...
@ -91,12 +97,9 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@@ -91,12 +97,9 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@ -116,9 +119,9 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@@ -116,9 +119,9 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@ -130,22 +133,15 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@@ -130,22 +133,15 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
MBeanExporterexporter=newMBeanExporter();
exporter.setBeans(getBeanMap());
exporter.setServer(server);
exporter.afterPropertiesSet();
exporter.start();
assertIsRegistered("The bean was not registered with the MBeanServer",
@ -158,22 +154,24 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@@ -158,22 +154,24 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@ -181,39 +179,32 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@@ -181,39 +179,32 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@ -225,19 +216,41 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@@ -225,19 +216,41 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
name=(String)server.getAttribute(oname,"Name");
assertEquals("Invalid name returned","Juergen Hoeller",name);
fail("MBeans should not have been exported with autoStartup set to false");
}
catch(InstanceNotFoundExceptione){
// expected
}
// Export manually
exporter.start();
assertNotNull(server.getObjectInstance(on));// Should be exposed now.
}finally{
ctx.close();
}
}
@ -250,14 +263,14 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@@ -250,14 +263,14 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@ -297,8 +310,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@@ -297,8 +310,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@ -327,8 +339,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@@ -327,8 +339,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@ -359,8 +370,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@@ -359,8 +370,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@ -385,13 +395,12 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@@ -385,13 +395,12 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@ -416,8 +425,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@@ -416,8 +425,7 @@ 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();
start(exporter);
}
@ -434,8 +442,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@@ -434,8 +442,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
assertIsRegistered("Bona fide MBean not autodetected in AUTODETECT_MBEAN mode",
ObjectNameManager.getInstance(OBJECT_NAME));
@ -458,8 +465,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@@ -458,8 +465,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",
@ -481,8 +487,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@@ -481,8 +487,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",
@ -506,104 +511,69 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@@ -506,104 +511,69 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@ -616,13 +586,12 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@@ -616,13 +586,12 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
assertEquals("Listener should not have been invoked (MBean previously unregistered by external agent)",0,
listener.getUnregistered().size());
}
@ -649,7 +618,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@@ -649,7 +618,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@ -671,7 +640,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@@ -671,7 +640,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@ -699,8 +668,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@@ -699,8 +668,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
exporter.setBeanFactory(factory);
try{
exporter.afterPropertiesSet();
exporter.start();
start(exporter);
fail("Must have failed during creation of RuntimeExceptionThrowingConstructorBean");
}
catch(RuntimeExceptionexpected){
@ -712,6 +680,10 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@@ -712,6 +680,10 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@ -61,7 +61,7 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
@@ -61,7 +61,7 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
@ -87,7 +87,7 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
@@ -87,7 +87,7 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
@ -115,7 +115,7 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
@@ -115,7 +115,7 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
@ -143,7 +143,7 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
@@ -143,7 +143,7 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
@ -181,7 +181,7 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
@@ -181,7 +181,7 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
@ -227,7 +227,7 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
@@ -227,7 +227,7 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
@ -258,7 +258,7 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
@@ -258,7 +258,7 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
@ -290,7 +290,7 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
@@ -290,7 +290,7 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
@ -322,7 +322,7 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
@@ -322,7 +322,7 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
@ -362,7 +362,7 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
@@ -362,7 +362,7 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
assertIsRegistered("Should have registered MBean",objectName1);
assertIsRegistered("Should have registered MBean",objectName2);
@ -384,7 +384,7 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
@@ -384,7 +384,7 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
@ -420,7 +420,7 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
@@ -420,7 +420,7 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
@ -175,7 +175,7 @@ public abstract class AbstractMetadataAssemblerTests extends AbstractJmxAssemble
@@ -175,7 +175,7 @@ public abstract class AbstractMetadataAssemblerTests extends AbstractJmxAssemble
@ -41809,6 +41809,13 @@ With this configuration the `testBean` bean is exposed as an MBean under the
@@ -41809,6 +41809,13 @@ With this configuration the `testBean` bean is exposed as an MBean under the
are exposed as attributes and all __public__ methods (bar those inherited from the
`Object` class) are exposed as operations.
[NOTE]
====
`MBeanExporter` is a `Lifecycle` bean (see <<beans-factory-lifecycle-processor>>)
and MBeans are exported as late as possible during the application lifecycle by default. It
is possible to configure the `phase` at which the export happens or disable automatic