Getting Started Extending VisualVM (Part 3)
By Geertjan-Oracle on Feb 28, 2008
In response to the question from Klaus at the end of my blog entry yesterday—yes, you can add subnodes to the application type node in VisualVM. Below you see two examples. The upper part shows a set of subnodes created by the GlassFish plugin for VisualVM, which you can get from visualvm.dev.java.net, together with the sources of the whole of VisualVM. You can see subnodes and that those nodes also have subnodes. Today I used that GlassFish sample as a kind of template for my own experiments. As you can see, now the Anagram Game application type node (in the lower part of the screenshot) has subnodes, for the attributes in the application, together with their type. And you can see, I've opened the MBeans tab in the main part of the tool (that MBeans tab is also provided by a plugin which you can get from the Plugin Manager in VisualVM), which I opened here so you can see that the attributes in the MBeans tab match those in my application type subnodes. (By the way, can someone remind me about how to get the values from an MBeanAttributeInfo?) Here's the result:
The amount of coding needed for subnodes is not insignificant; on the other hand, the GlassFish plugin (even though it is a prototype at the moment, so caveat emptor) is very helpful because it provides almost all the code you need. The only parts I needed to provide myself were the pieces relating to JMX. Here's a pic showing all the classes that I added in addition to those I had already created (i.e., yesterday for the sample that I discussed at that point in my blog):
Hope this serves to inspire you of the potential that VisualVM has for your own applications. Most entry points into VisualVM have now been discussed here in this blog, but a few still remain, and there are several t's to cross and i's to dot. So watch this space for further learnings in connection to VisualVM.
Update on 30 May 2008: If you want to download the complete sources of the sample discussed here, get the VisualVM Sample Collection from the Plugin Portal.