4 Replies Latest reply on May 29, 2003 1:31 PM by Chris Winters

    Decoupled mbean notifications

    Chris Winters Newbie

      Is it possible to register a NotificationListener with the MBean server rather than with an individual MBean? I'd like to receive all notifications from MBeans to tell whether they've started or not for use in a more 'friendly' management console application. To do this I'd like to decouple the listener from the MBeans I'd like to listen for.

        • 1. Re: Decoupled mbean notifications
          Adrian Brock Master

          I wrote something similar to this for jboss4,
          but sadly I deleted it by accident.

          The basic idea is to register with the
          MBeanServerDelegate to learn when MBeans
          are registered/unregistered.

          You can then act as a proxy for all notifications,
          so others can register with you.

          The MBeanServer has add/remove notification
          listener methods where you pass the object name.

          Regards,
          Adrian

          • 2. Re: Decoupled mbean notifications
            Chris Winters Newbie

            Yeah, in my startService() I asked the MBean server for all registered MBeans and then registered myself with them. This seems to work okay for all services present when the server starts but doesn't help when I do a hot deploy of a new or existing service.

            BTW: Right now I'm just surrounding the registration in a try/catch to ignore Runtime/ClassCastExceptions thrown when the returned MBean doesn't implement the NotificationBroadcaster interface. Is it better to do this or to do an 'instanceof' check instead?

            And 'deleted it by accident'? Surely you've drunk the CVS kool-aid by now! :-)

            Thanks for your help.

            • 3. Re: Decoupled mbean notifications
              Adrian Brock Master

              I just ignored mbeans whose getMBeanInfo()
              had no notification info.
              I actually went further and allowed people
              to register listeners against ObjectName patterns
              and/or Notification types.

              I'll have to recreate it when I get time.

              CVS is good, but when you really need it, you
              find you forgot to use it :-)

              A further tip:

              Use
              rm -rf oldjboss*
              not
              rm -rf oldjboss * (NOTE the space)

              Regards,
              Adrian

              • 4. Re: Decoupled mbean notifications
                Chris Winters Newbie

                I've got this working fairly well -- fortunately most of the stuff I care about (EJB JAR, EAR, WAR) is wrapped in one of the Deployer services. So I can register my listener with it and catch all the deploy/undeploy messages even if something is undeployed and redeployed. Cool.

                My next question: looking at the source I see that I can register a listener with the BeanVerifier used by the EJBDeployer to catch spec violation (and other) events. I'd like to be able to either catch these myself or have the EJBDeployer wrap the events in an MBean Notification and forward them on to *its* listeners.

                However, the EJBDeployer creates the verifier, adds its own listener and performs the verification all within create(). This doesn't give me much opportunity to step in! Do you have any advice?

                As for the deletion, I unfortunately witnessed something far worse: one of my colleagues accidentally typed

                rm -rf .*

                and when it didn't return after a four or five seconds immediately stopped it to realize it had climbed up the .. directory 'name' to delete everything in sight. Ouch!