1 Reply Latest reply on Jul 4, 2013 1:46 PM by Thiago Nascimento

    Java Client connecting to remote host

    Thiago Nascimento Newbie

      Hi,

       

      I've been writing a Java Client to connect to a remote host. I want to monitoring a Jboss App. I've tried two approaches and both works. However I've not understood the difference between them. Coud someone give me a help?

      For example, I don't understand why it's necessary to look up the RMIServer directly in the second approach. Moreover, why does the first approach works using the RMI default port (1090) and the second not works at it?

       

      String host = "xulambshost";

       

      ----------------------------------------------------------------------------------------------------------------------------------

      Approach 1:

      int port = 1090;

      String urlString = "service:jmx:rmi:///jndi/rmi://" + host + ":" + port + "/jmxconnector";

      JMXServiceURL serviceUrl = new JMXServiceURL(urlString);

      JMXConnector jmxconn = JMXConnectorFactory.connect(serviceUrl, null);

      ----------------------------------------------------------------------------------------------------------------------------------

      Approach 2

      int port = 9999;

      String urlPath = "/jndi/rmi://" + host + ":" + port + "/jmxrmi";

      JMXServiceURL jmxurl = new JMXServiceURL("rmi", "", 0, urlPath);

      Registry registry = LocateRegistry.getRegistry(host, port);

      RMIServer stub = (RMIServer) registry.lookup("jmxrmi");

      JMXConnector jmxconn = new RMIConnector(stub, null);

      jmxconn.connect();

      ----------------------------------------------------------------------------------------------------------------------------------

             

      MBeanServerConnection jmxserver = jmxconn.getMBeanServerConnection();

        • 1. Re: Java Client connecting to remote host
          Thiago Nascimento Newbie

          Actually, I've noticed the second approach can be rewritten as follow:

           

          ----------------------------------------------------------------------------------------------------------------------------------

          Approach 2:

          int port = 9999;

          String urlString = "service:jmx:rmi:///jndi/rmi://" + host + ":" + port + "/jmxrmi";

          JMXServiceURL serviceUrl = new JMXServiceURL(urlString);

          JMXConnector jmxconn = JMXConnectorFactory.connect(serviceUrl, null);

          ----------------------------------------------------------------------------------------------------------------------------------

           

          But some questions persists.

          1. Why does first approach works at the port 1090 and second works at the 9999?

          2. Why does first approach works with "/jmxconnector" in the URL and the second works with "/jmxrmi" in it?