Search code examples
jmxjboss7.xmbeans

Getting Instance of MBean service in JBOSS AS 7.1.1


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>

Here's the code:

public class TestService implements TestServiceMBean, MessageListener {

Solution

  • Muthu;

    For the AttributeNotFoundException: At least we know that the MBean is actually registered :) So the question is, does your TestService mbean define an attribute called Instance and does it have a return a type of TestServiceMBean and does it actually return this ? If not, that's what you need to do.

    TestService:

    public TestServiceMBean getInstance() {
        return this;
    }
    

    TestServiceMBean:

    public TestServiceMBean getInstance();
    

    For the invocation handler, you should not need to cast, but the returned class will not have the name you expect. It's called Proxy0 because it is a synthetic dynamic proxy, but you should find that it does implement the TestServiceMBean interface and you should be able to invoke operations against it.