[jboss-osgi-commits] JBoss-OSGI SVN: r88196 - in projects/jboss-osgi/trunk/bundle/jmx: src/main/java/org/jboss/osgi/jmx and 1 other directories.

jboss-osgi-commits at lists.jboss.org jboss-osgi-commits at lists.jboss.org
Tue May 5 03:20:14 EDT 2009


Author: thomas.diesler at jboss.com
Date: 2009-05-05 03:20:14 -0400 (Tue, 05 May 2009)
New Revision: 88196

Added:
   projects/jboss-osgi/trunk/bundle/jmx/src/main/java/org/jboss/osgi/jmx/internal/ServiceActivator.java
Removed:
   projects/jboss-osgi/trunk/bundle/jmx/src/main/java/org/jboss/osgi/jmx/ServiceActivator.java
Modified:
   projects/jboss-osgi/trunk/bundle/jmx/pom.xml
   projects/jboss-osgi/trunk/bundle/jmx/src/main/java/org/jboss/osgi/jmx/internal/JMXConnectorService.java
Log:
RMIAdaptor tracks NamingService

Modified: projects/jboss-osgi/trunk/bundle/jmx/pom.xml
===================================================================
--- projects/jboss-osgi/trunk/bundle/jmx/pom.xml	2009-05-05 07:19:57 UTC (rev 88195)
+++ projects/jboss-osgi/trunk/bundle/jmx/pom.xml	2009-05-05 07:20:14 UTC (rev 88196)
@@ -24,16 +24,23 @@
       <artifactId>jboss-osgi-spi</artifactId>
       <version>${version}</version>
     </dependency>
+    <dependency>
+      <groupId>org.osgi</groupId>
+      <artifactId>org.osgi.core</artifactId>
+      <scope>provided</scope>
+    </dependency>
     
+    <!-- Bundles -->
     <dependency>
       <groupId>org.jboss.osgi.bundles</groupId>
       <artifactId>jboss-osgi-common</artifactId>
       <version>${version}</version>
+      <scope>provided</scope>
     </dependency>
-    
     <dependency>
-      <groupId>org.osgi</groupId>
-      <artifactId>org.osgi.core</artifactId>
+      <groupId>org.jboss.osgi.bundles</groupId>
+      <artifactId>jboss-osgi-jndi</artifactId>
+      <version>${version}</version>
       <scope>provided</scope>
     </dependency>
     <dependency>
@@ -41,14 +48,6 @@
       <artifactId>org.osgi.compendium</artifactId>
       <scope>provided</scope>
     </dependency>
-    
-    <!-- Test Dependencies -->
-    <dependency>
-      <groupId>org.jboss.osgi</groupId>
-      <artifactId>jboss-osgi-runtime-felix</artifactId>
-      <version>${version}</version>
-      <scope>test</scope>
-    </dependency>
   </dependencies>
 
   <build>
@@ -60,14 +59,14 @@
         <configuration>
           <instructions>
             <Bundle-SymbolicName>${artifactId}</Bundle-SymbolicName>
-            <Bundle-Activator>org.jboss.osgi.jmx.ServiceActivator</Bundle-Activator>
+            <Bundle-Activator>org.jboss.osgi.jmx.internal.ServiceActivator</Bundle-Activator>
             <Import-Package>
                javax.management*,
                javax.naming, 
                javax.naming.spi, 
                org.jboss.net.sockets,
                org.jboss.osgi.common.log, 
-               org.jnp.interfaces,
+               org.jboss.osgi.jndi, 
                org.osgi.framework;version=1.4,
                org.osgi.service.log,
             </Import-Package>

Deleted: projects/jboss-osgi/trunk/bundle/jmx/src/main/java/org/jboss/osgi/jmx/ServiceActivator.java
===================================================================
--- projects/jboss-osgi/trunk/bundle/jmx/src/main/java/org/jboss/osgi/jmx/ServiceActivator.java	2009-05-05 07:19:57 UTC (rev 88195)
+++ projects/jboss-osgi/trunk/bundle/jmx/src/main/java/org/jboss/osgi/jmx/ServiceActivator.java	2009-05-05 07:20:14 UTC (rev 88196)
@@ -1,71 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.osgi.jmx;
-
-//$Id$
-
-import javax.management.MBeanServer;
-
-import org.jboss.osgi.jmx.internal.JMXConnectorService;
-import org.jboss.osgi.jmx.internal.MBeanServerService;
-import org.osgi.framework.BundleActivator;
-import org.osgi.framework.BundleContext;
-
-/**
- * A BundleActivator for the MBeanServer related services
- * 
- * @author thomas.diesler at jboss.com
- * @since 24-Apr-2009
- */
-public class ServiceActivator implements BundleActivator
-{
-   public static final String REMOTE_JNDI_HOST = "org.jboss.osgi.jndi.host";
-   public static final String REMOTE_JNDI_RMI_PORT = "org.jboss.osgi.jndi.rmi.port";
-
-   private JMXConnectorService conService;
-
-   public void start(BundleContext context)
-   {
-      MBeanServerService mbeanService = new MBeanServerService(context);
-      MBeanServer mbs = mbeanService.getMBeanServer();
-
-      String jndiHost = context.getProperty(REMOTE_JNDI_HOST);
-      if (jndiHost == null)
-         jndiHost = "localhost";
-
-      String jndiRmiPort = context.getProperty(REMOTE_JNDI_RMI_PORT);
-      if (jndiRmiPort == null)
-         jndiRmiPort = "1098";
-
-      conService = new JMXConnectorService(context, mbs, jndiHost, Integer.parseInt(jndiRmiPort));
-      conService.start();
-   }
-
-   public void stop(BundleContext context)
-   {
-      if (conService != null)
-      {
-         conService.stop();
-         conService = null;
-      }
-   }
-}
\ No newline at end of file

Modified: projects/jboss-osgi/trunk/bundle/jmx/src/main/java/org/jboss/osgi/jmx/internal/JMXConnectorService.java
===================================================================
--- projects/jboss-osgi/trunk/bundle/jmx/src/main/java/org/jboss/osgi/jmx/internal/JMXConnectorService.java	2009-05-05 07:19:57 UTC (rev 88195)
+++ projects/jboss-osgi/trunk/bundle/jmx/src/main/java/org/jboss/osgi/jmx/internal/JMXConnectorService.java	2009-05-05 07:20:14 UTC (rev 88196)
@@ -30,13 +30,9 @@
 import java.rmi.registry.Registry;
 
 import javax.management.MBeanServer;
-import javax.management.MBeanServerConnection;
 import javax.management.remote.JMXConnectorServer;
 import javax.management.remote.JMXConnectorServerFactory;
 import javax.management.remote.JMXServiceURL;
-import javax.naming.InitialContext;
-import javax.naming.Reference;
-import javax.naming.StringRefAddr;
 
 import org.jboss.net.sockets.DefaultSocketFactory;
 import org.jboss.osgi.common.log.LogServiceTracker;
@@ -52,7 +48,7 @@
 public class JMXConnectorService
 {
    private LogService log;
-   private JMXServiceURL conURL;
+   private JMXServiceURL serviceURL;
    private JMXConnectorServer conServer;
 
    public JMXConnectorService(BundleContext context, MBeanServer mbeanServer, String host, int rmiPort)
@@ -60,7 +56,6 @@
       log = new LogServiceTracker(context);
 
       String jmxConnectorServerPath = "/jmxconnector";
-      String rmiAdaptorPath = "jmx/invoker/RMIAdaptor";
       
       try
       {
@@ -84,23 +79,12 @@
          {
             rmiRegistry = LocateRegistry.createRegistry(rmiPort, null, new DefaultSocketFactory(bindAddress));
          }
-
-         String serviceURL = "service:jmx:rmi://" + host + "/jndi/rmi://" + host + ":" + rmiPort + jmxConnectorServerPath;
-         JMXServiceURL url = new JMXServiceURL(serviceURL);
          
          // create new connector server and start it
-         conServer = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbeanServer);
+         serviceURL = new JMXServiceURL("service:jmx:rmi://" + host + "/jndi/rmi://" + host + ":" + rmiPort + jmxConnectorServerPath);
+         conServer = JMXConnectorServerFactory.newJMXConnectorServer(serviceURL, null, mbeanServer);
 
          log.log(LogService.LOG_DEBUG, "JMX Connector created: " + serviceURL);
-
-         // Bind an ObjectFactory that creates the MBeanServerConnection
-         InitialContext iniCtx = new InitialContext();
-         iniCtx.createSubcontext("jmx").createSubcontext("invoker");
-         StringRefAddr addr = new StringRefAddr(JMXServiceURL.class.getName(), serviceURL);
-         Reference ref = new Reference(MBeanServerConnection.class.getName(), addr, RMIAdaptorFactory.class.getName(), null);
-         iniCtx.bind(rmiAdaptorPath, ref);
-         
-         log.log(LogService.LOG_INFO, "MBeanServerConnection bound: " + rmiAdaptorPath);
       }
       catch (RuntimeException rte)
       {
@@ -112,6 +96,11 @@
       }
    }
 
+   public JMXServiceURL getServiceURL()
+   {
+      return serviceURL;
+   }
+
    public void start()
    {
       if (conServer == null)
@@ -120,7 +109,7 @@
       try
       {
          conServer.start();
-         log.log(LogService.LOG_INFO, "JMXConnector started: " + conURL);
+         log.log(LogService.LOG_INFO, "JMXConnector started: " + serviceURL);
       }
       catch (IOException ex)
       {

Copied: projects/jboss-osgi/trunk/bundle/jmx/src/main/java/org/jboss/osgi/jmx/internal/ServiceActivator.java (from rev 88189, projects/jboss-osgi/trunk/bundle/jmx/src/main/java/org/jboss/osgi/jmx/ServiceActivator.java)
===================================================================
--- projects/jboss-osgi/trunk/bundle/jmx/src/main/java/org/jboss/osgi/jmx/internal/ServiceActivator.java	                        (rev 0)
+++ projects/jboss-osgi/trunk/bundle/jmx/src/main/java/org/jboss/osgi/jmx/internal/ServiceActivator.java	2009-05-05 07:20:14 UTC (rev 88196)
@@ -0,0 +1,148 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.osgi.jmx.internal;
+
+//$Id$
+
+import javax.management.MBeanServer;
+import javax.management.MBeanServerConnection;
+import javax.management.remote.JMXServiceURL;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.naming.Reference;
+import javax.naming.StringRefAddr;
+
+import org.jboss.osgi.common.log.LogServiceTracker;
+import org.jboss.osgi.jndi.NamingService;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.log.LogService;
+import org.osgi.util.tracker.ServiceTracker;
+
+/**
+ * A BundleActivator for the MBeanServer related services
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 24-Apr-2009
+ */
+public class ServiceActivator implements BundleActivator
+{
+   public static final String REMOTE_JMX_HOST = "org.jboss.osgi.jmx.host";
+   public static final String REMOTE_JMX_RMI_PORT = "org.jboss.osgi.jmx.rmi.port";
+   public static final String REMOTE_JMX_RMI_ADAPTOR = "org.jboss.osgi.jmx.rmi.adaptor";
+   
+   private JMXConnectorService conService;
+   private LogService log;
+
+   public void start(BundleContext context)
+   {
+      log = new LogServiceTracker(context);
+      
+      MBeanServerService mbeanService = new MBeanServerService(context);
+      MBeanServer mbs = mbeanService.getMBeanServer();
+
+      String jmxHost = context.getProperty(REMOTE_JMX_HOST);
+      if (jmxHost == null)
+         jmxHost = "localhost";
+
+      String jmxRmiPort = context.getProperty(REMOTE_JMX_RMI_PORT);
+      if (jmxRmiPort == null)
+         jmxRmiPort = "1098";
+
+      String rmiAdaptorPath = context.getProperty(REMOTE_JMX_RMI_ADAPTOR);
+      if (rmiAdaptorPath == null)
+         rmiAdaptorPath = "jmx/invoker/RMIAdaptor";
+      
+      conService = new JMXConnectorService(context, mbs, jmxHost, Integer.parseInt(jmxRmiPort));
+      conService.start();
+      
+      // Start tracking the NamingService
+      NamingServiceTracker tracker = new NamingServiceTracker(context, rmiAdaptorPath);
+      tracker.open();
+   }
+
+   public void stop(BundleContext context)
+   {
+      if (conService != null)
+      {
+         conService.stop();
+         conService = null;
+      }
+   }
+   
+   class NamingServiceTracker extends ServiceTracker
+   {
+      private String rmiAdaptorPath;
+      
+      public NamingServiceTracker(BundleContext context, String rmiAdaptorPath)
+      {
+         super(context, NamingService.class.getName(), null);
+         this.rmiAdaptorPath = rmiAdaptorPath;
+      }
+      
+      @Override
+      public Object addingService(ServiceReference reference)
+      {
+         NamingService naming = (NamingService)super.addingService(reference);
+         
+         // Bind the RMIAdaptor
+         try
+         {
+            InitialContext iniCtx = naming.getInitialContext();
+            iniCtx.createSubcontext("jmx").createSubcontext("invoker");
+            StringRefAddr addr = new StringRefAddr(JMXServiceURL.class.getName(), conService.getServiceURL().toString());
+            Reference ref = new Reference(MBeanServerConnection.class.getName(), addr, RMIAdaptorFactory.class.getName(), null);
+            iniCtx.bind(rmiAdaptorPath, ref);
+            
+            log.log(LogService.LOG_INFO, "MBeanServerConnection bound to: " + rmiAdaptorPath);
+         }
+         catch (NamingException ex)
+         {
+            log.log(LogService.LOG_ERROR, "Cannot bind RMIAdoaptor", ex);
+         }
+         
+         return naming;
+      }
+
+      @Override
+      public void removedService(ServiceReference reference, Object service)
+      {
+         NamingService naming = (NamingService)service;
+         
+         // Unbind the RMIAdaptor
+         try
+         {
+            InitialContext iniCtx = naming.getInitialContext();
+            iniCtx.unbind(rmiAdaptorPath);
+            
+            log.log(LogService.LOG_INFO, "MBeanServerConnection unbound from: " + rmiAdaptorPath);
+         }
+         catch (NamingException ex)
+         {
+            log.log(LogService.LOG_ERROR, "Cannot unbind RMIAdoaptor", ex);
+         }
+         
+         super.removedService(reference, service);
+      }
+   }
+}
\ No newline at end of file




More information about the jboss-osgi-commits mailing list