0 Replies Latest reply on Dec 7, 2010 6:55 AM by Bernhard D

    Q: (JBoss 5.1.0GA) Service POJO cannot act as JMX notification listener?

    Bernhard D Newbie

      Application is running on JBoss 5.1.0GA.Trying to establish a Service POJO, which also is a JMX MBean notification listener.

      I need this for periodic tasks, e.g. writing a statistic to the database.


      This won't work: When having a service xml file, I must omit the @Service annotation

      in the code. If I don't omit it I get a DuplicateBindException - even if service object

      names differ, but its the same code.


      When I omit the annotation, the POJO is not registered as EJB service - thus no

      objects are injected (@Depends, @Persistence context - whatsoever)


      Next I tried to skip the service.xml description and do the notification

      subscription by hand. But in that case, the class is not registered as mbean.

      This becomes obvious as the object name of the MBean Service is

      null causing the subscribe method of ListenerMBeanSupport to fail with a NPE (if .

      On the other hand, JBoss starts the MBean methods like startService or stopService.


      I am a little sceptical, if this behaviour is intended.

      Q: Is this intended? A service POJO cannot act as NotificationListener?


      So I have to do a workaround: Have two components: One MBean just acting listener and looking up the

      EJB POJO via Naming context.

      Q: Is there a better way to do this?


      Any help would be greatly appreciated.


      Below som code/xml snipptes:

      <!-- The hb-service.xml: -->





              <attribute name="SubscriptionList">


                      <mbean name="jboss.monitor:name=Heartbeat,type=Timer"></mbean>               







      // must skip either @Service annot. or the service file - otherwise Duplicate Bind ex

      @Service(name="HeartbeatListener", objectName = "trafficsoft.statistics:service=HeartbeatListener")



      public class HeartbeatListener extends ListenerServiceMBeanSupport implements

          HeartbeatListenerMBean, HeartbeatListenerLocal



        // when having an xml service def, this EM is null


        private EntityManager em;




        public void startService() throws Exception


          //super.subscribe(true);// --> needs an XML description

          // subscr. by hand: super.subscribe throws NPE at line 277! in a debug statement

          // at this time this.getServiceName() returns null? Seems the object is not registered

          NotificationFilterSupport nfss=new NotificationFilterSupport();


          SubscriptionInfo subInfo=new SubscriptionInfo(new ObjectName("jboss.monitor:name=Heartbeat,type=Timer"), null, nfss);

          ArrayList<SubscriptionInfo> slist=new ArrayList<SubscriptionInfo>();


          super.subscribe(slist, true, this.serviceName);