1 Reply Latest reply on Feb 14, 2005 6:46 PM by mazz

    How can a custom mbean to access other mbeans?

    davidchen Newbie

      Hi, there:

      As a newbie to mbean area, please bear with my dummy question:
      I want to write an mbean deployed on jboss which will grab some information from other jboss mbeans (ex. JBossManagedConnectionPool). I can call getAttribute from mbeanServer like:

      MBeanServer mbeanServer = (MBeanServer)MBeanServerFactory.findMBeanServer(null).get(0);
      ObjectName dsName = new ObjectName("DefaultDomain:service=XADataSource,name=DefaultDS"); //jboss2.4.8
      Integer maxSize = (Integer)mbeanServer.getAttribute(dsName,"MaxSize");
      

      However, because my mbean is deployed under the same mbean server as another mbean, so, is there any other option to get an instance of another mbean (maybe more straight way)? can I get an instance of another mbean by jndi lookup? how?

      Any comments will be highly appreciated, and thanks a lot in advance.
      David

        • 1. Re: How can a custom mbean to access other mbeans?
          mazz Master

          Your MBean implementation can override preRegister and squirrel away the MBeanServer that it gets. Have your MBean provide a public getter to that MBeanServer and you would then be able to have clients know what MBeanServer it belongs to. JBoss's ServiceMBean provides such a mechanism - giving your MBean that functionality, but it has to extend the JBoss specific ServiceMBean impl (ServiceMBeanSupport I think is the name)