3 Replies Latest reply on Apr 24, 2009 4:11 AM by ghinkle

    Set additional classpath for my own MBeanResourceComponent

    jim.ma

      I wrote a rhq plugin to monitor my application deployed in jbossAS server through JMX. In the plugin configuration file , I have something like this :

      <plugin..>
       <depends plugin="JMX" />
       <depends plugin="Tomcat" />
       <depends plugin="JBossAS" useClasses="true"/>
      
       <service name="ESB"
       discovery="org.rhq.plugins..HelloWorldDiscoveryComponent"
       class="org.rhq.plugins.HelloWorldComponent"
       description="Hello World rhq plugin"
       singleton="true">
       <runs-inside>
       <parent-resource-type name="JBossAS Server" plugin="JBossAS"/>
       </runs-inside>


      The HelloWorldDiscoveryComponent extends MBeanResourceDiscoveryComponent and HelloWorldComponent extends MBeanResouceComponent . In HelloWorldComonent , I would like to monitor a field defined in my own class foo.MyValue . The MyValue object can be retrieved through JMX method getValue() :
      MyValue getValue() {
       return value;
       }


      I added the foo.MyValue to the lib directory in my plugin . But the EmsConnection from pararentResouceComponent can not load that class.
      I saw there is "additionalClassPathEntries" configuration for JMXServerDisocveryComponent . How can I do the same thing for my plugin ? How can I add the classes under plugin lib directory to the EmsConnection settings ?

      Thanks in advance .




        • 1. Re: Set additional classpath for my own MBeanResourceCompone
          mazz

          First, I believe you must package your third-party or custom classes into .jar files (you cannot put .class files directly in the plugin's lib directory).

          To learn how to use the additional class path entries property, see these:

          http://management-platform.blogspot.com/2008/11/monitoring-hibernate-with-jopr.html
          http://support.rhq-project.org/display/RHQ/Plugins+-+Demos+-+Monitoring+Hibernate
          http://jira.rhq-project.org/browse/RHQ-1094

          Because your service is injected directly in a JBossAS server, I'm wondering if we'll need to do something extra. The connection properties that you use to connect to JBossAS are different than those when connecting to a generic VM. I'm thinking we might need to add the ability to add additional classpath entries to JBossAS connection properties. Its late and I can't think straight :) read those URLs above and see if you can do the same. I'm not sure if you can tell the JBoss plugin to add arbitrary jars to the classpath of the EMS connection today, but if you can't it shouldn't be hard to add another plugin-configuration simple-property to the jboss plugin rhq-plugin.xml descriptor to enable this.

          • 2. Re: Set additional classpath for my own MBeanResourceCompone
            jim.ma

            Thanks for your quick reply, Mazz.
            So far there is no code to handle adding classpath entry to EMSconnection in jboss plugin, so it looks like we can not enable it by adding a simple-property in rhq-plugin.xml .

            When we add the adding classpath entry function to jboss plugin , how can we enable EMSConnection to load a class in a nested jar (in the custom jar file packaged in plugin) ? At present whether ChilldFirstClassLoader or URLClassLoader working with EmsConnection can not load this kind of class . Is it possible to set the current plugin classloader to EmsConnection dynamically before retrieve the MyValue object through jmx?

            • 3. Re: Set additional classpath for my own MBeanResourceCompone
              ghinkle

              If you need custom connection properties and classes you can build your own EMS connection rather than trying to use the parent plugin component's. You should be able to use the AS plugin as an example of how to do that.

              After connectionFactory.discoverServerClasses is run you can add jar paths to the ConnectionSettings classPathEntries

              -Greg