2 Replies Latest reply on Apr 22, 2004 5:01 PM by Guy Rouillier

    Calling a MBean from the server side.

    Seb Newbie

      Hi all,

      I would like to know which is the best approach to call a MBean from a component server like an EJB or another MBean. Should I use the RMIAdaptor ? Does the RMIAdaptor have optimizing calls (ref calls) when we are in the same VM ?

      Or is there another road ... I haven't found anything about how MBeans communicate with each others in the source of JBOSS. (Due certainly to the fact that I'm a newbie !)

      Thanks a lot
      Seb.

        • 1. Re: Calling a MBean from the server side.
          Tarek Hammoud Novice

          This is what we do and it works well for us.

          public static Object getMBean(String name) {
          try {
          ObjectName myBeanContainerName = new ObjectName(name);
          Object myParams[] = { myBeanContainerName };
          String mySig[] = {"javax.management.ObjectName"};

          MBeanServer myServer = (MBeanServer) MBeanServerFactory.findMBeanServer(null).get(0);

          MBeanEntry myContainerEntry = (MBeanEntry)myServer.invoke(new ObjectName("JMImplementation:type=MBeanRegistry"),
          "get",
          myParams,
          mySig);

          mbean = myContainerEntry.getResourceInstance();

          // Handle XMBeans
          if (mbean instanceof XMBean) {
          XMBean xmBean = (XMBean)mbean;
          mbean = xmBean.getResource();
          }
          return mbean;
          }
          catch(Throwable e) {
          throw new RuntimeException(e);
          }
          }

          • 2. Re: Calling a MBean from the server side.
            Guy Rouillier Newbie

            Why is all that necessary? If all you want to do is invoke an MBean from within an EJB or another MBean, you can just do a simple lookup on the MBean, right?