[jboss-osgi-commits] JBoss-OSGI SVN: r93463 - projects/jboss-osgi/projects/bundles/jmx/trunk/src/main/java/org/jboss/osgi/jmx/internal.

jboss-osgi-commits at lists.jboss.org jboss-osgi-commits at lists.jboss.org
Mon Sep 14 05:50:14 EDT 2009


Author: thomas.diesler at jboss.com
Date: 2009-09-14 05:50:13 -0400 (Mon, 14 Sep 2009)
New Revision: 93463

Modified:
   projects/jboss-osgi/projects/bundles/jmx/trunk/src/main/java/org/jboss/osgi/jmx/internal/JMXConnectorService.java
   projects/jboss-osgi/projects/bundles/jmx/trunk/src/main/java/org/jboss/osgi/jmx/internal/JMXServiceActivator.java
Log:
Always start JMXConnectorServer, assume that failure indicates already running server


Modified: projects/jboss-osgi/projects/bundles/jmx/trunk/src/main/java/org/jboss/osgi/jmx/internal/JMXConnectorService.java
===================================================================
--- projects/jboss-osgi/projects/bundles/jmx/trunk/src/main/java/org/jboss/osgi/jmx/internal/JMXConnectorService.java	2009-09-14 09:32:01 UTC (rev 93462)
+++ projects/jboss-osgi/projects/bundles/jmx/trunk/src/main/java/org/jboss/osgi/jmx/internal/JMXConnectorService.java	2009-09-14 09:50:13 UTC (rev 93463)
@@ -55,40 +55,29 @@
    private boolean shutdownRegistry;
    private Registry rmiRegistry;
 
-   public JMXConnectorService(BundleContext context, MBeanServer mbeanServer, String host, int rmiPort)
+   public JMXConnectorService(BundleContext context, MBeanServer mbeanServer, String host, int rmiPort) throws IOException
    {
       log = new LogServiceTracker(context);
 
+      // check to see if registry already created
+      rmiRegistry = LocateRegistry.getRegistry(host, rmiPort);
       try
       {
-         // check to see if registry already created
-         rmiRegistry = LocateRegistry.getRegistry(host, rmiPort);
-         try
-         {
-            rmiRegistry.list();
-            log.log(LogService.LOG_DEBUG, "RMI registry running at host=" + host + ",port=" + rmiPort);
-         }
-         catch (RemoteException e)
-         {
-            log.log(LogService.LOG_DEBUG, "No RMI registry running at host=" + host + ",port=" + rmiPort + ".  Will create one.");
-            rmiRegistry = LocateRegistry.createRegistry(rmiPort, null, new DefaultSocketFactory(InetAddress.getByName(host)));
-            shutdownRegistry = true;
-         }
-
-         // create new connector server and start it
-         serviceURL = getServiceURL(host, rmiPort);
-         jmxConnectorServer = JMXConnectorServerFactory.newJMXConnectorServer(serviceURL, null, mbeanServer);
-
-         log.log(LogService.LOG_DEBUG, "JMXConnectorServer created: " + serviceURL);
+         rmiRegistry.list();
+         log.log(LogService.LOG_DEBUG, "RMI registry running at host=" + host + ",port=" + rmiPort);
       }
-      catch (RuntimeException rte)
+      catch (RemoteException e)
       {
-         throw rte;
+         log.log(LogService.LOG_DEBUG, "No RMI registry running at host=" + host + ",port=" + rmiPort + ".  Will create one.");
+         rmiRegistry = LocateRegistry.createRegistry(rmiPort, null, new DefaultSocketFactory(InetAddress.getByName(host)));
+         shutdownRegistry = true;
       }
-      catch (Exception ex)
-      {
-         throw new IllegalStateException("Cannot create JMXConnectorServer", ex);
-      }
+
+      // create new connector server and start it
+      serviceURL = getServiceURL(host, rmiPort);
+      jmxConnectorServer = JMXConnectorServerFactory.newJMXConnectorServer(serviceURL, null, mbeanServer);
+
+      log.log(LogService.LOG_DEBUG, "JMXConnectorServer created: " + serviceURL);
    }
 
    static JMXServiceURL getServiceURL(String host, int rmiPort)

Modified: projects/jboss-osgi/projects/bundles/jmx/trunk/src/main/java/org/jboss/osgi/jmx/internal/JMXServiceActivator.java
===================================================================
--- projects/jboss-osgi/projects/bundles/jmx/trunk/src/main/java/org/jboss/osgi/jmx/internal/JMXServiceActivator.java	2009-09-14 09:32:01 UTC (rev 93462)
+++ projects/jboss-osgi/projects/bundles/jmx/trunk/src/main/java/org/jboss/osgi/jmx/internal/JMXServiceActivator.java	2009-09-14 09:50:13 UTC (rev 93463)
@@ -31,8 +31,6 @@
 
 import javax.management.MBeanServer;
 import javax.management.MBeanServerConnection;
-import javax.management.remote.JMXConnector;
-import javax.management.remote.JMXConnectorFactory;
 import javax.management.remote.JMXServiceURL;
 import javax.naming.InitialContext;
 import javax.naming.NamingException;
@@ -146,16 +144,15 @@
          JMXServiceURL serviceURL = JMXConnectorService.getServiceURL(jmxHost, Integer.parseInt(jmxRmiPort));
          try
          {
-            // Assume that the JMXConnector is already running if we can connect to it 
-            JMXConnector connector = JMXConnectorFactory.connect(serviceURL);
-            connector.connect();
-            connector.close();
+            // Try to start the JMXConnector, this should fail if it is already running
+            // [TODO] is there a better way to check whether the connector is already running?
+            jmxConnector = new JMXConnectorService(context, mbeanServer, jmxHost, Integer.parseInt(jmxRmiPort));
+            jmxConnector.start();
          }
          catch (IOException ex)
          {
-            // Start JMXConnectorService
-            jmxConnector = new JMXConnectorService(context, mbeanServer, jmxHost, Integer.parseInt(jmxRmiPort));
-            jmxConnector.start();
+            // Assume that the JMXConnector is already running if we cannot start it 
+            log.log(LogService.LOG_DEBUG, "Assume JMXConnectorServer already running on: " + serviceURL);
          }
          
          try



More information about the jboss-osgi-commits mailing list