1 Reply Latest reply on Jun 12, 2012 11:57 AM by Jay SenSharma

    How to get Instance of MBean Service in JBOSS AS 7.1.1

    SMS JBOSS Newbie

      Hi,

           I am trying to access a MBean service deployed into JBOSS AS 7.1.1. My MBean service is also a Queue Listener. I am trying to get an instance of this MBean service to register it as a Queue Listener in another SAR.

       

      I tried out this code but it is not working,

                                    MBeanServer server = ManagementFactory.getPlatformMBeanServer();

                                                                  ObjectName mbeanObject = new ObjectName("myproject.service.Test:service=com.mytest.program");

                                    TestServiceMBean handler =  MBeanServerInvocationHandler.newProxyInstance(server,                                                                                                                                                      mbeanObject, TestServiceMBean.class, false);

       

      I also tried out this

                                    TestServiceMBean testMBeanService = (TestServiceMBean)server.getAttribute(mbeanObject, "Instance");

       

      In both the cases I am not getting the instance of the TestServiceMBean. Can anyone please help me in getting the access to MBean Test service.

       

       

         <mbean code="com.mytest.program.TestService"

                name="myproject.service.Test:service=com.mytest.program">

       

         </mbean>

       

      public class TestService implements TestServiceMBean, MessageListener {

        • 1. Re: How to get Instance of MBean Service in JBOSS AS 7.1.1
          Jay SenSharma Master

          Hi,

           

              As it looks like you are trying to access the MBean from inside a component (like servlet/jsp...etc) from inside the JBoss.  So can you try the following:

           

          Step1).   Place the "jboss-as-7.1.1.Final/bin/client/jboss-client.jar" inside the "WEB-INF/lib" directory of your application.

           

          Step2).   Now Change the code of MBean Access as following:

           

            String host = "localhost";  // Your JBoss Bind Address default is localhost

                  int port = 9999;  // management-native port

           

                  String urlString ="service:jmx:remoting-jmx://" + host + ":" + port;

                  System.out.println("          \n\n\t****  urlString: "+urlString);

           

                  JMXServiceURL serviceURL = new JMXServiceURL(urlString);

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

                  MBeanServerConnection connection = jmxConnector.getMBeanServerConnection();

           

                  //Invoke on the JBoss AS MBean server

                  int count = connection.getMBeanCount();

                  System.out.println(count);

           

                  ObjectName objectName=new ObjectName("myproject.service.Test:service=com.mytest.program");

           

                This is just to test whether the Mbean which you created if fine or If it is deployed successfully or not... You can also try using the JCOnsole to see if you are able to see your Custom MBean in the JConsole MBeans tab.

           

          Reference:  http://middlewaremagic.com/jboss/?p=1846