2 Replies Latest reply on Oct 16, 2004 3:39 PM by gunterze

    MMB's AttributeChangeNotifaction not received by Listener re

    gunterze

      What's wrong with this code:

      public class MyXMBeanImpl extends ServiceMBeanSupport
       implements NotificationListener {
      
       public void handleNotification(Notification notif, Object handback) {
       log.info("handleNotification, event: "+notif);
       }
      
       protected void startService() throws Exception {
       server.addNotificationListener(super.serviceName, this, null, null);
       }
      
       protected void stopService() throws Exception {
       server.removeNotificationListener(super.serviceName, this);
       }
      
      // ....
      // gettes & setter of service attributes, referenced in
      // conf/xmdesc/MyXMBean-mbean.xml
      }


      handleNotification does not receive AttributChangeNotifications triggered by attribute modifications by the JMX console (emitted by ModelMBeanInvoker.sendNotification()) - but it receives the AttributChangeNotifications emitted by ServiceMBeanSupport.jbossInternalStart and ServiceMBeanSupport.jbossInternalStop.

      The problem may be, that there are two NotificationBroadcasterSupport objects:
      1. class ServiceMBeanSupport extends NotificationBroadcasterSupport {..}
      2. ModelMBeanInvoker.notifer = new NotificationBroadcasterSupport();

      which each has its own ListenerRegistry:
      NotificationBroadcasterSupport.registry = new ListenerRegistry();

      And
      server.addNotificationListener(super.serviceName, this, null, null);
      seems to add the listener only in the registry of 1. , but ModelMBeanInvoker.sendNotification() only emits notification to listeners registered in 2.

        • 1. Re: MMB's AttributeChangeNotifaction not received by Listene
          dimitris

          I believe you right!

          Looking inside the code, with XMBeans when the target resource implements NotificationBroadcaster, then the 1st registry of the XMBean is never updated with listeners.

          Thinking of possible solutions, ideally the XMBean would forward notification "emitions" to the 2nd registry, but there is no interface to do this (other that trying to cast to NotificationBroadcasterSupport, but there is no guarantee for this).

          So the only way is to have both registries updated with listeners.

          Could you please, file a bug-report at sourceforge and possibly submit a simplified version of your MBean code, so we can add a test to the JBoss testsuite and I'll fix the bug.

          Which JBoss version are you using?

          • 2. Re: MMB's AttributeChangeNotifaction not received by Listene
            gunterze

            I am using jboss-3.2.5.

            I was wondering, why you have declare in the service descriptor as code attribute of the mbean element. the resource class and not the MMB class. Thinking, that could be a reason, why server.addNotifiactionListener() add the handler into the listener registry of the resource instead of the MMB, I tried

            <mbean code=" org.jboss.mx.modelmbean.XMBean" ..

            but that did not work.

            Ok, I will file a bug report with a code sample @ sourceforge.

            Regards,
            gunter