6 Replies Latest reply on Jun 22, 2005 3:11 AM by opiegai

    MBean with plugins

    jimdwyer

      I need to create and MBean with plugins. I have looked at passing the plugin info into the MBean using the attributes in the -service.xml and that is very clumsy and rigid as there may be 1 to n plugins. I looked at the xmbean-dd xmbean-code and they don't seem to fit my needs. What is the best way to add plugins to an MBean in jboss? Is modifying the jboss-service.xml and related .dtd the way to go? Any suggestions would be helpful.

      Thanks

      Jim

        • 1. Re: MBean with plugins
          dimitris

          A common pattern is to have an attribute of type String containing the full class name of a class implementing some interface of yours that you instantiate in the mbean.

          Just be carefull when loading the class:

          http://wiki.jboss.org/wiki/Wiki.jsp?page=HowCanIDynamicallyLoadClassesWithinAnMBean

          If you want to have many of them, why not using an attribute of type String[]?

          In any case, no need to change any dtds, whatsoever...

          • 2. Re: MBean with plugins
            jimdwyer

            Cool. I will check it out. Editing the DTD was a last resort and not something I really wanted to do.

            • 3. Re: MBean with plugins
              jimdwyer

              dimitris,

              The plugins are not only classnames but also the class arguments. Basically I want to be able to instantiate classes using a specific constructor. All passed in through the -service.xml file.


              Jim

              • 4. Re: MBean with plugins
                dimitris

                Then you'll have a problem. I guess there are 3 solutions.

                1) Make the plugins mbeans (or xmbeans) themselves, so you can create them using any constructor (the -service.xml syntax permits this). Then make the central mbean have a dependency list with their ObjectNames:

                 <mbean code="myBean" name="domain:name=x">
                 <depends-list optional-attribute-name="ObjectNameList">
                 <depends-list-element>domain:name=y</depends-list-element>
                 <depends-list-element>domain:name=z</depends-list-element>
                 </depends-list>
                 </mbean>
                


                This has the advantage of the plugins being manageable as well.

                2) Have an attribute of type org.w3c.dom.Element that supports your own arbitrary format for specifying classes and constructors parameters. You'll then have to parce that dom Element and do whatever (instantiate and initialize the mbean. As an example see how the SubscriptionList attribute is parsed in class org.jboss.system.ListenerServiceMBeanSupport, or look at how org.jboss.system.ServiceConfiguration is implemented.

                3) Wait a few months for the new JBoss MicroContainer that will let you do (1) but without actually the mbean requirement.

                • 5. Re: MBean with plugins
                  jimdwyer

                  Sounds like I need a MagicBean!

                  • 6. Re: MBean with plugins

                    The plugins could be MBeans as well and register with the Mbean using the plugins.

                    You would need a register/deregister fuction like this:

                    register( IPlugin p );
                    deregister( IPlugin p );

                    The plugin MBean would call these functions and pass itself.