Author: thomas.diesler(a)jboss.com
Date: 2010-03-18 17:42:45 -0400 (Thu, 18 Mar 2010)
New Revision: 102593
Modified:
projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-bundle/src/main/java/org/jboss/osgi/jmx/JMXCapability.java
projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-bundle/src/main/java/org/jboss/osgi/jmx/internal/MBeanServerService.java
Log:
Add more logging
Modified:
projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-bundle/src/main/java/org/jboss/osgi/jmx/JMXCapability.java
===================================================================
---
projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-bundle/src/main/java/org/jboss/osgi/jmx/JMXCapability.java 2010-03-18
21:18:15 UTC (rev 102592)
+++
projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-bundle/src/main/java/org/jboss/osgi/jmx/JMXCapability.java 2010-03-18
21:42:45 UTC (rev 102593)
@@ -58,16 +58,16 @@
{
// Provide logging
private static final Logger log = Logger.getLogger(JMXCapability.class);
-
+
public JMXCapability()
{
super(MBeanServer.class.getName());
-
+
addSystemProperty("org.jboss.osgi.jmx.host",
System.getProperty("jboss.bind.address", "localhost"));
addSystemProperty("org.jboss.osgi.jmx.rmi.port", "1198");
-
+
addDependency(new CompendiumCapability());
-
+
addBundle("bundles/jboss-osgi-jmx.jar");
addBundle("bundles/org.apache.aries.jmx.jar");
}
@@ -75,6 +75,10 @@
@Override
public void start(OSGiRuntime runtime) throws BundleException
{
+ // Explicitly create the MBeanServer, so we don't get into
+ // a race condition with jboss-osgi-jmx also creating one
+ runtime.getMBeanServer();
+
super.start(runtime);
assertMBeanRegistration(runtime, true);
}
@@ -88,32 +92,44 @@
private void assertMBeanRegistration(OSGiRuntime runtime, boolean state)
{
+ log.debug("assertMBeanRegistration: " + state);
+
MBeanServer server = (MBeanServer)runtime.getMBeanServer();
ObjectName fwkName = ObjectNameFactory.create(FrameworkMBean.OBJECTNAME);
ObjectName bndName = ObjectNameFactory.create(BundleStateMBean.OBJECTNAME);
ObjectName srvName = ObjectNameFactory.create(ServiceStateMBean.OBJECTNAME);
-
+
int timeout = 5000;
- while ( 0 < (timeout -= 200))
+ while (0 < (timeout -= 200))
{
- if (server.isRegistered(fwkName) != state || server.isRegistered(bndName) !=
state || server.isRegistered(srvName) != state)
+ boolean fwkCheck = checkMBean(server, fwkName, state);
+ boolean bndCheck = checkMBean(server, bndName, state);
+ boolean srvCheck = checkMBean(server, srvName, state);
+ if (fwkCheck == true && bndCheck == true && srvCheck == true)
+ break;
+
+ try
{
- try
- {
- Thread.sleep(200);
- }
- catch (InterruptedException e)
- {
- // ignore
- }
+ Thread.sleep(200);
}
+ catch (InterruptedException e)
+ {
+ // ignore
+ }
}
-
- if (server.isRegistered(fwkName) != state)
+
+ if (checkMBean(server, fwkName, state) == false)
log.warn("FrameworkMBean " + (state ? "not" :
"still") + " registered");
- if (server.isRegistered(bndName) != state)
+ if (checkMBean(server, bndName, state) == false)
log.warn("BundleStateMBean " + (state ? "not" :
"still") + " registered");
- if (server.isRegistered(srvName) != state)
+ if (checkMBean(server, srvName, state) == false)
log.warn("ServiceStateMBean " + (state ? "not" :
"still") + " registered");
}
+
+ protected boolean checkMBean(MBeanServer server, ObjectName oname, boolean state)
+ {
+ boolean registered = server.isRegistered(oname);
+ log.debug(oname + " registered: " + registered);
+ return registered == state;
+ }
}
\ No newline at end of file
Modified:
projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-bundle/src/main/java/org/jboss/osgi/jmx/internal/MBeanServerService.java
===================================================================
---
projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-bundle/src/main/java/org/jboss/osgi/jmx/internal/MBeanServerService.java 2010-03-18
21:18:15 UTC (rev 102592)
+++
projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-bundle/src/main/java/org/jboss/osgi/jmx/internal/MBeanServerService.java 2010-03-18
21:42:45 UTC (rev 102593)
@@ -23,6 +23,7 @@
//$Id$
+
import java.util.ArrayList;
import javax.management.MBeanServer;
@@ -52,37 +53,46 @@
public MBeanServer registerMBeanServer()
{
- MBeanServer mbeanServer = null;
-
// Check if there is an MBeanServer service already
ServiceReference sref = context.getServiceReference(MBeanServer.class.getName());
if (sref != null)
{
- mbeanServer = (MBeanServer)context.getService(sref);
+ MBeanServer mbeanServer = (MBeanServer)context.getService(sref);
log.debug("Found MBeanServer fom service: " +
mbeanServer.getDefaultDomain());
return mbeanServer;
}
+ // Get or create th MBeanServer
+ MBeanServer mbeanServer = getMBeanServer();
+
+ // Register the MBeanServer
+ context.registerService(MBeanServer.class.getName(), mbeanServer, null);
+ log.debug("MBeanServer registered");
+
+ return mbeanServer;
+ }
+
+ private MBeanServer getMBeanServer()
+ {
+ MBeanServer mbeanServer = null;
+
ArrayList<MBeanServer> serverArr = MBeanServerFactory.findMBeanServer(null);
if (serverArr.size() > 1)
log.warn("Multiple MBeanServer instances: " + serverArr);
-
+
if (serverArr.size() > 0)
{
mbeanServer = serverArr.get(0);
- log.debug("Found MBeanServer: " + mbeanServer.getDefaultDomain());
+ log.debug("Found MBeanServer: " + mbeanServer);
}
-
+
if (mbeanServer == null)
{
log.debug("No MBeanServer, create one ...");
mbeanServer = MBeanServerFactory.createMBeanServer();
+ log.debug("Created MBeanServer: " + mbeanServer);
}
-
- // Register the MBeanServer
- context.registerService(MBeanServer.class.getName(), mbeanServer, null);
- log.debug("MBeanServer registered");
-
+
return mbeanServer;
}
}
\ No newline at end of file
Show replies by date