-
1. Re: Does the Microcontainer register MBeans that it deploys
alesj Dec 13, 2008 5:19 AM (in response to garymarsh)I have no problems querying mbeans.
Just added MBeanServerQuery classpublic 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 outputJBoss-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 Dec 15, 2008 3:49 PM (in response to 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 Dec 15, 2008 4:19 PM (in response to garymarsh)"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 Dec 15, 2008 6:04 PM (in response to 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 Dec 16, 2008 3:25 AM (in response to garymarsh)"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 Dec 16, 2008 1:30 PM (in response to 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 Dec 16, 2008 1:48 PM (in response to garymarsh)"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 Dec 16, 2008 1:50 PM (in response to garymarsh)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 Dec 16, 2008 2:06 PM (in response to garymarsh)"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.