14 Replies Latest reply on Mar 19, 2012 5:19 PM by Peter Fry

    remote JMX call from within JBoss

    Peter Fry Newbie

      I have tried to follow the answer posted on

       

      https://community.jboss.org/message/719763

       

      with regard access JMX information in JBoss. I think this is working for me when connecting from a remote client (not surprisingly since this matches the answer's usecase exactly)

       

      BUT

       

      I am having trouble when trying to do this from within JBoss. My code is:

       

       

      JMXServiceURL serviceURL = new JMXServiceURL(urlString);       

      JMXConnector jmxConnector = JMXConnectorFactory.connect(serviceURL, null);       

      MBeanServerConnection connection = jmxConnector.getMBeanServerConnection();

       

      The module that is trying to connect to JMX is in myear.ear/lib

       

      I have tried a number of varitions on

       

      <jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.0">

      <ear-subdeployments-isolated>false</ear-subdeployments-isolated>

        <deployment>

          <dependencies>

             <module name="org.jboss.as.jmx"/>.....

       

      But to no avail, the stack trace is

       

      failed to connect: java.net.MalformedURLException: Unsupported protocol: remoting-jmx

      at javax.management.remote.JMXConnectorFactory.newJMXConnector(JMXConnectorFactory.java:327) [rt.jar:1.6.0_13]

      at javax.management.remote.JMXConnectorFactory.connect(JMXConnectorFactory.java:247) [rt.jar:1.6.0_13]

       

      Which the answered question indicates as a classpath issue hence my attempt to introduce a dependency on "org.jboss.as.jmx" .

       

      Any hints much appreciated.

       

      Peter.

        • 1. Re: remote JMX call from within JBoss
          Darran Lofthouse Master

          Can you try adding a dependency on the "org.jboss.remoting3.remoting-jmx" module - this is where the provider implementation lives.

          • 2. Re: remote JMX call from within JBoss
            Peter Fry Newbie

            Still says, errors with the same stack trace.

            • 3. Re: remote JMX call from within JBoss
              Darran Lofthouse Master

              Ok, I will try this with something else I am looking at regarding JMX.

               

              One quick question, is there a reason you need a remote connection to JMX?  Is this to connect to a remote server or the local server?

              • 4. Re: remote JMX call from within JBoss
                Peter Fry Newbie

                Essentially I have remote and local (within jboss) clients that can send messages to queues and I don't want to allow them to do so until those queues are available.

                 

                The code that we previously used in Jboss 5.0.1 is

                 

                JMXServiceURL serviceURL = new JMXServiceURL(urlString);       
                JMXConnector jmxConnector = JMXConnectorFactory.connect(serviceURL, null);       
                MBeanServerConnection connection = jmxConnector.getMBeanServerConnection();
                               
                ObjectName name = ObjectName.getInstance("jboss.system", "type", "Server");
                Boolean started = (Boolean) connection.getAttribute(name, "Started");

                 

                 

                • 5. Re: remote JMX call from within JBoss
                  Peter Fry Newbie

                  I said that the remote client seemed to be connecting but in fact I am getting

                   

                  java.lang.RuntimeException: Operation failed with status WAITING
                  at org.jboss.remoting3.jmx.RemotingConnector.connect(RemotingConnector.java:173)
                  at javax.management.remote.JMXConnectorFactory.connect(JMXConnectorFactory.java:248)

                  This remote client has a classpath which has the new jboss-client-7.1.0.Final.jar on it as well as a jboss-ejb-client.properties file and is able to make remote ejb calls via the ejb: protocol.

                  • 6. Re: remote JMX call from within JBoss
                    Darran Lofthouse Master

                    in-vm you would probably be better to just access the MBeanServer directly and save any network overhead.

                     

                    For the remote client which port are you trying to connect to?  Do you get any errors on the server?

                    1 of 1 people found this helpful
                    • 7. Re: remote JMX call from within JBoss
                      Peter Fry Newbie

                      My remote jmx connection now works (confusion on my part between the remoting port and the management native port.

                       

                      Some comments though:

                       

                      1) I can't get jconsole to connect (I noticed someone else raising this, I'm guessing if you are going to jboss remoting rather than rmi then you will need that on the jconsole classpath?)

                      2) jmxConnector.close() doesn't seem to do anything (trying out the simple java app in the JBoss AS 7.1 documentation on JMX hangs and when I kill it I get warning messages in JBoss - this was from eclipse so maybe something funny going on there).

                       

                      Lastly but most importantly can you give any guidance to what bean to use instead of the bean used in the following which worked for Jboss 5.0.1

                       

                                      ObjectName name = ObjectName.getInstance("jboss.system", "type", "Server");
                                      Boolean started = (Boolean) connection.getAttribute(name, "Started");

                       

                      Bit worried about the the jmxConnecter.close()! UPDATE - I definitely have loads of connections being left around  and get lots of

                       

                      2012-03-01 09:43:12,288 ERROR - JBREM000200: Remote connection failed: java.io.IOException: An existing connection was forcibly closed by the remote host (org.jboss.remoting.remote.connection)

                       

                      being reported in the client after I stop JBoss.

                       

                      Thanks,

                       

                      Peter.

                      • 8. Re: remote JMX call from within JBoss
                        Darran Lofthouse Master

                        1) I can't get jconsole to connect (I noticed someone else raising this, I'm guessing if you are going to jboss remoting rather than rmi then you will need that on the jconsole classpath?)

                        Yes jconsole does need the correct classpath to be set so that the remoting-jmx libraries can be found, within the bin folder of the AS7 distributions there is now a pair of jconsole scripts that set up the classpath as required before starting jconsole.

                         

                        2) jmxConnector.close() doesn't seem to do anything (trying out the simple java app in the JBoss AS 7.1 documentation on JMX hangs and when I kill it I get warning messages in JBoss - this was from eclipse so maybe something funny going on there).

                        The close call does shut down the Remoting connection but there was also an ExecutorService left running which was causing some client issues which has been resolved under the following issue: -

                         

                        https://issues.jboss.org/browse/REMJMX-34

                         

                        If you still get close errors a test case to reproduce would be appreciated so we can try and run it locally.

                         

                        Regarding the available MBeans I am going to need to let someone else follow up on that one  as I have been more involved in the communications protocol rather than the beans themselves.

                        1 of 1 people found this helpful
                        • 9. Re: remote JMX call from within JBoss
                          Peter Fry Newbie

                          Thanks, I hadn't noticed the jconsole scripts in the jboss as 7.1 bin directory, able to connect fine now.

                           

                          REMJMX-34 suggests that the daeomon threads die after 60 seconds so I will see if this is indeed the case, if so it is something we can tolerate.

                           

                          UPDATE: the threads are not dying after 60 seconds I have uploaded a test case.

                           

                          Thanks,

                           

                          Peter.

                           

                          Message was edited by: Peter Fry

                          • 10. Re: remote JMX call from within JBoss
                            Peter Fry Newbie

                            Is there any recommendation regarding REMJMX-34 ? The issue log indicates it is fixed, should I try and get a jar and drop it into my JBoss AS 7.1 installation (though preumably I'll have to update the bundled client jar ?

                             

                            • 11. Re: remote JMX call from within JBoss
                              Darran Lofthouse Master

                              You will not be able to drop it in on the server side as there are some changes to the classes referenced by AS7 - on the client side however the protocol is exactly the same so you may be able to replace the version on the client.

                              • 12. Re: remote JMX call from within JBoss
                                Peter Fry Newbie

                                I've tried the following code for querying the jmx server from WITHIN JBoss (in fact from a servlet that is being deployed, I make the servlet dependent on the 'org.jboss.as.jmx' module)

                                 

                                connection = MBeanServerFactory.newMBeanServer();

                                 

                                ObjectName serviceRef = new ObjectName("*.*:*");
                                Set<ObjectName> mbeans = connection.queryNames(serviceRef, null);
                                for (ObjectName on : mbeans)
                                {

                                       System.out.println("\t ObjectName : " + on);
                                }

                                 

                                But it doest list any MBeans. Is this the right way to get a local connection to the Jboss 7.1 JMX server to query MBeans?

                                • 13. Re: remote JMX call from within JBoss
                                  Dimitris Andreadis Master

                                  Get the platformMBeanServer instead of creating a new one.

                                  • 14. Re: remote JMX call from within JBoss
                                    Peter Fry Newbie

                                    OK this is a dumb question - how do you get the platform MBeanServer from within a JBoss AS 7.1 deployment unit (such as a servlet). Would appreciate a code snippet.

                                     

                                    Thanks,

                                     

                                    Peter.

                                     

                                    UPDATE:

                                     

                                    Do you mean:

                                     

                                    ManagementFactory.getPlatformMBeanServer();