Mapping to OpenTypes: MXBean Complex Attribute Types

In the recent weeks, I've seen several questions on the SDN JMX forum regarding how to export a complex data type - such as the content of a Map<String,Integer> using MXBeans, in order to obtain a mapping to a desired OpenType.

Although it might not be a very good idea to define your management model based on how it will be displayed by a given GUI, such as that provided by JConsole or VisualVM, I believe it is nonetheless interesting to explore the various way in which such a Map<String,Integer> could be modeled and exposed through an MXBean attribute.

In this post - I will expose five different ways in which such a complex type can be exposed, three using a regular mapping provided by the MXBean framework, two using a more complex custom mapping involving the use of the CompositeDataView interface. Note that the code example shown in this post is based on the APIs available today in JDK 6: for those interested, some improvements are also planned for JDK 7. Compared to what is demonstrated here, these improvements should greatly increase the flexibility of MXBean mapping customization.

To illustrate my demonstration, I have created a ProductCodes application, exposing a "ProductsDB" MXBean which allows you to register new products in its data base. This is just an example which allows me to expose a Map<String,Integer>, such as discussed above. I have therefore kept my example to the bare minimum: a registered product is composed simply of a product name - a String, used as primary key, and an integer, a product code dynamically allocated by the "ProductsDB" MXBean when the new product is registered.

The ProductsDBMXBean interface shown below lets me exports the same Map<String,Integer> in five different ways, using five different attribute types and mappings. Some are obviously uglier than others, depending on whether you look at them through the programmatic lens, or through the JConsole/VisualVM lens. Remember: the purpose of this example is to let you experiment with these various ways of exposing data through MXBean. Personally - I would recommend using the first method exposed (array of RegisteredProduct interface) which provides the best compromise between programmatic access and GUI navigation...

Well, enough said for now. It's time for your to experiment: grab the class below, compile it, and run it in a shell window with the command:

java example.productcodes.ProductCodes
      

You can now start JConsole or VisualVM and point it at your ProductCodes application. Open the MBeanTab and select the MBean named example:type=ProductsDB.

If you select its "Attributes" node you will see our five attributes, all exposing the same information in five different ways. The specifics of each mapping is explained in the comments associated with the code.

Here is my full ProductCodes.java [HTML] [source] example!

Cheers,

--daniel

Comments:

Cool example :) I was looking for something like this.

A direct download link would be nice though, c&p of the class annoyed javac as there were some whitespaces in it.

Ingo

Posted by Ingo Rockel on May 07, 2008 at 03:00 AM CEST #

Hi Ingo!

I thought simply cut&pasting from the browser would give you a non-html version of the source - that's what happens when I cut from firefox and paste in xemacs.
The result might depend on which browser and which editor you're using though - so I followed your suggestion and added a direct link:
http://blogs.sun.com/jmxetc/resource/ProductCodes/ProductCodes.java

Sorry for the trouble!
-- daniel

Posted by daniel on May 07, 2008 at 03:48 AM CEST #

Your site looks cool,really informative...

Posted by Serg on December 23, 2008 at 12:50 PM CET #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Daniel Fuchs blogs on Scene Builder, JMX, SNMP, Java, etc...

The views expressed on this blog are those of the author and do not necessarily reflect the views of Oracle.

Search

Categories
Archives
« July 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
31
  
       
Today