2 Replies Latest reply on Jun 4, 2009 6:32 AM by Dimitris Andreadis

    Receiving notification from other MBeans

    joshua aaaaa Newbie

      Hi all!
      I'm trying to receive notifications from a simple MBean component. The MBean (taken from wikis) simply dumps a Message when the operation printMessage is invoked:

      public class StartupService extends ServiceMBeanSupport implements StartupServiceMBean
      {
       // Our message attribute
       private String message = "Sorry no message today";
      
       // Getters and Setters
       public String getMessage()
       {
       return message;
       }
       public void setMessage(String message)
       {
       this.message = message;
       }
      
       // The printMessage operation
       public void printMessage()
       {
       log.info(message);
       }
      
       // The lifecycle
       protected void startService() throws Exception
       {
       log.info("Starting with message=" + message);
       }
       protected void stopService() throws Exception
       {
       log.info("Stopping with message=" + message);
       }
      }
      


      The notification Listener (also taken from wikis) extends ListenerServiceMBeanSupport

      public class NotificationListener
       extends ListenerServiceMBeanSupport
       implements NotificationListenerMBean
      {
       // Constructors --------------------------------------------------
       /**
       * CTOR
       **/
       public NotificationListener()
       {
       // empty
       }
      
       // NotificationListenerMBean implementation ----------------------
       // No attributes or operations in this example to implement!
      
       // Lifecycle control (ServiceMBeanSupport) -----------------------
       /**
       * Start
       **/
       public void startService()
       throws Exception
       {
       // subscribe for notification, true=dynamic
       super.subscribe(true); // listener is me!
       }
      
       /**
       * Stop
       **/
       public void stopService()
       throws Exception
       {
       // unsubscribe for notifications
       super.unsubscribe();
       }
      
       // ListenerServiceMBeanSupport override ------------------------
       /**
       * Overriden to add handling!
       **/
       public void handleNotification2(Notification notification, Object handback)
       {
       log.info("Got notification: " + notification + ", handback: " + handback);
       }
      
      
      }


      Then I've tried to adapt the service xml file so that it receives notifications from the domain com.sample.jmx:


      <mbean code="com.sample.jmx.StartupService" name="com.packtpub.jmx:service=StartupClass">
       <attribute name="Message">Hello World</attribute>
       </mbean>
      
       <server>
       <mbean code="jboss.example.NotificationListener"
       name="jboss.example:name=NotificationListener">
      
       <attribute name="SubscriptionList">
       <subscription-list>
       <mbean name="*:service=invoker,*" handback="anObject"></mbean>
       <mbean name="com.sample.jmx:*"></mbean>
      
       <notification type="JBOSS_MONITOR_NOTIFICATION"></notification>
       <mbean name="JMImplementation:type=MBeanServerDelegate">
       <notification type="JMX.mbean.registered"></notification>
       </mbean>
       </subscription-list>
       </attribute>
       </mbean>
       </server>


      Unfortunately I don't receive any notification when the method printMessage is invoked....have you got any idea what's wrong?
      JBoss release used 5.0.0 GA with JDK 1.6
      Thanks a lot
      John

        • 1. Re: Receiving notification from other MBeans
          Dimitris Andreadis Master

          Your subscription list is wrong, so try an mbean descriptor like this:

          <mbean code="com.sample.jmx.StartupService" name="com.packtpub.jmx:service=StartupClass">
           <attribute name="Message">Hello World</attribute>
           </mbean>
          
           <server>
           <mbean code="jboss.example.NotificationListener"
           name="jboss.example:name=NotificationListener">
          
           <attribute name="SubscriptionList">
           <subscription-list>
           <mbean name="com.packtpub.jmx:service=StartupClass"/>
           </subscription-list>
           </attribute>
           </mbean>
           </server>
          

          Your StartupClass does not emit any custom notification to show in your listener. The only notification that should come up are the ones from the base ServiceMBeanSupport class.

          • 2. Re: Receiving notification from other MBeans
            Dimitris Andreadis Master

            Also the 'server' tag is at the wrong place. It should appear in the top.