0 Replies Latest reply on Jan 13, 2009 4:30 AM by Mayank Mittal

    Notifications in MBean

    Mayank Mittal Novice

      Hi All,
      I'm facing a unique problem, Basically i'm trying to send & recieve notifications from and within multiple MBean's.
      For this, i tried a lot and even follow the steps specified on wiki ( http://www.jboss.org/community/docs/DOC-9713) . but failed to listen anything.
      I'm using JDK 1.6.0_03 and JBoss 4.2.3. The code is

      package com.aa.trial.mbean;
      
      
      import java.util.Date;
      
      import javax.management.Notification;
      import javax.management.NotificationListener;
      import javax.management.ObjectName;
      
      import org.apache.log4j.Logger;
      import org.jboss.annotation.ejb.Management;
      import org.jboss.annotation.ejb.Service;
      import org.jboss.monitor.services.NotificationListenerMBean;
      import org.jboss.system.ListenerServiceMBeanSupport;
      import org.jboss.system.ServiceMBeanSupport;
      import org.jboss.varia.scheduler.Schedulable;
      
      
      /**
       * TODO: Documentation to be done for type 'Trial'..
       *
       * @author maym
       */
      @Service(objectName = "com.aa.trial.mbean:service=TrialMBeanService")
      @Management(TrialMBean.class)
      public class TrialMBeanService
       extends ListenerServiceMBeanSupport
       implements TrialMBean, NotificationListenerMBean
      {
      
      
       private static Logger aLogger = null;
       private ObjectName anObjectName = null;
      
       static
       {
       aLogger = Logger.getLogger(TrialMBeanService.class);
       }
      
      
       /**
       * TODO: Documentation to be done for constructor 'TrialMBeanService', by 'maym'..
       */
       public TrialMBeanService()
       {
      
       }
      
      
       /**
       * @see com.aa.trial.mbean.TrialMBean#test()
       */
       @Override
       public void test ()
       {
       System.out.println("Hello !!!!!!!!!!!!!!!!!!!!!!! ");
      
       }
      
      
       /**
       * @see org.jboss.system.ServiceMBeanSupport#startService()
       */
       @Override
       protected void startService ()
       throws Exception
       {
       // TODO Auto-generated method stub
       super.subscribe(true);
       }
      
      
       /**
       * @see org.jboss.system.ListenerServiceMBeanSupport#handleNotification2(javax.management.Notification, java.lang.Object)
       */
       @Override
       public void handleNotification2 (Notification anNotification, Object anHandback)
       {
       // TODO Auto-generated method stub
       log.debug("Notification Recieved!!!");
       test();
       }
      
      
       /**
       * @see org.jboss.system.ServiceMBeanSupport#stopService()
       */
       @Override
       protected void stopService ()
       throws Exception
       {
       // TODO Auto-generated method stub
       super.unsubscribe();
       }
      
      
       /**
       * @see org.jboss.monitor.services.NotificationListenerMBean#getDynamicSubscriptions()
       */
       @Override
       public boolean getDynamicSubscriptions ()
       {
       // TODO Auto-generated method stub
       return true;
       }
      
      
       /**
       * @see org.jboss.monitor.services.NotificationListenerMBean#getLogLevel()
       */
       @Override
       public String getLogLevel ()
       {
       // TODO Auto-generated method stub
       return "DEBUG";
       }
      
      
       /**
       * @see org.jboss.monitor.services.NotificationListenerMBean#getNotificationCount()
       */
       @Override
       public long getNotificationCount ()
       {
       // TODO Auto-generated method stub
       return super.getNextNotificationSequenceNumber() - 1;
      
       }
      
      
       /**
       * @see org.jboss.monitor.services.NotificationListenerMBean#getNotificationListener()
       */
       @Override
       public ObjectName getNotificationListener ()
       {
       return anObjectName;
       }
      
      
       /**
       * @see org.jboss.monitor.services.NotificationListenerMBean#setDynamicSubscriptions(boolean)
       */
       @Override
       public void setDynamicSubscriptions (boolean anArg0)
       {
      
      
       }
      
      
       /**
       * @see org.jboss.monitor.services.NotificationListenerMBean#setLogLevel(java.lang.String)
       */
       @Override
       public void setLogLevel (String anArg0)
       {
       // TODO Auto-generated method stub
      
       }
      
       /**
       * @see org.jboss.monitor.services.NotificationListenerMBean#setNotificationListener(javax.management.ObjectName)
       */
       @Override
       public void setNotificationListener (ObjectName anArg0)
       {
       try
       {
       this.anObjectName = anArg0;
       getServer().addNotificationListener(anArg0, this, null, null);
       }
       catch (Exception exception)
       {
       exception.printStackTrace();
       }
       }
      }
      

      MBean Interface is
      package com.aa.trial.mbean;
      
      import org.jboss.annotation.ejb.Management;
      import org.jboss.system.ListenerServiceMBean;
      import org.jboss.system.ServiceMBean;
      
      
      /**
       * Trial MBean
       *
       * @author maym
       */
      @Management
      public interface TrialMBean
       extends ListenerServiceMBean
      {
       /**
       *
       * TODO: Documentation to be done for method 'test', by 'maym'..
       *
       */
       public void test ();
      }
      

      and, jboss-service.xml is

      <?xml version="1.0" encoding="UTF-8"?>
      <server>
       <mbean code="com.aa.trial.mbean.TrialMBeanService" name="com.aa.trial.mbean:service=TrialMBeanService">
       <attribute name="SubscriptionList">
       <subscription-list>
       <mbean name="*:service=invoker,*" handback="anObject"></mbean>
       <mbean name="jboss.monitor:*">
       <notification type="JBOSS_MONITOR_NOTIFICATION"></notification>
       </mbean>
       <mbean name="JMImplementation:type=MBeanServerDelegate">
       <notification type="JMX.mbean.registered"></notification>
       </mbean>
       </subscription-list>
       </attribute>
       </mbean>
       </server>


      Plz. help me to find out the problem...