7 Replies Latest reply on Dec 19, 2008 7:06 AM by kconner

    Accessing Mbean

      Hi ,
      I want to access JMX Console Mbean Messagecount property..Please guide me to the Mbean api which would help me to obtain various propeties of Mbean.

        • 1. Re: Accessing Mbean
          kconner

          The beans are available through the normal mechanisms although they have been reworked recently.

          What have you tried and what do you want to achieve?

          • 2. Re: Accessing Mbean

            I am novice in this area .In the JMX console we have various properties for each queue deployed on the server . I want to access the message count property of a particular queue.For this i should be able to interact with Mbaen and extract this particular property. How to do the same? What all API is required ?Could you provide me with a sample code ?

            • 3. Re: Accessing Mbean
              kconner

              Interact in what way though?

              If this is within the same VM then you just need to lookup the MBeanServer and then query the attribute.

              MBeanServer mbeanServer = MBeanServerLocator.locateJBoss();

              public Object getAttribute(ObjectName name, String attribute)

              • 4. Re: Accessing Mbean

                I have jboss-soa-p.4.2.0 on my local machine . I want to write java code so that I can obtain the value of MessageCount property of 'helloworlrd' queue that is deployed on the jboss-as that I obtain in my jmx console.

                • 5. Re: Accessing Mbean

                   


                  MBeanServer mbeanServer = MBeanServerLocator.locateJBoss();

                  public Object getAttribute(ObjectName name, String attribute)


                  I tried it but i get following error

                  
                  Exception in thread "main" java.lang.IllegalStateException: No 'jboss' MBeanServer found!
                   at org.jboss.mx.util.MBeanServerLocator.locateJBoss(MBeanServerLocator.java:122)
                   at MbeanAccessor.main(MbeanAccessor.java:9)
                  


                  My line 9 is

                   //Line 9 :
                   MBeanServer mbeanServer = MBeanServerLocator.locateJBoss();
                   //Line 10 :
                  System.out.println(mbeanServer.getMBeanCount());



                  • 6. Re: Accessing Mbean

                    Hi ,

                    I got the solution .

                    The code to access a Mbean property is :

                    
                     InitialContext context = new InitialContext();
                     MBeanServerConnection mbeanServer = (MBeanServerConnection)context.lookup ( "jmx/invoker/RMIAdaptor" );
                     ObjectName queue = new ObjectName ("jboss.messaging.destination:service=Queue,name=testQueue" );
                     Integer messageCount = (Integer)server.getAttribute ( queue, "MessageCount" );
                     System.out.println ( messageCount );
                    
                    
                    


                    Apart from this one has to set following properties. You can pass them on the command line ("-Djava.naming.provider.url=jnp://localhost:1099"), put them in a jndi.properties file in your classpath, or put them in a Hashtable and pass it when creating the InitialContext.

                    
                    java.naming.factory.initial=org.jboss.security.jndi.JndiLoginInitialContextFactory
                    java.naming.provider.url=jnp://localhost:1099
                    java.naming.security.principal=admin
                    java.naming.security.credentials=admin
                    
                    


                    • 7. Re: Accessing Mbean
                      kconner

                      Sorry for the delay in getting back to you.

                      Yes, the code you have is correct for accessing the MBeanServer from outside the VM. The MBeanServerLocator.locateJBoss() invocation is from within the same VM.

                      Kev