[jboss-cvs] JBossAS SVN: r66618 - trunk/jbossas/jmx-remoting/src/main/org/jboss/mx/remoting/service.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Oct 31 12:51:38 EDT 2007


Author: dimitris at jboss.org
Date: 2007-10-31 12:51:38 -0400 (Wed, 31 Oct 2007)
New Revision: 66618

Modified:
   trunk/jbossas/jmx-remoting/src/main/org/jboss/mx/remoting/service/JMXConnectorServerService.java
   trunk/jbossas/jmx-remoting/src/main/org/jboss/mx/remoting/service/JMXConnectorServerServiceMBean.java
Log:
JBAS-3885, bind the rmi Registry to the specified address and not 0.0.0.0.

Modified: trunk/jbossas/jmx-remoting/src/main/org/jboss/mx/remoting/service/JMXConnectorServerService.java
===================================================================
--- trunk/jbossas/jmx-remoting/src/main/org/jboss/mx/remoting/service/JMXConnectorServerService.java	2007-10-31 16:33:13 UTC (rev 66617)
+++ trunk/jbossas/jmx-remoting/src/main/org/jboss/mx/remoting/service/JMXConnectorServerService.java	2007-10-31 16:51:38 UTC (rev 66618)
@@ -8,6 +8,7 @@
 
 import java.io.IOException;
 import java.net.InetAddress;
+import java.net.UnknownHostException;
 import java.rmi.registry.LocateRegistry;
 import java.rmi.registry.Registry;
 import java.rmi.RemoteException;
@@ -17,10 +18,12 @@
 import javax.management.remote.JMXConnectorServerFactory;
 import javax.management.remote.JMXServiceURL;
 import org.jboss.logging.Logger;
-
+import org.jboss.net.sockets.DefaultSocketFactory;
 /**
  * Service mbean for starting the JMX Remoting (JSR-160) connector server.
+ * 
  * @author <a href="mailto:tom.elrod at jboss.com">Tom Elrod</a>
+ * @author <a href="mailto:dimitris at jboss.org">Dimitris Andreadis</a>
  */
 public class JMXConnectorServerService implements JMXConnectorServerServiceMBean
 {
@@ -32,8 +35,9 @@
 
    private MBeanServer mbeanServer;
 
+   /** The interface to bind, useful for multi-homed hosts */
+   private InetAddress bindAddress;   
    private int registryPort = Registry.REGISTRY_PORT;
-   private String bindAddress = null;
    private String jndiPath = JNDI_PATH_DEFAULT;
    private JMXConnectorServer connectorServer = null;
    private Registry rmiRegistry = null;
@@ -50,14 +54,17 @@
       return registryPort;
    }
 
-   public void setBindAddress(String bindAddress)
+   public void setBindAddress(String bindAddress) throws UnknownHostException
    {
-      this.bindAddress = bindAddress;
+      this.bindAddress = toInetAddress(bindAddress);
    }
 
    public String getBindAddress()
    {
-      return bindAddress;
+      if (bindAddress != null)
+         return bindAddress.getHostAddress();
+      else
+         return null;
    }
 
    public String getJndiPath()
@@ -77,9 +84,12 @@
 
    public void start() throws Exception
    {
+      // the address to expose in the urls
+      String host = System.getProperty("java.rmi.server.hostname");
+      
       // check to see if registry already created
-      rmiRegistry = LocateRegistry.getRegistry(registryPort);
-      if(rmiRegistry != null)
+      rmiRegistry = LocateRegistry.getRegistry(host, registryPort);
+      if (rmiRegistry != null)
       {
          try
          {
@@ -87,29 +97,25 @@
          }
          catch(RemoteException e)
          {
-            log.debug("No registry running at port " + registryPort + ".  Will create one.");
-            rmiRegistry = LocateRegistry.createRegistry(registryPort);
+            log.debug("No registry running at host '" + host +
+                  "', port '" + registryPort + "'.  Will create one.");
+            rmiRegistry = LocateRegistry.createRegistry(registryPort, null, new DefaultSocketFactory(bindAddress));
          }
       }
       else
       {
-         rmiRegistry = LocateRegistry.createRegistry(registryPort);
+         rmiRegistry = LocateRegistry.createRegistry(registryPort, null, new DefaultSocketFactory(bindAddress));
       }
 
-      if(bindAddress == null || bindAddress.equals("0.0.0.0"))
-      {
-         bindAddress = InetAddress.getLocalHost().getHostName();
-      }
+      String serviceURL = "service:jmx:rmi://" + host + "/jndi/rmi://" + host + ":" + registryPort + jndiPath;
 
-      String serviceURL = "service:jmx:rmi://" + bindAddress + "/jndi/rmi://" + bindAddress + ":" + registryPort + jndiPath;
-
       JMXServiceURL url = new JMXServiceURL(serviceURL);
 
       // create new connector server and start it
       connectorServer = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbeanServer);
       connectorServer.start();
 
-      log.debug("JMX Connector server: " + serviceURL);
+      log.info("JMX Connector server: " + serviceURL);
    }
 
    public void stop() throws IOException
@@ -145,4 +151,16 @@
    {
       // no op, needed for MBeanRegistration interface
    }
+   
+   /**
+    * Safely convert a host string to InetAddress or null
+    */
+   private InetAddress toInetAddress(String host) throws UnknownHostException
+   {
+      if (host == null || host.length() == 0)
+         return null;
+      else
+         return InetAddress.getByName(host);
+   }
+   
 }
\ No newline at end of file

Modified: trunk/jbossas/jmx-remoting/src/main/org/jboss/mx/remoting/service/JMXConnectorServerServiceMBean.java
===================================================================
--- trunk/jbossas/jmx-remoting/src/main/org/jboss/mx/remoting/service/JMXConnectorServerServiceMBean.java	2007-10-31 16:33:13 UTC (rev 66617)
+++ trunk/jbossas/jmx-remoting/src/main/org/jboss/mx/remoting/service/JMXConnectorServerServiceMBean.java	2007-10-31 16:51:38 UTC (rev 66618)
@@ -1,10 +1,12 @@
 package org.jboss.mx.remoting.service;
 
 import java.io.IOException;
+import java.net.UnknownHostException;
 import javax.management.MBeanRegistration;
 
 /**
  * @author <a href="mailto:telrod at e2technologies.net">Tom Elrod</a>
+ * @author <a href="mailto:dimitris at jboss.org">Dimitris Andreadis</a>
  */
 public interface JMXConnectorServerServiceMBean extends MBeanRegistration
 {
@@ -20,7 +22,7 @@
 
    int getRegistryPort();
 
-   void setBindAddress(String bindAddress);
+   void setBindAddress(String bindAddress) throws UnknownHostException;
 
    String getBindAddress();
 




More information about the jboss-cvs-commits mailing list