0 Replies Latest reply on Jul 19, 2002 6:15 AM by krasheed

    Register MBean Listener

    krasheed

      Hi

      I want to create & register MBean listener to the MBeanServer ( JBoss 3.0 Beta ) through RMIAdaptor because I am accessing MBean from remote location.

      Here's the code; Please feed me that what line of code should I write to create & register MBean Listener.
      Please assist me.....
      ________________________________________________________
      ________________________________________________________
      ________________________________________________________

      package com.netpace.wireless.agents;

      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.MBeanNotificationInfo;

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

      import org.jnp.interfaces.NamingContextFactory;

      import java.util.Hashtable;

      import org.jboss.jmx.adaptor.rmi.RMIAdaptor;

      import com.netpace.wireless.agents.JMSNotifyListener;

      public class JMSAgent implements NotificationListener{
      JMSNotifyListener notificationListener = new JMSNotifyListener();

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

      InitialContext initialContext = null;
      Hashtable env = new Hashtable();
      env.put(Context.PROVIDER_URL,"jnp://zealous:1099");
      env.put(Context.INITIAL_CONTEXT_FACTORY ,"org.jnp.interfaces.NamingContextFactory");
      env.put(Context.URL_PKG_PREFIXES ,"org.jboss.naming:org.jnp.interfaces");

      try{
      if (initialContext == null)
      {
      initialContext = new InitialContext(env);
      }
      RMIAdaptor server = (RMIAdaptor) initialContext.lookup("jmx:zealous:rmi");

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

      Object obj = new Object();

      StringMonitor stringMonitor = new StringMonitor();
      stringMonitor.setObservedObject(mbeanObjName);
      stringMonitor.setStringToCompare("Stopped");
      stringMonitor.setObservedAttribute("StateString");
      stringMonitor.setNotifyMatch(true);
      stringMonitor.setGranularityPeriod(10000);

      stringMonitor.start();


      } catch(Exception e){
      System.out.println("Error getting inital Context." + e.getMessage());

      }
      }

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



      Thanx and Bu Bye.