zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ph...@apache.org
Subject svn commit: r1164176 - in /zookeeper/trunk: CHANGES.txt src/java/main/org/apache/zookeeper/jmx/MBeanRegistry.java src/java/main/org/apache/zookeeper/jmx/ManagedUtil.java src/java/test/org/apache/zookeeper/test/JMXEnv.java
Date Thu, 01 Sep 2011 17:15:08 GMT
Author: phunt
Date: Thu Sep  1 17:15:08 2011
New Revision: 1164176

URL: http://svn.apache.org/viewvc?rev=1164176&view=rev
Log:
ZOOKEEPER-1168. ZooKeeper fails to run with IKVM (Andrew Finnell via phunt)

Modified:
    zookeeper/trunk/CHANGES.txt
    zookeeper/trunk/src/java/main/org/apache/zookeeper/jmx/MBeanRegistry.java
    zookeeper/trunk/src/java/main/org/apache/zookeeper/jmx/ManagedUtil.java
    zookeeper/trunk/src/java/test/org/apache/zookeeper/test/JMXEnv.java

Modified: zookeeper/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/zookeeper/trunk/CHANGES.txt?rev=1164176&r1=1164175&r2=1164176&view=diff
==============================================================================
--- zookeeper/trunk/CHANGES.txt (original)
+++ zookeeper/trunk/CHANGES.txt Thu Sep  1 17:15:08 2011
@@ -300,6 +300,8 @@ BUGFIXES: 
   ZOOKEEPER-1051. SIGPIPE in Zookeeper 0.3.* when send'ing after 
   cluster disconnection (Stephen Tyree via mahadev)
 
+  ZOOKEEPER-1168. ZooKeeper fails to run with IKVM (Andrew Finnell via phunt)
+
 IMPROVEMENTS:
   ZOOKEEPER-724. Improve junit test integration - log harness information 
   (phunt via mahadev)

Modified: zookeeper/trunk/src/java/main/org/apache/zookeeper/jmx/MBeanRegistry.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/main/org/apache/zookeeper/jmx/MBeanRegistry.java?rev=1164176&r1=1164175&r2=1164176&view=diff
==============================================================================
--- zookeeper/trunk/src/java/main/org/apache/zookeeper/jmx/MBeanRegistry.java (original)
+++ zookeeper/trunk/src/java/main/org/apache/zookeeper/jmx/MBeanRegistry.java Thu Sep  1 17:15:08
2011
@@ -24,6 +24,7 @@ import java.util.concurrent.ConcurrentHa
 
 import javax.management.JMException;
 import javax.management.MBeanServer;
+import javax.management.MBeanServerFactory;
 import javax.management.MalformedObjectNameException;
 import javax.management.ObjectName;
 
@@ -39,7 +40,7 @@ import org.slf4j.LoggerFactory;
 public class MBeanRegistry {
     private static final Logger LOG = LoggerFactory.getLogger(MBeanRegistry.class);
     
-    private static MBeanRegistry instance=new MBeanRegistry(); 
+    private static MBeanRegistry instance = new MBeanRegistry(); 
     
     private Map<ZKMBeanInfo, String> mapBean2Path =
         new ConcurrentHashMap<ZKMBeanInfo, String>();
@@ -47,10 +48,31 @@ public class MBeanRegistry {
     private Map<String, ZKMBeanInfo> mapName2Bean =
         new ConcurrentHashMap<String, ZKMBeanInfo>();
 
-    public static MBeanRegistry getInstance(){
+    private MBeanServer mBeanServer;
+
+    public static MBeanRegistry getInstance() {
         return instance;
     }
-    
+
+    public MBeanRegistry () {
+        try {
+            mBeanServer = ManagementFactory.getPlatformMBeanServer();        
+        } catch (Error e) {
+            // Account for running within IKVM and create a new MBeanServer
+            // if the PlatformMBeanServer does not exist.
+            mBeanServer =  MBeanServerFactory.createMBeanServer();
+        }
+    }
+
+    /**
+     * Return the underlying MBeanServer that is being
+     * used to register MBean's. The returned MBeanServer
+     * may be a new empty MBeanServer if running through IKVM.
+     */
+    public MBeanServer getPlatformMBeanServer() {
+        return mBeanServer;
+    }
+
     /**
      * Registers a new MBean with the platform MBean server. 
      * @param bean the bean being registered
@@ -71,10 +93,9 @@ public class MBeanRegistry {
         mapName2Bean.put(bean.getName(), bean);
         if(bean.isHidden())
             return;
-        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
         ObjectName oname = makeObjectName(path, bean);
         try {
-            mbs.registerMBean(bean, oname);
+            mBeanServer.registerMBean(bean, oname);
         } catch (JMException e) {
             LOG.warn("Failed to register MBean " + bean.getName());
             throw e;
@@ -90,9 +111,8 @@ public class MBeanRegistry {
         if(path==null)
             return;
         if (!bean.isHidden()) {
-            MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
             try {
-                mbs.unregisterMBean(makeObjectName(path, bean));
+                mBeanServer.unregisterMBean(makeObjectName(path, bean));
             } catch (JMException e) {
                 LOG.warn("Failed to unregister MBean " + bean.getName());
                 throw e;

Modified: zookeeper/trunk/src/java/main/org/apache/zookeeper/jmx/ManagedUtil.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/main/org/apache/zookeeper/jmx/ManagedUtil.java?rev=1164176&r1=1164175&r2=1164176&view=diff
==============================================================================
--- zookeeper/trunk/src/java/main/org/apache/zookeeper/jmx/ManagedUtil.java (original)
+++ zookeeper/trunk/src/java/main/org/apache/zookeeper/jmx/ManagedUtil.java Thu Sep  1 17:15:08
2011
@@ -18,7 +18,6 @@
 
 package org.apache.zookeeper.jmx;
 
-import java.lang.management.ManagementFactory;
 import java.util.Enumeration;
 
 import javax.management.JMException;
@@ -45,7 +44,7 @@ public class ManagedUtil {
             return;
         }
         
-        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
+        MBeanServer mbs = MBeanRegistry.getInstance().getPlatformMBeanServer();
 
         // Create and Register the top level Log4J MBean
         HierarchyDynamicMBean hdm = new HierarchyDynamicMBean();

Modified: zookeeper/trunk/src/java/test/org/apache/zookeeper/test/JMXEnv.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/JMXEnv.java?rev=1164176&r1=1164175&r2=1164176&view=diff
==============================================================================
--- zookeeper/trunk/src/java/test/org/apache/zookeeper/test/JMXEnv.java (original)
+++ zookeeper/trunk/src/java/test/org/apache/zookeeper/test/JMXEnv.java Thu Sep  1 17:15:08
2011
@@ -19,7 +19,6 @@
 package org.apache.zookeeper.test;
 
 import java.io.IOException;
-import java.lang.management.ManagementFactory;
 import java.util.Arrays;
 import java.util.HashSet;
 import java.util.Set;
@@ -36,9 +35,10 @@ import javax.management.remote.JMXServic
 
 import junit.framework.TestCase;
 
+import org.apache.zookeeper.jmx.CommonNames;
+import org.apache.zookeeper.jmx.MBeanRegistry;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.apache.zookeeper.jmx.CommonNames;
 
 public class JMXEnv {
     protected static final Logger LOG = LoggerFactory.getLogger(JMXEnv.class);
@@ -47,7 +47,7 @@ public class JMXEnv {
     private static JMXConnector cc;
 
     public static void setUp() throws IOException {
-        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
+        MBeanServer mbs = MBeanRegistry.getInstance().getPlatformMBeanServer();
         
         JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://");
         cs = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);



Mime
View raw message