1 Reply Latest reply on Jun 3, 2004 7:54 AM by ysidelnikov

    note on instrumenting a NotificationBroadcaster as an XMBean

    brettcalvin Newbie

      Just thought I'd share something I'd discovered:

      If you have a class that implements the NotificationBroadcaster interface (sends JMX notifications) and you instrument it as a ModelMBean using the XMBean approach (by providing an XML description of the MBean interface), you must have a public method sendNotification(Notification notification) in your class for it to work.

      I had a standard MBean that is a NotificationBroadcaster and I converted it to be a ModelMBean to take advantage of the persistence mechanism, but then it stopped working. The reason is that my class was no longer the MBean, but was wrapped by the XMBean class. In order for the XMBean to recognize that it needs to forward your class all the NotificationBroacaster stuff, it needs to see via reflection that your class has that sendNotification method.

      From the ModelMBeanInvoker.java class in the v3.2.3 source:

       /*
       If the managed resource is a NotificationBroadcaster and does have a public method
       sendNotification on it, set our notifier to it. The sendNotification call
       will be invoked through reflection on the resource.
       This is currently the only way an xmbean can send notifications.
       */

      In case someone else comes across the same and is searching for the solution...

      Regards,

      Brett

        • 1. Re: note on instrumenting a NotificationBroadcaster as an XM
          ysidelnikov Newbie

          Could you please provide more details ?
          I have class :
          public class Log implements NotificationBroadcaster
          ...
          public void sendNotification(Notification notification)throws MBeanException
          {
          notifier.sendNotification(notification);
          logger.info("sendNotification()");
          }
          ...
          public MBeanNotificationInfo[] getNotificationInfo()
          {
          return (new MBeanNotificationInfo[] {
          notificationInfo
          });
          }
          and xml:
          <!-- Notifications -->

          Log messages
          javax.management.Notification
          <notification-type>Log</notification-type>

          but I can't see any notifications via for example MC4J.
          Thank you.