Tuesday May 06, 2008 ![]() |
JMX, SNMP, Java, etc...Daniel Fuchs blogs on JMX, SNMP, Java, etc... |
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
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
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
The ProductsDBMXBean interface shown below lets me exports the same
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:
You can now start JConsole or VisualVM and point it at your ProductCodes
application. Open the MBeanTab and select the MBean named
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 Tags: java jmx management monitoring mxbeanPosted by dfuchs ( May 06 2008, 05:37:15 PM CEST ) Permalink Comments [3] |
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 10: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 10:48 AM CEST #
Your site looks cool,really informative...
Posted by Serg on December 23, 2008 at 08:50 PM CET #