4 Replies Latest reply on Jul 25, 2007 10:14 AM by konkimalla

    user defined mbeans - Notification Broadcaster

    konkimalla

      I am planning to use JBoss JMX Services and create a user defined mbean and make it as a notification broadcaster. I have successfully registered the mbean and can invoke its opreations fromt the Servlet. However, I am getting the following error when trying to register a listener to this mbean:



      17:59:57,250 ERROR [STDERR] javax.management.RuntimeOperationsException
      17:59:57,250 ERROR [STDERR] at org.jboss.mx.server.MBeanServerImpl.addNotifi
      cationListener(MBeanServerImpl.java:739)
      17:59:57,250 ERROR [STDERR] at com.clique.cmg.web.ComputeServlet.init(Comput
      eServlet.java:68)
      17:59:57,250 ERROR [STDERR] at org.apache.catalina.core.StandardWrapper.load
      Servlet(StandardWrapper.java:1161)
      17:59:57,250 ERROR [STDERR] at org.apache.catalina.core.StandardWrapper.allo
      cate(StandardWrapper.java:806)
      17:59:57,250 ERROR [STDERR] at org.apache.catalina.core.StandardWrapperValve
      .invoke(StandardWrapperValve.java:129)
      17:59:57,250 ERROR [STDERR] at org.apache.catalina.core.StandardContextValve
      .invoke(StandardContextValve.java:175)
      17:59:57,250 ERROR [STDERR] at org.jboss.web.tomcat.security.SecurityAssocia
      tionValve.invoke(SecurityAssociationValve.java:179)
      17:59:57,250 ERROR [STDERR] at org.jboss.web.tomcat.security.JaccContextValv
      e.invoke(JaccContextValve.java:84)
      17:59:57,250 ERROR [STDERR] at org.apache.catalina.core.StandardHostValve.in
      voke(StandardHostValve.java:128)
      17:59:57,250 ERROR [STDERR] at org.apache.catalina.valves.ErrorReportValve.i
      nvoke(ErrorReportValve.java:104)
      17:59:57,250 ERROR [STDERR] at org.jboss.web.tomcat.service.jca.CachedConnec
      tionValve.invoke(CachedConnectionValve.java:156)
      17:59:57,250 ERROR [STDERR] at org.apache.catalina.core.StandardEngineValve.
      invoke(StandardEngineValve.java:109)
      17:59:57,250 ERROR [STDERR] at org.apache.catalina.connector.CoyoteAdapter.s
      ervice(CoyoteAdapter.java:241)
      17:59:57,250 ERROR [STDERR] at org.apache.coyote.http11.Http11Processor.proc
      ess(Http11Processor.java:844)
      17:59:57,250 ERROR [STDERR] at org.apache.coyote.http11.Http11Protocol$Http1
      1ConnectionHandler.process(Http11Protocol.java:580)
      17:59:57,250 ERROR [STDERR] at org.apache.tomcat.util.net.JIoEndpoint$Worker
      .run(JIoEndpoint.java:447)
      17:59:57,250 ERROR [STDERR] at java.lang.Thread.run(Thread.java:619)
      17:59:57,250 ERROR [STDERR] Caused by: java.lang.IllegalArgumentException: The M
      Bean named exists but does not implement the NotificationBroadcaster interface.


      I have used the following code in the servlet:


      MBeanServer server = MBeanServerLocator.locate();
      ObjectName broadCaster = new ObjectName("TestJmxBean:service=Jmxcalculate");
      JmxListener listener = new JmxListener();
      server.addNotificationListener(broadCaster, listener, null, null);

      I made sure that the mbean extends JBossNotificationBroadcasterSupport but not sure why it gives the message.

      My fundamental question is can a user defined mbean emit notifications???



        • 1. Re: user defined mbeans - Notification Broadcaster
          dimitris

          You also need declare that the mbean implements the NotificationBroadcaster interface.

          • 2. Re: user defined mbeans - Notification Broadcaster
            konkimalla

            Even after implementing the interface I am getting the same error. Below is the mbean class


            package com.clique.cmg.util;

            import org.jboss.annotation.ejb.Service;
            import org.jboss.annotation.ejb.Management;
            import javax.management.Notification;
            import javax.management.*;
            import org.jboss.mx.util.*;
            import java.util.*;

            @Service (objectName="TestJmxBean:service=Jmxcalculate")
            @Management(JmxCalculatorMBean.class)
            public class JmxCalculator extends JBossNotificationBroadcasterSupport
            implements JmxCalculatorMBean, NotificationBroadcaster {

            int growthrate;
            int result;

            public void setGrowthrate (int growthrate) {
            this.growthrate = growthrate;
            }

            public int getGrowthrate () {
            return growthrate;
            }

            public int calculate (int start, int end) {
            result = growthrate + start + end;
            emitNotification();
            return result;
            }

            // Lifecycle methods
            public void create() throws Exception {

            growthrate = 50;
            System.out.println("Calculator - Creating");

            }

            public void destroy() {
            System.out.println("Calculator - Destroying");
            }

            private void emitNotification() {
            try {
            System.out.println("Send the Notification");
            Notification attribNotify = new Notification("cmg", this, 1L, "Notify the result: " + result);
            sendNotification(attribNotify);
            } catch (Exception e) {
            e.printStackTrace();
            System.out.println("Error in broadcaster");
            }
            }

            }

            • 3. Re: user defined mbeans - Notification Broadcaster
              alokeshweta

              We are also running into the same issue. Did you figure out what was wrong.

              • 4. Re: user defined mbeans - Notification Broadcaster
                konkimalla

                I was tired working on the solution and left it.