Letting VisualVM Distinguish Between NetBeans Platform Applications

A typical factory for the com.sun.tools.visualvm.application.type.ApplicationType class specifies that the aforementioned class should only be created for an application with a specific main class. So, for example, if your application's main class is "com.toy.anagrams.ui.Anagrams", then the factory will extend MainClassApplicationTypeFactory and it will have a method override like this:
@Override
public ApplicationType createApplicationTypeFor(Application app, Jvm jvm, String mainClass) {
    if ("com.toy.anagrams.ui.Anagrams".equals(mainClass)) {
        return new WonderfulApplicationType(app.getPid());
    }
    return null;
}

However, what about NetBeans Platform applications? Except for the extremely rare situation where you create your own main class that overrides the one provided by the runtime container, your NetBeans Platform application will always have "org.netbeans.Main" as its main class.

So, how can VisualVM distinguish between NetBeans Platform applications? Instead of extending MainClassApplicationTypeFactory, you will need to extend NetBeansApplicationTypeFactory, in one of two ways, which could also be combined, if necessary: (1) identify the application via its unique branding token, (2) identify the application via its unique cluster.

Below code is shown for distinguishing via the unique branding name, which here is "wonderful", defined in the application's project.properties file, via the branding.token key:

public class WonderfulApplicationTypeProvider extends NetBeansApplicationTypeFactory {

    private static final String WONDERFUL_ID = "wonderful"; // NOI18N

    @Override
    public ApplicationType createApplicationTypeFor(Application app, Jvm jvm, String mainClass) {
        String branding = getBranding(jvm);
        if (WONDERFUL_ID.equals(branding)) {
            return new WonderfulApplicationType(app.getPid());
        }
        return null;
    }
    
}

The result, as you can see from the highlighted part below, is that even though the main class of my Wonderful application is the same as all other NetBeans Platform applications, the icon and display name of the node in VisualVM is distinct, which in this case is thanks to the branding token:

For details on the other approach, i.e., using the application's unique cluster, look at the sources of com.sun.tools.visualvm.application.type.NetBeansApplicationTypeFactory.

In other news. Blogs.sun.com is 5 years old today! Hurray and thanks for all the work done by the people behind it.

Comments:

Post a Comment:
  • HTML Syntax: NOT allowed
About

Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
12
13
14
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today