-
1. Re: Using queryMBean
dimitris May 9, 2006 2:32 PM (in response to peterj)Try a 'null' QueryExp and use the ObjectName:
"jboss.management.local:j2eeType=Servlet,*" -
2. Re: Using queryMBean
peterj May 9, 2006 4:56 PM (in response to peterj)OK, that works. I thought that I had gotten an exception when I tried that earlier. Oh, now I remember, what I tried at first was (this is only one of many variations of the object name string containing wild cards):
ObjectName name = new ObjectName("jboss.management.local:EJBModule=*,*"); getServer().queryMBeans(name, qe);
This gave me the exception:Exception in thread "main" javax.management.MalformedObjectNameException: jboss. management.local:EJBModule=*,* is not a valid ObjectName. The value * cannot con tain * use quote backslash * quote or ObjectName.quote(String)
This lead me to attempt to figure out how query expressions worked, which lead to the code I originally posted. My end goal is to come up with a query that will give me all mbeans that have a particular attribute, regardless of the value of the attribute.
By the way, I am close to figuring out why the query isn't working. I'll post my conclusions when I am done. -
3. Re: Using queryMBean
peterj May 9, 2006 7:04 PM (in response to peterj)I have reached my conclusion: I don't know what I am doing. :-(
I now realize that the query expression will filter MBeans based on the values of the properties defined for the MBean. I mistakenly thought that parts of the MBean name were the attributes that I could query on. That is, an MBean with name "foo.bar:name1=xxx,name2=yyy" had attributes name1 and name2 and thus I could query on those. But actually, if this MBean has properties prop1 and prop2, I can use a query to find an MBean with particular values for properties prop1 or prop2. The tutorials that were confusing to me at first are now a lot clearer.
But, I still have room to complain. :-)
First, class org.jboss.mx.server.MBeanServerImpl, method queryMBean has this code:try { return queryExp.apply(objectName); } catch (Exception e) { return false; }
Not quite sure who thought it was a good idea to throw away the exception. So, I added a logging statement to the code to find out what exception was being thrown and noticed this exception: Exception in thread "main" java.lang.NullPointerException at javax.management.BadAttributeValueExpException.toString(BadAttributeValueExpException.java:71) at org.apache.log4j.spi.VectorWriter.println(ThrowableInformation.java:88) . . .
OK, so printing of the stack trace blew up. Seems to be "a bad thing" to me. Looking at the above toString method, I see:return "Bad attribute value expression: " + val.toString();
Hmm, not only is the call to toString on variable val superfluous, but it is also a bad idea because if val is nul? (you get the idea). OK, so get rid of the toString call on val so that I can finally get my exception printed out. And I then found another instance where an exception was being thrown away in javax.management.AttributeValueExp.getAttribute:try { MBeanServer mbs = QueryEval.getMBeanServer(); return QueryEval.getMBeanServer().getAttribute(name, attr); } catch (Exception e) { return null; }
The toString bug should be fixed. Should I write a JIRA?
For the dropped exceptions, I thought it would be nice to at least log them. But, given the way the code is written, every query will generate a lot of exceptions because if you query for a particular property, an exception is thrown for every MBEan that doesn't have such a property. But this could be handled by catching something other than Exception. Not sure if this is worth opening a JIRA or not. -
4. Re: Using queryMBean
dimitris May 10, 2006 6:45 AM (in response to peterj)The point is those exception were never meant to be seen and it just happened that you came across them, only because of using QueryExp the wrong way :)
Maybe open a "minior" JIRA case proposing a fix for the NPE, and possibly some trace logging for the exceptions messages (the full stack traces are not needed, I think), but again, I'm not sure if people will want to enable tracing of jmx query expression. -
5. Re: Using queryMBean
dimitris May 10, 2006 6:49 AM (in response to peterj)So the "powerpoint" version of the conclusion is:
0) key/value pairs in ObjectNames are not related to mbean attribute values
1) Use ObjectName patterns to match a set of MBean ObjectNames
2) Use QueryExp to match specific attributes on those MBeans.