5 Replies Latest reply on Dec 2, 2004 2:14 AM by warren1

    How to dynamically create a standard MBean

    warren1

      I'm trying to create an MBean to monitor a jsp form bean. As a first step I created a simple hello world MBEAN.

      First I created an interface class :

      public interface EmailConfigFormMBean {
      public String getHewwwo();
      }

      Next an implementation :

      public class EmailConfigFormMBeanImpl implements EmailConfigFormMBean {
      public String getHewwwo() {
      return "hewwwwo";
      }
      }

      I created some code in my form bean to instantiate an MBean and TRY to register it :

      List srvrlist = MBeanServerFactory.findMBeanServer(null);
      MBeanServer server = (MBeanServer)srvrlist.iterator().next();

      ObjectName name = new ObjectName("user:name=EmailConfigForm");
      EmailConfigFormMBeanImpl emb = new EmailConfigFormMBeanImpl();
      try {
      //
      server.registerMBean(emb, name);
      } catch (InstanceAlreadyExistsException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      throw e;
      } catch (MBeanRegistrationException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      throw e;
      } catch (NotCompliantMBeanException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      throw e;
      }

      Everything works except the registerMBean call. It always throws a
      NotCompliantMBeanException Class does not expose a management interface: java.lang.Object

      Why should it care about java.lang.Object ?? I just want a simple MBean (not a jboss service).

      Can anyone help me.

      Thanx
      Warren Roberts

        • 1. How to dynamically create a standard MBean
          dimitris

          I'm trying to create an MBean to monitor a jsp form bean. As a first step I created a simple hello world MBEAN.

          First I created an interface class :

          public interface EmailConfigFormMBean {
          public String getHewwwo();
          }

          Next an implementation :

          public class EmailConfigFormMBeanImpl implements EmailConfigFormMBean {
          public String getHewwwo() {
          return "hewwwwo";
          }
          }

          I created some code in my form bean to instantiate an MBean and TRY to register it :

          List srvrlist = MBeanServerFactory.findMBeanServer(null);
          MBeanServer server = (MBeanServer)srvrlist.iterator().next();

          ObjectName name = new ObjectName("user:name=EmailConfigForm");
          EmailConfigFormMBeanImpl emb = new EmailConfigFormMBeanImpl();
          try {
          //
          server.registerMBean(emb, name);
          } catch (InstanceAlreadyExistsException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
          throw e;
          } catch (MBeanRegistrationException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
          throw e;
          } catch (NotCompliantMBeanException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
          throw e;
          }

          Everything works except the registerMBean call. It always throws a
          NotCompliantMBeanException Class does not expose a management interface: java.lang.Object

          Why should it care about java.lang.Object ?? I just want a simple MBean (not a jboss service).

          Can anyone help me.

          Thanx
          Warren Roberts

          • 2. Deployment Order
            warren1

            Hi,
            I would like to deploy an mbean "Scheduler" to the deploy-ha-singleton directory, which is dependent from a queue "jms/scheduler/Timer ", which is deployed in deploy/jms directory.

            At the end of jboss (3.2.6) startup I get the following error:

            MBeans waiting for other MBeans:
            ObjectName: cmd.scheduler:service=Scheduler
            state: CONFIGURED
            I Depend On: jboss.mq.destination:service=Queue,name=jms/scheduler/Timer

            Depends On Me:

            MBEANS THAT ARE THE ROOT CAUSE OF THE PROBLEM:
            ObjectName: jboss.mq.destination:service=Queue,name=jms/scheduler/Timer
            state: NOTYETINSTALLED
            I Depend On:
            Depends On Me: cmd.scheduler:service=Scheduler


            How can I configure the ha-singleton directory to be deployed a f t e r the deploy directory? The queue must not be deployes to the ha-singleton/jms directory, because the queue is needed on every jboss node within the cluster, the scheduler mbean has to be a cluster singleton.

            Thanks
            Stefan



            • 3. Re: How to dynamically create a standard MBean
              warren1

              Hmmmm ....

              It doesn't seem to matter what the name of the implementation class is I always get the same error. I've changed the name of the impl class to

              EmailConfigFormMBean
              EmailConfigFormBllahImpl

              I always throws the NonCompliantMBeanException

              The interface does follow the standard mbean pattern. it is IEmailConfigFormMBean

              I thought maybe the actual implementation class needed to end in MBean so as you can see above I tried that as well. It simply won't register my mbean.

              Any help would be appreciated.

              Warren

              • 4. Re: How to dynamically create a standard MBean
                warren1

                I just looked at the MBeanCapability.java file where the exception is being thrown. The strange thing is that it thinks the mbeanClass is java.lang.Object.

                What's up with that??

                Do I need to do a class cast in the register call or something like that?

                Thanx
                Warren

                • 5. Re: How to dynamically create a standard MBean
                  dimitris

                  I'll write that again, if you class is called Z the interface must be called ZMBean

                  So, just change the name of you implementation class to:

                  EmailConfigForm

                  in order to agree with interface name EmailConfigFormMBean