How to find all of the MBeans in a particular domain
My code is connecting to my WebLogic 8.1 server without a problem and I can get all of the MBeans running in it. What I'd like to do is retrieve a subset for a particular Domain.
Right now I'm using:
rmbs = (MBeanServer) ctx.lookup(weblogic.management.RemoteMBeanServer.JNDI_NAME);
Set set = rmbs.queryMBeans(null,null);
This returns a set of all of the MBeans, in this case 702. What I would like to do is get the MBeans in a particular domain, for example WeblogicManagement.
Is there a way to do it?
[541 byte] By [
sasdava] at [2007-10-2 21:36:25]

Hi,
I don't have a direct answer to your question, but maybe:
http://edocs.bea.com/wls/docs81/jmx/namespace.html#1138147
could help you figure this out.
By passing 'null,null' to rmbs.queryMBeans(null,null), you get back all the MBeans
registered in the MBeanServer.
However, the first parameter to queryMBeans is an ObjectName pattern.
An ObjectName pattern can let you select all the MBeans whose name match
that pattern. In JMX 1.0 (which is I believe what WebLogic 8.1 is using) an
ObjectName pattern obey the syntax:
<domain-pattern>:<key-assignement>*[<wildcard>]
<domain-pattern> is any sequence of character, excluding colon, where '?'
represents any character and '*' represents any sequence of character.
<key-assignement> is a regular JMX key=value pair,
<wildcard> is the optional ",*" (or "*" if there's no key assignement) string.
For instance:
queryMBeans(new ObjectName("*:*"), null)
is equivalent to
queryMBeans(null,null)
queryMBeans(new ObjectName("foo:*"), null)
will return all MBeans whose ObjectName domain is exactly "foo"
queryMBeans(new ObjectName("foo?bar*:*"), null)
will return all MBeans whose ObjectName domain matches "foo?bar*" - i.e.
"fooXbar", "fooXbarZZZ", but not "foobar"
queryMBeans(new ObjectName("foo?bar*:type=MyType,*"), null)
will return all MBeans whose ObjectName domain matches "foo?bar*",
and which additionally have a key-property assignement 'type=MyType'
The doc at http://edocs.bea.com/wls/docs81/jmx/namespace.html#1138147
might help you figure out whether there's an ObjectName pattern that would
let you select the subset of MBeans you're interested in.
For more information on JMX 1.0, you can download the JMX 1.0 specification
from http://jcp.org/aboutJava/communityprocess/final/jsr003/index.html
Hope this helps,
-- daniel
JMX, SNMP, Java, etc...
http://blogs.sun.com/roller/page/jmxetc
Actually, no it doesn't help much. But then the documentation on the WebLogic site rarely does.
For instance, here's the code I'm running:
InitialContext ctx = new InitialContext(props);
rmbs = (MBeanServer) ctx.lookup("weblogic.management.server");
ObjectName objName = new ObjectName("*:Type=ServerRuntimeMBean,*");
Set set = rmbs.queryMBeans(objName,null);
System.out.println(set.size());
Now the url I'm connecting to has two Managed servers, but the code above reports 0 as the size of the returned set.
Message was edited by:
sasdav
Hi,
I googled for "Type=ServerRuntimeMBean" and found the following link
http://dev2dev.bea.com/pub/a/2002/07/437.html
which lets me think that the ObjectName pattern to use should rather be
ObjectName objName = new ObjectName(<b>"*:Type=ServerRuntime,*"</b>);
This seems to be confirmed by the fact that googling for "Type=ServerRuntime"
returns many more results!
Would that be the reason?
Hope this helps,
-- daniel
JMX, SNMP, Java, etc...
http://blogs.sun.com/roller/page/jmxetc