7 Replies Latest reply on Feb 6, 2004 11:01 AM by Juha Lindfors

    Timer MBean Problem

    Roger Tan Newbie

       

      "divine_comedy" wrote:
      Sorry it's a little bit long, you can skip to the Problem section if you want to know what I think the problem is :

      I am experiencing some problems with our MBean ( which acts like a scheduler by depending on the TimerMBean ), this happens after we upgraded to to JBoss 3.x from JBoss 2.4.4 ( we are currently using JBoss 3.2.3, Java 1.4_02 ) :

      The MBean's function is to provide a level of abstraction that would allow people to schedule things either in certain intervals or daily at certain times ( I did not implement this but was called in when this problem occurs, although I think JBoss has this functionality in the scheduler ). Anyway when I schedule things using the scheduled intervals, everything seems to be ok, but if I use the daily at certain times setting, it would not work.

      Here's a brief description of the architecture :
      1. An abtract superclass that implements the scheduling activity ( above ) by using NotificationFilter, etc
      2. Other MBeans would then extend from this abstract superclass.

      I've traced through the problem as best as I can and my suspicion lies with the mechanics of the NotificationFilter. It's my understanding that when you do an addNotificationListener with a filter, that filter is going to be invoked when there's a notification for that listener. The way we implemented our NotificationFilter is by following the example on the JMX book ( by Fleury and Lindfors ) where we construct the Filter by passing in the NotifID we get by adding a Notification to the server and then comparing that ID with the TimerNotification.getIdentificationID method when the isNotificationEnabled is called.

      The Problem as far as I can see is that :
      the Notification is sent, but the correct NotificationFilter is never used such that the Listener never receives any Notification whatsoever. Strangely this works for the interval use case and we use the same NotificationFilter, same type, etc

      Here's a snippet of log that caused my suspicion :

      [createUseSetClockTimes] 22 Added Notification: Thu Jan 22 16:43:00 PST 2004 14

      ( The number at the very back refers to the NotificationId I get from the MBeanServer after calling the addNotification function on the TimerMBean, this NotifID is then passed in to the constructor of my Filter, refer to above for details )

      [createUseSetClockTimes] 22 Added Notification: Thu Jan 22 16:48:00 PST 2004 15


      And then here is where I see that the Notification is sent :

      INFO [NVLScheduledProcess] ===============> [NvlTimerFilter] timer.notification 14 received in filter: 1
      2004-01-22 16:43:01,943 INFO [NVLScheduledProcess] The details of the notification : javax.management.timer.TimerNotification: type=timer.notification.useSetTime source=DefaultDomain:service=timer sequence=2 time=1074818580707 message================> Timer invokes MBean Successfully id=14 userData=null

      14 refers to the TimerNotification.getNotificationID and 1 refers to the FilterID ( which is actually the ID of a NotificationID ).

      I also notice that JBoss keeps using Filters with ID 1, 22, 23, 24 and nothing else which is certainly possible but why not ID 14 for this particular Listener.

      Am I using the TimerMBean wrongly or is this a bug ? Anyone who can shed light on this is highly appreciated.






        • 1. Re: Timer MBean Problem
          Juha Lindfors Master

           

          "juha@jboss.org" wrote:
          Not sure I fully understand the problem you're describing -- you're saying that you register a listener with a filter but that filter is never invoked? Is it invoking no filters at all, or is it invoking a wrong filter?

          Maybe a few code snippets would clarify it.



          • 2. Re: Timer MBean Problem
            Roger Tan Newbie

             

            "divine_comedy" wrote:
            Hi Juha, it seems to be invoking the wrong filter. The mechanics of our TimerMBean 90% resembles the example you have in your book ( JMX ), page 172 to 175, where we invoke the "addNotification" method and then passing the result into a filter which is then registered with a particular listener.

            We have several MBeans that does this, some of which has the correct filter used, or is that coincidence ?

            Thanks




            • 3. Re: Timer MBean Problem
              Roger Tan Newbie

               

              "divine_comedy" wrote:
              Also, can you give a little bit of insight on the mechanics of the JBoss code involved, or the relevant packages ( so that I can take a look at the code as well ). Thanks


              • 4. Re: Timer MBean Problem
                Roger Tan Newbie

                Okay dokay, I finally figured it out after taking a look at the source ( thank God ). I would like to call attention to the following lines on the NotificationBroadcasterSupport class ( addNotificationListener method )

                synchronized (listenerMap)
                {
                Map hbMap = (Map)listenerMap.get(listener);

                if (hbMap != null)
                {
                hbMap.put(handback, filter);
                }
                else
                {
                hbMap = new HashMap();
                hbMap.put(handback, filter);
                listenerMap.put(listener, hbMap);
                }
                }


                It turns out that the code I was tracing through is passing a null handler with several filters so that only the last filter is being used. Maybe I am not understanding the reason for the handler, but shouldn't the MBean be also allowed to have multiple filters without no handler or only one handler ? Maybe a Vector or an Array is more appropriate here somewhat.

                I'll reread my JMX book.

                • 5. Re: Timer MBean Problem
                  Roger Tan Newbie

                  OK, so just took a look at "Java Management Extensions" by J. Stephen Perry and he mentions that it's ok to pass in a null for the handler. So I think this is a JBoss bug.

                  • 6. Re: Timer MBean Problem
                    Roger Tan Newbie

                    I also keep saying handler but it's handback :).

                    • 7. Re: Timer MBean Problem
                      Juha Lindfors Master

                      Yes that does seem like a bug, please submit it through SourceForge.