@ -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
@ -395,16 +405,31 @@ public class MBeanExporter extends MBeanRegistrationSupport
@@ -395,16 +405,31 @@ public class MBeanExporter extends MBeanRegistrationSupport
// If no server was provided then try to find one. This is useful in an environment
@ -412,28 +437,58 @@ public class MBeanExporter extends MBeanRegistrationSupport
@@ -412,28 +437,58 @@ 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();
}
@Override
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;
}
}
catch(RuntimeExceptionex){
// Unregister beans already registered by this exporter.
running=true;
}
@Override
publicvoidstop(){
logger.info("Unregistering JMX-exposed beans on stop");
logger.info("Unregistering JMX-exposed beans on shutdown");
unregisterNotificationListeners();
unregisterBeans();
publicbooleanisRunning(){
synchronized(this.lifecycleMonitor){
returnthis.running;
}
}
@Override
publicbooleanisAutoStartup(){
returnthis.autoStartup;
}
@Override
publicintgetPhase(){
returnthis.phase;
}
@ -1054,7 +1109,6 @@ public class MBeanExporter extends MBeanRegistrationSupport
@@ -1054,7 +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 {
@ -75,12 +85,9 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@@ -75,12 +85,9 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
// put a non-NotificationListener instance in as a value...
@ -90,12 +97,9 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@@ -90,12 +97,9 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@ -115,8 +119,9 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@@ -115,8 +119,9 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@ -128,21 +133,15 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@@ -128,21 +133,15 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
MBeanExporterexporter=newMBeanExporter();
exporter.setBeans(getBeanMap());
exporter.setServer(server);
exporter.afterPropertiesSet();
assertIsRegistered("The bean was not registered with the MBeanServer",
@ -155,20 +154,24 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@@ -155,20 +154,24 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@ -176,37 +179,32 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@@ -176,37 +179,32 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@ -218,18 +216,41 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@@ -218,18 +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();
}
}
@ -242,13 +263,14 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@@ -242,13 +263,14 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@ -288,7 +310,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@@ -288,7 +310,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@ -317,7 +339,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@@ -317,7 +339,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@ -348,7 +370,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@@ -348,7 +370,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@ -373,12 +395,12 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@@ -373,12 +395,12 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@ -403,7 +425,8 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@@ -403,7 +425,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();
start(exporter);
}
@Test
@ -419,7 +442,8 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@@ -419,7 +442,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",
@ -441,7 +465,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@@ -441,7 +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",
@ -463,7 +487,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@@ -463,7 +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",
@ -487,101 +511,69 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@@ -487,101 +511,69 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@ -594,12 +586,12 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@@ -594,12 +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());
}
@ -626,7 +618,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@@ -626,7 +618,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@ -648,7 +640,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@@ -648,7 +640,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@ -676,7 +668,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@@ -676,7 +668,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
exporter.setBeanFactory(factory);
try{
exporter.afterPropertiesSet();
start(exporter);
fail("Must have failed during creation of RuntimeExceptionThrowingConstructorBean");
}
catch(RuntimeExceptionexpected){
@ -688,6 +680,10 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
@@ -688,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