12 Replies Latest reply on Dec 7, 2001 9:12 PM by juha

    mbeaninfo with standard mbeans

    jmntn2000

      Hi,

      With standard mbeans how would one go about adding descriptions for the managment applications from inside the mbean itself. With dynamic mbeans there is a method that returns the mbeaninfo class that would contain the description to be displayed to the user, but I don't see how to do that for standard mbeans that use introspection? Am I missing something or do I have to go through the trouble of implementing a dynamic mbean for this functionallity?

      Thanks
      James

        • 1. xmbean and jmxdoclet task

          Hi,

          I have added the xdoclet tags (like @jmx:mbean) in my java code and am trying to generate the xmbean files using the following ant task.

          <!-- Generate mbeans with XDoclet -->











          The above ant task does not throw any error (even in debug mode), but also does not generate the *xmbean.xml files.

          However the same task (with instead of ) is generating the Mbean interface.

          Any ideas?

          -A

          • 2. Re: mbeaninfo with standard mbeans
            user57

            I am not 100% on this, but I don't think that this is possible with standard mbeans.

            --jason

            • 3. Re: mbeaninfo with standard mbeans

              Jason is correct, there is no way to do this with Standard MBeans. So you have to use MBeans that implement the DynamicMBean interface (Dynamic or Model MBeans).

              The good news is the metadata can be generated (read from a file, DB, etc), so you will not have to write all of the implementation by yourself. There's a Model MBean implementation that generates the metadata from an XML coming up for JBossMX (Real Soon Now, aiming for this weekend) which takes most of the burden of implementing DynamicMBean interface from you.

              • 4. Re: mbeaninfo with standard mbeans
                simone

                It is possible, as extension to the JMX spec, to have also std mbeans with descriptions.
                The feature would work this way: following a lexical pattern similar to std MBean, the MBeanServer looks, for mbean MyService, for a class called MyServiceMBeanDescription, that implements a jbossmx interface. If it founds it (same rules as finding MyServiceMBean interfaces) then before creating the metadata, the MBeanServer calls this class to obtain descriptions for the std MBean.
                Will be portable across JMX impl (ignored if not supported), and gives a real plus for the management applications, since std mbeans are simple to write WRT dynamic, and IMHO more type safe.
                The MBeanDescription interface will have methods like
                String getAttributeDescription(Method m) or
                String getOperationParameterName(Method m, index i)
                and there can be an adaptor already given that returns default values:
                String getOperationParameterName(Method m, index i) {return "param" + (i + 1);}

                • 5. Re: mbeaninfo with standard mbeans

                  Yes,

                  It is possible.

                  But like you said, this will work only on server implementations that do reflect on the resource for the specific methods.

                  A better approach, in my opinion, is to add a metadata generation to a model mbean implementation that follows the standard mbean conventions on the resource class interface (and any possible extensions). This works better across servers, and is just as convenient as using a standard mbean.

                  Standard MBeans as defined today in the JMX spec really aren't useful for much more than prototyping (again IMHO). They would be much more useful if the standard conventions allowed a getMBeanDescriptors() (or similar) method to be added to the standard MBean interface which would do a merged metadata generation from both the introspected properties and the explicit ones exposed by the getMBeanDescriptors() method.

                  Luckily, all this can be achieved with MMBean without sacrificing the convenience of the standard mbeans (which is their only advantage as far as I can see).

                  • 6. Re: mbeaninfo with standard mbeans
                    marc.fleury


                    > Luckily, all this can be achieved with MMBean without
                    > sacrificing the convenience of the standard mbeans
                    > (which is their only advantage as far as I can see).

                    as I write my 10023 standard mbean,

                    it is a pretty big advantage, if you can duplicate that it will be good,

                    ease of programming is a bit of a mantra around here as you know.

                    • 7. Re: mbeaninfo with standard mbeans
                      simone

                      Agree with you on getMBeanDescriptor (that breaks the lexical pattern MBean-interface however. Not sure if it makes any difference however).
                      Don't follow on the MMB. Can you expand with example ? Say MyService, MyServiceMBean, how do I specify the description for constructor arguments with the MMB ?

                      • 8. Re: mbeaninfo with standard mbeans

                        There is not much duplication to be done. That is exactly what the MBean server has to do. It takes a java interface and turns it into MBeanInfo. So you do the same thing in the model mbean to the resource reference.

                        That already happens in the JBossMX. Any standard MBean you register will be generated into a dynamic mbean which is always used internally. The metadata generation is done via a MetaDataBuilder interface implementation. The model mbean implementation can have any MetaDataBuilder instance plugged into it.

                        • 9. Re: mbeaninfo with standard mbeans
                          simone

                          Uhm, interesting, but I did not got everything yet.
                          In my idea, you ship 3 classes, MyService, MyServiceMBean and MyServiceMBeanDescription.
                          The first is the mbean and it is registered. The third is not an mbean, it's not registered, just there to be loaded by the MBeanServer that supports it. Yes, if not supported, you can't see descriptions.
                          I still don't get how in your case
                          MBeanServer.getMBeanInfo(myStdMBeanObjName) will return the MBeanInfo with the description of the std mbean without extending the MBeanServerImpl functionality. Ah, well, will wait till Monday :)

                          • 10. Re: mbeaninfo with standard mbeans

                            [I]MBeanServer.getMBeanInfo(myStdMBeanObjName) will return the MBeanInfo with the description of the std mbean without extending the MBeanServerImpl functionality. Ah, well, will wait till Monday [/I]

                            It doesn't, if you register your MBean as standard MBean.

                            What I mean to say is, don't use standard MBeans (at all), instead register a model mbean and feed it a resource class that can look like a standard MBean (or the extended version you proposed).

                            standard mbean is a subset of management information that can be represented with a dynamic mbean (and therefore model mbeans). Therefore, if you get the convenience of standard mbean with model mbeans, there is really no reason to use standard mbeans at all.

                            This way you get the extended functionality, keep the standard mbean convenience, and can switch between server implementations.

                            • 11. Re: mbeaninfo with standard mbeans
                              simone

                              ...there is really no reason to use standard mbeans at all. This way you get the extended functionality, keep the standard mbean convenience...

                              Still fighting my way, sorry to be insistent, hope you don't mind :)

                              Can you expand on convenience ? I think std mbean are waaay simpler to code than dynamic and MMB, and since they're more typed, less prone to mistakes discovered only at runtime. So, removing their use, being replaced by a MMB, how will keep their convenience ?

                              So you say take you std, pass it to a special MMB, pass also an XML with description, register the MMB with the obj name used before for the std.
                              How do you enforce std mbean compliance (you don't care, right ?) ?
                              Another thing: you can't register a MMB without having set the ModelMBeanInfo on it (said by the spec, not enforced by RI). This does not allow dynamic registration through management interface of MMB, since it requires preparation.

                              • 12. Re: mbeaninfo with standard mbeans

                                > Can you expand on convenience ?

                                Meaning you don't have to explicitly create the meta data objects (in code), instead you rely on introspection (or xml parsing, or db) to generate it.

                                > I think std mbean are waaay simpler to code than
                                > dynamic and MMB

                                If I can take any Java interface, introspect it, and generate a MBeanInfo out of that Java interface, I really don't see the difference in simplicity (you will have to be more specific what is it that makes coding the standard mbean more simpler).

                                > and since they're more typed

                                There is no difference in compile time type checking as far as I can see. If a resource implements an interface that is used to determine the management interface then the compiler guarantees the methods have concrete implementations.

                                Introspection is used to generate the MBeanInfo and used in invocation in both cases.

                                > less prone to mistakes discovered
                                > only at runtime. So, removing their use, being
                                > replaced by a MMB, how will keep their convenience ?

                                The means to generate the metadata is the same (introspection), the location is just different (server v. MMB).


                                > So you say take you std, pass it to a special MMB,
                                > pass also an XML with description

                                I wouldn't combine these two (both introspection and XML)... if you want to extend the normal standard mbean interface with description (or more likely with Descriptors) just create a new resource type that applies a new set of naming rules to the interface in the model mbean.


                                > How do you enforce std mbean compliance (you don't
                                > care, right ?) ?

                                You enforce it in the metadata generation. When you introspect the interface, and you find it conflicts with standard mbean naming conventions, you throw a NotCompliantMBeanException.

                                > Another thing: you can't register a MMB without
                                > having set the ModelMBeanInfo on it (said by the
                                > spec, not enforced by RI).

                                Applies to all MBeans really. You cannot register an MBean that doesn't expose the metadata in MBeanServer.getMBeanInfo(). With standard MBeans this is always generated by the server. With dynamic (and model) mbeans it can be either generated or explicitly coded.

                                This does not allow
                                > dynamic registration through management interface of
                                > MMB, since it requires preparation.

                                I'm not following you here. What does it not allow?


                                -- Juha