9 Replies Latest reply on Sep 13, 2002 5:06 PM by Juha Lindfors

    MBeanRegistration::preRegister ObjectName change

    Tom Elrod Master

      It seems as though the current implementation (within BasicMBeanRegistry) will ignore the ObjectName returned from the call to preRegister() of the MBeanRegistration interface if the ObjectName passed in as a parameter is not null (if null, will use the returned value).

      The spec isn't really clear about this one (see below). I was wondering if reason to do this or if ok to change it so uses the returned ObjectName regardless.

      Thanks.

      -Tom

      ---- spec
      If the MBean developer chooses to implement the MBeanRegistration interface, the following methods must be provided:

      > preRegister - This is a callback method that the MBean server will invoke before registering the MBean. The MBean will not be registered if any exception is raised by this method. This method may throw the MBeanRegistrationException which will be re-thrown as is by the Mbean server. Any other exception will be caught by the MBean server, encapsulated in an MBeanRegistrationException and re-thrown.

      This method may be used to:
      - Allow an MBean to keep a reference on its MBean server.
      - Perform any initialization that needs to be done before the MBean is exposed to management operations.
      - Perform semantic checking on the object name, and possibly provide a name if the object was created without a name.
      - Get information about the environment, for instance, check on the existence of services the MBean depends upon. When such required services are not available, the MBean might either try to instantiate them, or raise a ServiceNotFoundException exception.

        • 1. Re: MBeanRegistration::preRegister ObjectName change
          Juha Lindfors Master

          The implementation is correct as per the javadoc specification of the MBeanRegistration interface. If no object name is specified (null) then then MBean may return a default object name.

          -- Juha


          • 2. Re: MBeanRegistration::preRegister ObjectName change
            Tom Elrod Master

            (already replied once, so if 2 show up, sorry. Jive caching is real pain).

            Ok. Guess this also implies that if the object name is not null, then MBean may not return a default object name (or at least it will be ignored).

            My goal was to be able to have some sort of base MBean class all my other MBeans could extend so that I could append some common information to all the object names of all my MBeans. For example, I might want to append vendor=Acme to all my MBeans. I was hoping to be able to do this in the preRegister() method since it is a central location to do this. You have any other suggestions on another way to do this?

            Thanks.

            -Tom

            • 3. Re: MBeanRegistration::preRegister ObjectName change
              Juha Lindfors Master

              Why do you need to have this information as part of the object name rather than just an attribute of the MBean? Additional benefit of defining an attribute is that you get the query support which object names do not currently have.

              -- Juha

              • 4. Re: MBeanRegistration::preRegister ObjectName change
                Tom Elrod Master

                I think the example of vendor was bad. Vendor would probably be better as an attribute.

                Another reason I would want to have ability to change ObjectName in preRegister() is to change the domain of the object name. This will come in handy in the case of remote MBeans, where I only want to see the MBeans for my domain (especially useful during testing). That way my queries could be scoped to only include the MBeans matching my domain.

                • 5. Re: MBeanRegistration::preRegister ObjectName change
                  Juha Lindfors Master

                  Not quite sure I got this second example either... but anyway

                  If you really want to change the behavior you can always plug in your own registry implementation. Should be a simple matter of "extends" of BMR where you replace the part that deals with ObjectName handling.

                  (we might want to break that logic down into more methods in future so doing this type of thing becomes easier... IIRC there's a quite a chunk you need to override now.. oh well, copy paste works)

                  -- Juha

                  • 6. Re: MBeanRegistration::preRegister ObjectName change
                    Jeff Haynie Newbie

                    OK, we extended BasicMBeanRegistry (cut and paste style as suggested) and added the system property jbossmx.mbean.registry.class to the run.bat. I copied the JAR that contains that class in the /lib directory and it can't seem to find my class. Moving the lib under server/lib didn't help either. If I added my jar to the classpath in run.bat (not ideal), it found it, but can't find org/jboss/mx/server/registry/MBeanRegistry now.

                    Any pointers on where I need to stick my jar? Seems like it ignores it if in /lib.

                    • 7. Re: MBeanRegistration::preRegister ObjectName change
                      Jeff Haynie Newbie

                      (if this is a duplicate post, sorry, jives doesn't seem to be working on my post)

                      OK, we extended BasicMBeanRegistry (cut and paste style as suggested) and added the system property jbossmx.mbean.registry.class to the run.bat. I copied the JAR that contains that class in the /lib directory and it can't seem to find my class. Moving the lib under server/lib didn't help either. If I added my jar to the classpath in run.bat (not ideal), it found it, but can't find org/jboss/mx/server/registry/MBeanRegistry now.

                      Any pointers on where I need to stick my jar? Seems like it ignores it if in /lib.

                      • 8. Re: MBeanRegistration::preRegister ObjectName change
                        Jeff Haynie Newbie

                        OK - figured it out using -L


                        I'm going to refactor to BasicMBeanRegistry to make it subclass friendly.

                        Juha, is it ok if I have Tom commit that to HEAD once we have it implemented and tested?

                        • 9. Re: MBeanRegistration::preRegister ObjectName change
                          Juha Lindfors Master

                          yes it's ok =)

                          thank you for contributing