8 Replies Latest reply on Oct 18, 2009 12:42 PM by ohadr

    Non-proprietary connection to JBoss JMX MBeanServer

    ronchalant

      The RMI Adaptor gives access to the JBoss JMX MBeanServer, but is there a non-proprietary way I can directly access the server? I'm writing a client application to access my managed beans, and I don't want to tie it directly to JBoss in case we switch to another app server in production. Previously I've done this by creating a JMXServiceURL, then getting a JMXConnector and finally getting the direct connection to the MBeanServer from the connector.

      I've tried to connect by building a JNDI connector URL (used in the JMXServiceURL) like this: service:jmx:rmi://localhost/jndi/jmx/rmi/RMIAdaptor

      But this just returns the RMIAdaptor object, so I get a ClassCastException because it's looking for an implementation of the Server - not the proprietary JBoss adaptor. I've not found anything online, so this is my last ditch effort before I have to change my design to designate specific implementations of an MBeanServerAccessor or something.

        • 1. Re: Non-proprietary connection to JBoss JMX MBeanServer
          genman


          Look on the Wiki. You can get a javax.management.MBeanServer which wraps the calls to the RMI adaptor.

          • 2. Re: Non-proprietary connection to JBoss JMX MBeanServer
            ronchalant

            Yeah but I still need to use propriety code. I can't just gain a connection to a JBoss MBeanServer using a JMXConnector (which would require a JMXConnectorServer to be running somewhere).

            What I've started to try and do now is creating a JBoss-specific MBean that is a JMXConnectorServer essentially. I'd like to use the jmxmp protocol, but it doesn't seem that JBoss supports this.

            It seems like JBoss doesn't make it very easy to get a connection to their MBeanServer without using any of their code or libs. I don't want to be tied to JBoss though.

            • 3. Re: Non-proprietary connection to JBoss JMX MBeanServer
              ronchalant

              I've actually found a way to do it. I extended the org.jboss.system.ServiceMBeanSupport class and in it I created a JMXConnectorServer. I used the JMXMP protocol, and it was failing before not because JBoss doesn't support it, but because I need to include the jmxremote_optional.jar file in my deployment lib directory.

              Now I can create a JMXConnector object to connect directly to the JMXConnectorMBean, which will give me non-proprietary remote access to my MBeans on the MBeanServer.

              • 4. Re: Non-proprietary connection to JBoss JMX MBeanServer
                raja05

                You could use the HTTPAdaptor as well. You probably need to tweak ur url to pass in arguments and stuff but thats definitely a workable solution.
                Whatever u view through the jmx-console uses the HTTPAdaptor to do its work.

                • 5. Re: Non-proprietary connection to JBoss JMX MBeanServer
                  ronchalant

                  I could use the HTTPAdaptor, but it would only work for JBoss. I wanted to use a method that's not proprietary to any particular appserver. Creating a JMXConnectorServer and running it as a bean still requires some JBoss specific implementation, but it still provides a design for allowing remote management of MBeans by providing a generic, non-proprietary connection to the MBeanServer.

                  • 6. Re: Non-proprietary connection to JBoss JMX MBeanServer
                    hengels

                    Could you please send me your code? I tried to do the same, but I keep getting ClassCastExceptions during:

                     JMXConnector connector = JMXConnectorFactory.connect(url);
                    


                    This is my binding code:

                     JMXServiceURL url = new JMXServiceURL("rmi", null, 0);
                     connectorServer = JMXConnectorServerFactory.newJMXConnectorServer(url, null, getServer());
                     connectorServer.start();
                     bind(jndiName, connectorServer.toJMXConnector(null));
                    


                    JndiView shows:

                     +- JMXConnectorServer (class: javax.management.remote.rmi.RMIConnector)
                    


                    The exception:

                    java.lang.ClassCastException
                    org.concern.ControllerException: java.lang.ClassCastException
                     at org.concern.j2ee.client.JMXConnector.connect(JMXConnector.java:43)
                     at org.concern.j2ee.client.commandline.Concern.getController(Concern.java:80)
                     at org.concern.j2ee.client.commandline.Concern.main(Concern.java:53)
                    Caused by: java.lang.ClassCastException
                     at javax.management.remote.rmi.RMIConnector.narrowJRMPServer(RMIConnector.java:1818)
                     at javax.management.remote.rmi.RMIConnector.findRMIServerJNDI(RMIConnector.java:1813)
                     at javax.management.remote.rmi.RMIConnector.findRMIServer(RMIConnector.java:1777)
                     at javax.management.remote.rmi.RMIConnector.connect(RMIConnector.java:259)
                     at javax.management.remote.JMXConnectorFactory.connect(JMXConnectorFactory.java:248)
                     at javax.management.remote.JMXConnectorFactory.connect(JMXConnectorFactory.java:207)
                     at org.concern.j2ee.client.JMXConnector.connect(JMXConnector.java:36)
                     ... 2 more
                    


                    thanks in advance,

                    Holger

                    • 7. Re: Non-proprietary connection to JBoss JMX MBeanServer
                      hengels

                       

                      "hengels" wrote:
                      This is my binding code:
                       JMXServiceURL url = new JMXServiceURL("rmi", null, 0);
                       connectorServer = JMXConnectorServerFactory.newJMXConnectorServer(url, null, getServer());
                       connectorServer.start();
                       bind(jndiName, connectorServer.toJMXConnector(null));
                      



                      Found out myself. The binding was wrong. Don't put the jmx connector into jndi but the javax.management.remote.rmi.RMIServer:

                       JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/JMXConnectorServer");
                       connectorServer = JMXConnectorServerFactory.newJMXConnectorServer(url, null, getServer());
                       connectorServer.start();
                      


                      • 8. Re: Non-proprietary connection to JBoss JMX MBeanServer
                        ohadr

                        hi
                        did u get the code? i am interested as well...
                        im trying to do the same...
                        btw - onchalant - how did u handle WebSphere?

                        thanks
                        ohad