9 Replies Latest reply on Dec 16, 2008 2:06 PM by alesj

    Does the Microcontainer register MBeans that it deploys with

    garymarsh

      I am using the DZone_1_0 demo's JMXMain.java, Main.java, JMXKernel.java, JBossJMXKernel.java along with HDScanner.java and MainDeployerHelper.java to deploy my own MBeans. I am using aop injection to pass the JMXKernel's serviceController in as a parameter to the constructor of my DataManagementServer class (DMServer) a POJO. The MBeans are deployed first and then the DMServer is deployed last. When I access the MBeanServer that is contained in the serviceController I am unable to see any reference to my MBeans when I execute a piece of code like :

      public DataManagementServer(ServiceController sController ) {
      
       mbeanServer =sController.getMBeanServer( );
       Set<ObjectInstance> mBeanObjects = mbeanServer.queryMBeans( null, null );
       Set<ObjectName> mbObjectNames = mbeanServer.queryNames( null, null );
      
       String className = "";
       ObjectName objName = null;
      
       for( ObjectInstance objInst : mBeanObjects ){
      
       associatedType = "";
       className = objInst.getClass( ).getName( );
      
       if( className.contains( "MonitorMgmt" ))
       continue;
      
       if( className.contains("DirMonitor") ){
       objName = objInst.getObjectName( );
      
       associatedType = (String) mbeanServer.invoke( objName, "getAssociateType", null, null );
      
       // do some work
       }
       }
       }
      


      The problem I am running into is, although my MBeans deploy correctly they aren't registered with the MBeanServer. Is this the correct behavior? I thought the MBeans were suppose to be deployed and registered with the MBeanServer. Would this be something that happens in the lower levels of the Microcontainer or should I modify the Demo code to make this happen?

      Regards,
      GMarsh

        • 1. Re: Does the Microcontainer register MBeans that it deploys
          alesj

          I have no problems querying mbeans.
          Just added MBeanServerQuery class

          public class MBeanServerQuery
          {
           private Logger log = Logger.getLogger(getClass());
           private MBeanServer server;
          
           public MBeanServerQuery(MBeanServer server)
           {
           if (server == null)
           throw new IllegalArgumentException("Null server");
          
           this.server = server;
           }
          
           @SuppressWarnings("unchecked")
           public Set<ObjectName> executeQuery(ObjectName name, QueryExp exp)
           {
           return server.queryNames(name, exp);
           }
          
           public void start()
           {
           Set<ObjectName> currentMBeans = executeQuery(null, null);
           log.info("Listing all mbeans:");
           int count = 0;
           for (ObjectName on : currentMBeans)
           {
           log.info((++count) + ". " + on);
           }
           }
          }
          

          with -beans.xml file
          <deployment xmlns="urn:jboss:bean-deployer:2.0">
          
           <bean name="MBeanServerQuery" class="org.jboss.demos.models.jmx.MBeanServerQuery">
           <constructor>
           <parameter><inject bean="JMXKernel" property="mbeanServer"/></parameter>
           </constructor>
           </bean>
          
          </deployment>
          

          into demos trunk:
          - http://anonsvn.jboss.org/repos/jbossas/projects/demos/microcontainer/trunk/

          And the log output
          JBoss-MC-Demo INFO [13-12-2008 11:14:00] MBeanServerQuery - Listing all mbeans:
          JBoss-MC-Demo INFO [13-12-2008 11:14:00] MBeanServerQuery - 1. jboss.pojo:name='AnnotatedJMXPojo'
          JBoss-MC-Demo INFO [13-12-2008 11:14:00] MBeanServerQuery - 2. jboss.demos:service=ExposedPojo
          JBoss-MC-Demo INFO [13-12-2008 11:14:00] MBeanServerQuery - 3. jboss.classloader:system=29367209,domain="DefaultDomain"
          JBoss-MC-Demo INFO [13-12-2008 11:14:00] MBeanServerQuery - 4. jboss.security:service=XMLLoginConfig
          JBoss-MC-Demo INFO [13-12-2008 11:14:00] MBeanServerQuery - 5. jboss.pojo:name='XmlJMXPojo'
          JBoss-MC-Demo INFO [13-12-2008 11:14:00] MBeanServerQuery - 6. JMImplementation:type=MBeanServerDelegate
          JBoss-MC-Demo INFO [13-12-2008 11:14:00] MBeanServerQuery - 7. jboss.classloader:id="vfszip:/C:/projects/demos/sandbox/jboss-demos-models.jar"
          JBoss-MC-Demo INFO [13-12-2008 11:14:00] MBeanServerQuery - 8. jboss.classloader:service=ClassLoaderSystem
          JBoss-MC-Demo INFO [13-12-2008 11:14:00] MBeanServerQuery - 9. JMImplementation:service=LoaderRepository,name=Default
          JBoss-MC-Demo INFO [13-12-2008 11:14:00] MBeanServerQuery - 10. jboss.security:service=SecurityConfig
          JBoss-MC-Demo INFO [13-12-2008 11:14:00] MBeanServerQuery - 11. JMImplementation:type=MBeanRegistry


          • 2. Re: Does the Microcontainer register MBeans that it deploys
            garymarsh

            AlesJ.

            Ok.. I added the start() method and executed the queryName() call from inside this method printed out the ObjectNames and I don't see the two MBeans I deployed in my nichpro-beans.xml configuration file.

            DataManagementServer. java code :

            public class DataManagementServer {
            
             private MBeanServer mbeanServer = null;
            
             private static final String MONITOR_MANAGER = "MonitorMgmt";
            
             static Logger logger = Logger.getLogger( DataManagementServer.class );
            
             // ////////// End of MBeanReg Declaration ////////////////
             public DataManagementServer(MBeanServer mbeanServer ) {
            
             this.mbeanServer = mbeanServer;
            
             }
            
             public void start() {
             System.out.println("Starting DataManagementServer....");
            
             Set<ObjectName> mbObjectNames = mbeanServer.queryNames( null, null );
            
             int cnt = 1;
             for( ObjectName on : mbObjectNames){
             System.out.println("ObjectName "+ (cnt++) +" ="+ on);
             }
            
            
             }
            


            The nichpro-beans.xml code :

            <deployment xmlns="urn:jboss:bean-deployer:2.0">
            
             <!-- -->
            
             <bean name="DataProc" class="com.nichpro.jmx.processing.data.DataProc" >
             <property name="associatedType">DataDirMonitor</property>
             </bean>
            
             <bean name="DataDirMonitor" class="com.nichpro.jmx.scandir.monitor.data.DataDirMonitor" >
             <constructor>
             <parameter>/NichPro/NP_ScanDirectory/Data</parameter>
             </constructor>
             <property name="associatedType">DataProc</property>
             </bean>
            
             <bean name="DMServer" class="com.nichpro.jmx.server.DataManagementServer">
             <constructor>
             <parameter><inject bean="JMXKernel" property="mbeanServer"/></parameter>
             </constructor>
             </bean>
            
            </deployment>
            
            


            I placed a start() method in each of the MBeans that I created (DataProc and DirMonitor) and printed out that it is started so I could be sure it actually started and this is the output :


            Using bootstrap: file:/C:/NichPro/MicrocontainerDirectoryScanner/src/META-INF/bootstrap-beans.xml
            Deployed URL: file:/C:/NichPro/MicrocontainerDirectoryScanner/src/META-INF/system-jmx-beans.xml
            Deployed URL: file:/C:/NichPro/MicrocontainerDirectoryScanner/src/META-INF/aop-beans.xml
            Starting DataProc...
            I am monitoring /NichPro/NP_ScanDirectory/Data directory.
            Starting DirMonitor...
            Data Directory is empty....
            Going to sleep for 15 minutes now....
            Starting DataManagementServer....
            ObjectName 1 =JMImplementation:type=MBeanRegistry
            ObjectName 2 =jboss.classloader:service=ClassLoaderSystem
            ObjectName 3 =JMImplementation:service=LoaderRepository,name=Default
            ObjectName 4 =JMImplementation:type=MBeanServerDelegate
            Deployed URL: file:/C:/NichPro/MicrocontainerDirectoryScanner/src/META-INF/nichpro-beans.xml


            As I mentioned before even though it appears that the DataProc and DirMonitor MBeans were deployed they do not appear in the Set returned by the call to mbeanServer.queryName() .

            I hope this makes my dilemma more understandable. I need to have access and association of these MBeans to the MBeanServer so I can use the MBean notification functionality. So how do I get this association?

            Regards,
            GMarsh

            • 3. Re: Does the Microcontainer register MBeans that it deploys
              alesj

               

              "Gary Marsh" wrote:

              I don't see the two MBeans I deployed in my nichpro-beans.xml configuration file

              -beans.xml files don't register things as mbeans,
              unless you explicitly use @JMX annotation.
              The services are plain pojos/beans in MC.

              Either use legacy -service.xml or add @JMX annotation to your beans.
              Check demos code on how to do this.

              • 4. Re: Does the Microcontainer register MBeans that it deploys
                garymarsh

                AlesJ.

                OK, let's say I go the -service.xml route, what parses this file? Currently I am parsing my -beans.xml files through Main.deploy() and this throws a parse error on my -sevice.xml file. So either I have an error in my .xml file or I need a different parser.

                here is my nichpro-service.xml file :

                <?xml version="1.0" encoding="UTF-8"?>
                <server>
                 <mbean name="nichpro:service=DataProc" code="com.nichpro.jmx.processing.data.DataProc" >
                 <property name="associatedType">DataDirMonitor</property>
                 </mbean>
                
                 <mbean name="nichpro:service=DataDirMonitor" code="com.nichpro.jmx.scandir.monitor.data.DataDirMonitor" >
                 <constructor>
                 <parameter>/NichPro/NP_ScanDirectory/Data</parameter>
                 </constructor>
                 <property name="associatedType">DataProc</property>
                 </mbean>
                
                 <mbean name="nichPro:service=DMServer" code="com.nichpro.jmx.server.DataManagementServer">
                 <constructor>
                 <parameter><inject bean="JMXKernel" property="mbeanServer"/></parameter>
                 </constructor>
                 </mbean>
                
                </server>
                


                Here is the error message I get when I try to deploy this file with Main.deploy() :


                org.jboss.xb.binding.JBossXBException: Failed to parse source: file:/C:/NichPro/MicrocontainerDirectoryScanner/src/META-INF/nichpro-service.xml@2,9
                at org.jboss.xb.binding.parser.sax.SaxJBossXBParser.parse(SaxJBossXBParser.java:177)
                at org.jboss.xb.binding.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:147)
                at org.jboss.kernel.plugins.deployment.xml.BasicXMLDeployer.deploy(BasicXMLDeployer.java:147)
                at com.nichpro.jmx.bootstrap.Main.deploy(Main.java:123)
                at com.nichpro.jmx.server.config.JMXMain.main(JMXMain.java:40)
                Caused by: org.jboss.xb.binding.JBossXBRuntimeException: Failed to resolve schema nsURI= location=server
                at org.jboss.xb.binding.sunday.unmarshalling.SundayContentHandler.startElement(SundayContentHandler.java:313)
                at org.jboss.xb.binding.parser.sax.SaxJBossXBParser$DelegatingContentHandler.startElement(SaxJBossXBParser.java:401)
                at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(Unknown Source)
                at com.sun.org.apache.xerces.internal.xinclude.XIncludeHandler.startElement(Unknown Source)
                at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
                at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl$NSContentDriver.scanRootElementHook(Unknown Source)
                at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown Source)
                at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(Unknown Source)
                at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)
                at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(Unknown Source)
                at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
                at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
                at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
                at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
                at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
                at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
                at org.jboss.xb.binding.parser.sax.SaxJBossXBParser.parse(SaxJBossXBParser.java:173)
                ... 4 more


                Are MBeans deployed differently from POJOs, or do I have a mistake in my service.xml file?

                Your input on this is greatly appreciated.
                Thanks,

                GMarsh

                • 5. Re: Does the Microcontainer register MBeans that it deploys
                  alesj

                   

                  "Gary Marsh" wrote:

                  Are MBeans deployed differently from POJOs, or do I have a mistake in my service.xml file?

                  Renaming it to -service.xml and adding 'm' to bean doesn't make it magically work.
                  See how we defined mbeans in JBossAS for the last 5 years. ;-)


                  • 6. Re: Does the Microcontainer register MBeans that it deploys
                    garymarsh

                    OK I deserved that one. So I looked at your service.xml examples online and in the demo directories. Changed the properties to attributes, got ride of the constructor tags and I think I have cleaned up the service.xml file so it looks legit now.

                    The new and improved nichpro-service.xml file :

                    <?xml version="1.0" encoding="UTF-8"?>
                    <server>
                     <mbean name="nichpro:service=DataProc" code="com.nichpro.jmx.processing.data.DataProc">
                     <attribute name="associatedType">DataDirMonitor</attribute>
                     </mbean>
                    
                     <mbean name="nichpro:service=DataDirMonitor" code="com.nichpro.jmx.scandir.monitor.data.DataDirMonitor">
                     <attribute name="rootDir">/NichPro/NP_ScanDirectory/Data</attribute>
                     <attribute name="associatedType">DataProc</attribute>
                     </mbean>
                    
                     <mbean name="nichpro:service=DataManagementServer" code="com.nichpro.jmx.server.DataManagementServer">
                     <attribute name="mbeanServer"><inject bean="JMXKernel" property="mbeanServer"/></attribute>
                     </mbean>
                    </server>
                    


                    But I still get a parser error due to the inability to find the schema....


                    org.jboss.xb.binding.JBossXBException: Failed to parse source: file:/C:/NichPro/MicrocontainerDirectoryScanner/src/META-INF/nichpro-service.xml@2,9
                    at org.jboss.xb.binding.parser.sax.SaxJBossXBParser.parse(SaxJBossXBParser.java:177)
                    at org.jboss.xb.binding.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:147)
                    at org.jboss.kernel.plugins.deployment.xml.BasicXMLDeployer.deploy(BasicXMLDeployer.java:147)
                    at com.nichpro.jmx.bootstrap.Main.deploy(Main.java:123)
                    at com.nichpro.jmx.server.config.JMXMain.main(JMXMain.java:40)
                    Caused by: org.jboss.xb.binding.JBossXBRuntimeException: Failed to resolve schema nsURI= location=server
                    at org.jboss.xb.binding.sunday.unmarshalling.SundayContentHandler.startElement(SundayContentHandler.java:313)
                    at org.jboss.xb.binding.parser.sax.SaxJBossXBParser$DelegatingContentHandler.startElement(SaxJBossXBParser.java:401)
                    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(Unknown Source)




                    None of the examples address schema locations or schema definitions which leaves me kind of at a dead end.

                    Regards,
                    GMarsh

                    • 7. Re: Does the Microcontainer register MBeans that it deploys
                      alesj

                       

                      "Gary Marsh" wrote:
                      OK I deserved that one.

                      ;-)

                      "Gary Marsh" wrote:

                      But I still get a parser error due to the inability to find the schema....

                      org.jboss.xb.binding.JBossXBException: Failed to parse source: file:/C:/NichPro/MicrocontainerDirectoryScanner/src/META-INF/nichpro-service.xml@2,9
                      at org.jboss.xb.binding.parser.sax.SaxJBossXBParser.parse(SaxJBossXBParser.java:177)
                      at org.jboss.xb.binding.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:147)
                      at org.jboss.kernel.plugins.deployment.xml.BasicXMLDeployer.deploy(BasicXMLDeployer.java:147)
                      at com.nichpro.jmx.bootstrap.Main.deploy(Main.java:123)

                      BasicXMLDeployer only understands pre-configured JBossXB schemas
                      in SingletonSchemaResolver and expects an KernelDeployment outcome.

                      It's the SARDeployer that understands -service.xml,
                      meaning you should deploy that file into sandbox only when this deployer is present.
                      Use explicit dependencies to get the right deployment order.

                      • 8. Re: Does the Microcontainer register MBeans that it deploys
                        alesj

                        Note: parsing of -service.xml is not JBossXB based
                        See SARDeployer on how the file is parsed.

                        • 9. Re: Does the Microcontainer register MBeans that it deploys
                          alesj

                           

                          "alesj" wrote:

                          Either use legacy -service.xml or add @JMX annotation to your beans.

                          @JMX won't work so early as well.
                          The part that handles that is in aop.xml.

                          Currently we're using some hack in JBossAS
                          to see/manage the bootstrap beans.
                          - see TempBasicXMLDeployer
                          This should eventually be properly fixed/implemented.