4 Replies Latest reply on Nov 7, 2003 4:28 PM by sys user

    trying to register mbean - not showing up in jmx-console

    sys user Master

      Hi - I'm trying to extend a message driven bean such that I can get some statistics using jmx.

      Here is the implementation -

      // MdbBean.java
      // Message Driven bean
      package testmdb;

      import javax.ejb.EJBException;
      import javax.ejb.MessageDrivenBean;
      import javax.ejb.MessageDrivenContext;
      import javax.jms.Message;
      import javax.jms.MessageListener;
      import javax.jms.TextMessage;
      import javax.jms.JMSException;
      import javax.management.ObjectName;
      import javax.management.MBeanServer;
      import javax.management.MBeanServerFactory;

      public class MdbBean implements MessageDrivenBean,
      MessageListener,
      MdbBeanMBean
      {

      private transient MessageDrivenContext mdbContext;
      private int messagesProcessed = 0;
      private int instances = 0;
      private static MBeanServer _server = null;
      private static ObjectName _objectName = null;

      // ------------------------------------------------------------------
      // MessageDrivenBean implementation
      // ------------------------------------------------------------------

      /**
      * Default constructor
      *
      */
      public MdbBean()
      {

      }

      public void setMessageDrivenContext(MessageDrivenContext ctx)
      {
      System.out.println( "MdbBean setMessageDrivenContext");
      mdbContext = ctx;
      }

      public void ejbRemove()
      {
      System.out.println( "MdbBean ejbRemove");
      }

      public void ejbCreate()
      {
      if (_server==null)
      {
      _server = MBeanServerFactory.createMBeanServer();
      try
      {
      _objectName = new ObjectName("jboss:type=mdb,name=test_mbean");
      _server.registerMBean((Object)this,_objectName);
      }
      catch (Exception ex)
      {
      System.err.println("Exception caught: "+ex);
      throw new EJBException (ex);
      }
      }
      System.out.println( "MdbBean ejbCreate");
      }
      /*
      public static MBeanServer getMBeanServer()
      {
      return _server;
      }
      */

      /**
      * onMessage method
      */
      public void onMessage(Message message)
      {
      messagesProcessed++;
      System.out.println( "MdbBean onMessage");
      try
      {
      TextMessage mess = (TextMessage)message;
      System.out.println( "Message received: "+mess.getText());
      }
      catch(JMSException ex)
      {
      System.err.println("Exception caught: "+ex);
      }
      }

      // JMX functions
      public int getNumberMessagesProcessed()
      {
      return messagesProcessed;
      }

      public int getNumberInstances()
      {
      return instances;
      }
      }


      It seems to build and load fine but I can't see it in the jmx-console web page - am I doing something wrong? or missing some configuration step?

      Thanks in advance,
      H