0 Replies Latest reply on Jul 22, 2002 3:02 AM by Kashif Rasheed

    Error receiving notification

    Kashif Rasheed Newbie

      Hi JBoss Gurus;

      Following is the code;

      **********************************************************
      **********************************************************
      package com.netpace.wireless.agents;

      import java.util.Iterator;

      import javax.management.MBeanServer;
      import javax.management.MBeanInfo;
      import javax.management.ObjectName;
      import javax.management.MalformedObjectNameException;
      import javax.management.MBeanServerFactory;
      import javax.management.RuntimeMBeanException;
      import javax.management.MBeanException;
      import javax.management.MBeanAttributeInfo;
      import javax.management.monitor.StringMonitor;
      import javax.management.monitor.MonitorNotification;
      import javax.management.NotificationListener;
      import javax.management.Notification;
      import javax.management.Attribute;
      import javax.management.AttributeList;
      import javax.management.MBeanNotificationInfo;
      import javax.management.ObjectInstance;

      import org.jboss.jmx.connector.rmi.RMIConnectorImpl;
      import org.jboss.jmx.connector.RemoteMBeanServer;
      import org.jboss.jmx.connector.notification.RMIClientNotificationListener_Stub;
      import org.jnp.interfaces.NamingContextFactory;
      import org.jboss.jmx.adaptor.rmi.RMIAdaptor;

      import javax.naming.Context;
      import javax.naming.InitialContext;

      import java.util.Hashtable;

      public class JMSAgent implements NotificationListener{
      JMSNotifyListener notificationListener = new JMSNotifyListener();
      private static RMIConnectorImpl server = null;
      private static ObjectName monitorName = null;
      private static JMSAgent jmsAgent = new JMSAgent();

      public JMSAgent() {
      }
      public static void main(String[] args){

      try{
      System.out.println("Setting Naming Context");

      InitialContext initialContext = null;

      System.setProperty(Context.PROVIDER_URL,"jnp://202.125.129.86:1099");
      System.setProperty(Context.INITIAL_CONTEXT_FACTORY ,"org.jnp.interfaces.NamingContextFactory");
      System.setProperty(Context.URL_PKG_PREFIXES ,"org.jboss.naming:org.jnp.interfaces");

      System.out.println("Creating RMI Connector");
      try{
      server = new RMIConnectorImpl(RMIConnectorImpl.NOTIFICATION_TYPE_RMI,null, "zealous");
      }catch(Exception e)
      {
      System.out.println("Error getting connector instance.. : " + e.getMessage());
      e.printStackTrace();
      }


      System.out.println("Creating String monitor");
      monitorName = new ObjectName("jboss.test:service=StringMonitor");
      if (!server.isRegistered(monitorName))
      {
      server.createMBean("javax.management.monitor.StringMonitor" , monitorName);
      }

      System.out.println("Configurng string Monitor");

      ObjectName mbeanObjName = new ObjectName("jboss.mq:service=JMSProviderLoader,name=JBossMQProvider");

      AttributeList attributes = new AttributeList();

      attributes.add(new Attribute("ObservedObject", mbeanObjName));
      attributes.add(new Attribute("ObservedAttribute", "StringState"));
      attributes.add(new Attribute("StringToCompare", "Stopped"));
      attributes.add(new Attribute("NotifyMatch", new Boolean(true)));
      attributes.add(new Attribute("GranularityPeriod", new Long(10000)));

      server.setAttributes(monitorName , attributes);
      server.invoke(monitorName , "start",new Object[0] ,new String[0] );

      System.out.println("Starting to listen ........");

      server.addNotificationListener(monitorName , jmsAgent, null , null);

      } catch(Exception e)
      {
      System.out.println("Exception ....... : " + e.getMessage());
      e.printStackTrace();

      }
      }

      public void handleNotification(Notification JMSNotification , Object HandBackObj){
      System.out.println("Notification occured ......");
      }
      }

      **********************************************************
      **********************************************************

      And here's the output

      /////////////////////////////////////////////////////////
      /////////////////////////////////////////////////////////

      Setting Naming Context
      Creating RMI Connector
      RMIClientConnectorImp.start(), got Naming Context: javax.naming.InitialContext@360be0, environment: {java.naming.provider.url=202.125.129.86:1099, java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory, java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces:org.jboss.naming:org.jnp.interfaces}, name in namespace:
      RMIClientConnectorImpl.start(), got remote connector: org.jboss.jmx.adaptor.rmi.RMIAdaptorImpl_Stub[RemoteStub [ref: [endpoint:[202.125.129.86:1485](remote),objID:[4b6009:ef30955971:-8000, 3]]]]Creating String monitor
      Configurng string Monitor
      Starting to listen ........

      /////////////////////////////////////////////////////////
      /////////////////////////////////////////////////////////

      The bold area of the output message is displayed in JBuider in red which means there's an error getting notification.
      I have verified that the listener and MBean has been registered to the MBeanServer but it's not returing the notification to handleNotification if I changes the StringState from Started to Stopped.

      Please help me....

      Bu Bye.