2 Replies Latest reply on Aug 12, 2003 10:20 AM by kristoeffy

    MBean service object references

    Fred Loney Newbie

      (cross-posted from jboss-user)

      Correct me if I'm wrong, but I get the impression that JMX was not intended to provide a service object reference. The JMX spec is unclear about this, but MBean interaction appears to block every avenue to get past the arm's-length invocation and get at a direct object reference.

      I understand the JMX motivation for distributed interaction, but some (most?) apps would prefer either a simple registrar local to a VM or a smart proxy a la Jini LUS. Unfortunately, that doesn't appear to be forthcoming from JMX, so we must each hand-roll our little hacks.

      I implemented a registration protocol on top of an MBeanServer that records the service object reference with a service broker. The Service Loader MBean below appears to be a similar concept. There are several gotchas, e.g. setting a listener for new MBean notification.

      Since jboss is active in the JMX group, does somebody out there have more insight as to whether there is or will be a conventional way to obtain a direct service object reference?

      ----- Original Message -----
      From: "Lennart Petersson" <lennart.petersson@benefit.se>
      To: <jboss-user@lists.sourceforge.net>
      Sent: Monday, August 20, 2001 11:40 PM
      Subject: SV: [JBoss-user] How to obtain the reference of a MBean?


      Here is an snippet from my code:

      /** Reference to a instance of the MbeanServer */
      private transient MBeanServer mbeanServer = null;

      /** ObjectName of the service loader MBean */
      private transient ObjectName serviceLoader = null;

      try
      {
      // Get instance to MBeanServer
      Collection col = MBeanServerFactory.findMBeanServer(null);
      if(col.isEmpty())
      {
      System.out.println("No MBeanServer found");
      return;
      }
      // Assumes there is only one :-)
      mbeanServer = (MBeanServer)col.iterator().next();

      // Construct ObjectName of the service loader MBean (this is our own MBean)
      Set set = mbeanServer.queryMBeans(new ObjectName("*:service=ECS Service Loader"), null);
      if(set.isEmpty())
      {
      System.out.println("No ECS Service Loader MBean found");
      return;
      }
      // Now i know that there is only one :-)
      serviceLoader = ((ObjectInstance)set.iterator().next()).getObjectName();

      }
      catch(final Exception e)
      {
      System.out.println("Failed to create a trader bean");
      e.printStackTrace();
      }

      // Now i have a ref to our ECS Service Loader MBean and can invoke methods on it like in this example:
      try
      {
      // Get a collection of available services from our ECSServiceLoader MBean using the MBeanServer
      return (Collection)mbeanServer.invoke(
      serviceLoader,
      "getServices",
      new Object[0],
      new String[0]);
      }
      catch(final Exception e)
      {
      System.out.println("Failed to get services from loader mbean");
      e.printStackTrace();
      return new ArrayList();
      }

      /Lennart

      ----- Original Message -----
      From: Herve Tchepannou <htchepannou@objexis.com>
      To: <jboss-user@lists.sourceforge.net>
      Sent: Monday, August 20, 2001 9:02 PM
      Subject: [JBoss-user] How to obtain the reference of a MBean?


      > I've just successfuly deploy a MBean into JBoss.
      > Im wondering how my EJB object can obtain the reference of the MBean object?
      >

        • 1. Re: MBean service object references
          kristoeffy Newbie

          I've written a "getThis()){return this;} method by the MBean which is exported.
          Works of course only in Server-VM (e.g. Server-Side-Interceptors).

          • 2. Re: MBean service object references
            kristoeffy Newbie

            ... And for anybody who is not so experienced with MBeans:
            you will call the getThis() with:
            _server.getAttribute(objName, "This");

            [ and not the invoke(...) mechanism - if you want to use invoke(...) you will have to export a method beginning NOT with "get" - e.g. "returnThis()" ]

            >> objName for example like this:
            ObjectName objName = new ObjectName("myDomain:service=DataCollector");

            >> _server you can get (ignoring exceptions and null-ReturnValues) with:
            ArrayList mbeanServers = MBeanServerFactory.findMBeanServer(null);
            _server = (MBeanServer) mbeanServers.get(0);