JConsole's MBeans tab: MBean tree construction

Do you want to know how the MBean tree is constructed in the JConsole's MBeans tab in Mustang (Java SE 6)?

If the answer is yes, keep reading!

I will explain how the MBean tree is constructed by default and how you can specify the key order the MBean tree construction algorithm must follow when adding MBeans (ObjectNames) to the MBean tree.

JConsole's default behavior

By default, the MBeans are displayed in the tree based on their ObjectNames creation key order, i.e. the key order specified at the ObjectName creation time is preserved by JConsole when adding MBeans to the MBean tree. The exact ordered key property list JConsole will use to build the MBean tree will be the one returned by the method ObjectName.getKeyPropertyListString() with type as first key, and j2eeType as second key, if present.

For example, suppose you have Triangle objects with the following names:

com.sun.example:type=Triangle,side=scalene,name=1
com.sun.example:type=Triangle,side=scalene,name=2
com.sun.example:type=Triangle,side=isosceles,name=1
com.sun.example:type=Triangle,side=isosceles,name=2
com.sun.example:type=Triangle,side=isosceles,name=3

JConsole is started as follows:

% jconsole

The MBean tree will be rendered by JConsole as follows:

JConsole screenshot showing MBean tree

By looking at the picture above, everything looks fine at first sight. However, relying on the ObjectName key properties creation order may sometimes lead to an unexpected MBean tree rendering behavior. For example, if two OjectNames have similar keys but their key original order differs, then the corresponding MBeans will not be created under the same node in the MBean tree.

For example, suppose you have Triangle objects with the following names:

com.sun.example:type=Triangle,side=scalene,name=1
com.sun.example:type=Triangle,side=scalene,name=2
com.sun.example:type=Triangle,side=isosceles,name=1
com.sun.example:type=Triangle,name=2,side=isosceles
com.sun.example:type=Triangle,side=isosceles,name=3

Notice that the previous ObjectName

com.sun.example:type=Triangle,side=isosceles,name=2

has been created now as follows

com.sun.example:type=Triangle,name2,side=isosceles

JConsole is started as follows:

% jconsole

The MBean tree will be rendered by JConsole as follows:

JConsole screenshot showing MBean tree

As you can see in the picture above a new branch for the name=2 node has been created and the side=isosceles node added to it thus making the different isosceles triangles be wrongly displayed in separate branches.

Using the new system property to specify the key order

In order to avoid all these subtleties you can specify the order in which the MBeans are displayed in the tree by supplying an ordered key property list when you start JConsole at the command line, using the system property com.sun.tools.jconsole.mbeans.keyPropertyList, as shown below:

% jconsole -J-Dcom.sun.tools.jconsole.mbeans.keyPropertyList=<key>[,<key>]\*

The key property list system property takes a comma-separated list of keys, in the order of your choosing, where <key> must be a string representing an ObjectName key or the empty string. If any of the keys specified in the list does not apply to a particular MBean, then that key will be discarded. If a particular MBean has more keys than the ones specified in the key property list then the key order defined by the returned value of the method ObjectName.getKeyPropertyListString() will be used to complete the key order defined by the key property list system property. Therefore, specifying an empty list of keys just means to display keys in the order they appear in the ObjectName. If the key property list system property is set to the empty string, as shown below:

% jconsole -J-Dcom.sun.tools.jconsole.mbeans.keyPropertyList=""

then Mustang JConsole falls back to the Tiger JConsole behavior when building the MBean tree. The order of keys at ObjectName creation time, i.e. the value returned by the method ObjectName.getKeyPropertyListString() will be the one used by JConsole to build the MBean tree.

For example, suppose you have Triangle objects with the following names:

com.sun.example:type=Triangle,side=scalene,name=1
com.sun.example:type=Triangle,side=scalene,name=2
com.sun.example:type=Triangle,side=isosceles,name=1
com.sun.example:type=Triangle,name=2,side=isosceles
com.sun.example:type=Triangle,side=isosceles,name=3

JConsole is started as follows:

% jconsole -J-Dcom.sun.tools.jconsole.mbeans.keyPropertyList=side,name

The MBean tree will be rendered by JConsole as follows:

JConsole screenshot showing MBean tree

As you can see in the picture above the side key comes first, followed by the name key. The type key comes at the end. This behavior is due to the fact that the type key wasn't specified in the key property list thus the MBean tree algorithm applied the key original order for the remaining keys, i.e. the type key in this case has been appended at the end, right after the keys which were defined by the key property list system property.

In order to follow the ObjectName convention described in the JMX Best Practices where the type key should come first we would have to run JConsole as follows:

% jconsole -J-Dcom.sun.tools.jconsole.mbeans.keyPropertyList=type,side,name

The MBean tree will be rendered by JConsole as follows:

JConsole screenshot showing MBean tree

As you can see in the picture above the type key comes first, the side key comes second, followed by the name key.

Comments:

I've nothing to say, except, JMX rules, Java rules, and SUN rulezzzzzzzzz ... :D

Posted by Kebir Selim on November 22, 2007 at 02:29 PM CET #

Thanks for sharing that information! I've been googling for nesting mbeans, nesting jmx domains, mbean parent/child but the solution was in JConsole... Ah well, now I know :)

Posted by Gabriel Falkenberg on March 28, 2008 at 05:21 AM CET #

Post a Comment:
  • HTML Syntax: NOT allowed
About

lmalvent

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today