Getting Started Extending VisualVM (Part 4)

Update on 28 May 2008: The code and steps in this blog entry have been updated to reflect the VisualVM 1.0 APIs. If you want to download the complete sources of the sample discussed here, get the VisualVM Sample Collection from the Plugin Portal.

In part 2 of this series, I talked about extending the Overview tab in VisualVM. At the time, I didn't realize that you can also extend the Monitor tab and the Threads tab. In each case, when you initialize the plugin that provides the subtab (i.e., the tab within the Overview tab, Monitor tab, or Threads tab), you need to use either ApplicationViewsSupport.sharedInstance().getOverviewView(), ApplicationViewsSupport.sharedInstance().getMonitorView(), or ApplicationViewsSupport.sharedInstance().getThreadsView(), like this, for example:

public static void initialize() {
    ApplicationViewsSupport.sharedInstance().getOverviewView().
                registerPluginProvider(new AnagramViewPluginProvider());
}

Call the above from the ModuleInstall class and then your subtab will end up in the tab you specified (i.e., either "Overview", "Monitor", or "Threads"), as is shown here for "MonitorViewSupport", where I added a "User Interface" tab to the bottom right (the tab simply contains a screenshot of the ui of the application in question):

That's nice, because someone can create a whole separate module that does nothing other than provide a subtab:

However, what's even more interesting than that (much more interesting, in fact) is that you can make your own tabs extendable. So, while "Overview", "Monitor", and "Threads" are provided by VisualVM, you can (as explained at the start of this series) provide your own tab. The cool thing I discovered today is that YOU CAN CREATE YOUR TAB IN SUCH A WAY THAT OTHERS CAN EXTEND IT. Sorry, I never use uppercase, but here I think it is warranted. That same line of code above is rewritten to the following, in the plugin shown in the screenshot above:

public static void initialize() {
    DemoViewSupport.getInstance().getApplicationPluggableView().
            registerPluginProvider(new DemoViewPluginProvider());
}

Where does "DemoViewSupport" come from? Look in the sources of VisualVM and you will NOT find it. I created a module called "DemoPluggableView", which looks like this:

The two files you see highlighted are the two classes I needed to add in order to make the tab defined by the provider and datasource view extendable. The DemoViewSupport is defined as follows:

package org.visualvm.demopluggableview;

import com.sun.tools.visualvm.application.Application;
import com.sun.tools.visualvm.core.ui.DataSourceViewsManager;
import com.sun.tools.visualvm.core.ui.PluggableDataSourceViewProvider;

public class DemoViewSupport {

    private static DemoViewSupport instance;
    
    private DemoViewProvider DemoPluggableView = new DemoViewProvider();    

    public static synchronized DemoViewSupport getInstance() {
        if (instance == null) {
            instance = new DemoViewSupport();
        }
        return instance;
    }

    public PluggableDataSourceViewProvider getApplicationPluggableView() {
        return DemoPluggableView;
    }

    public DemoViewSupport() {
        DataSourceViewsManager.sharedInstance().addViewProvider(DemoPluggableView, Application.class);
    }
    
}

And this is the DemoPluggableView:

package org.visualvm.demopluggableview;

import com.sun.tools.visualvm.application.Application;
import com.sun.tools.visualvm.core.ui.DataSourceView;
import com.sun.tools.visualvm.core.ui.DataSourceViewProvider;
import com.sun.tools.visualvm.core.ui.DataSourceViewsManager;
import com.sun.tools.visualvm.core.ui.PluggableDataSourceViewProvider;
import java.util.Set;

public class DemoPluggableView extends PluggableDataSourceViewProvider<Application> {

    private static DataSourceViewProvider<Application> instance = new DemoPluggableView();

    @Override
    public boolean supportsViewFor(Application application) {
        //Always shown:
        return true;
    }

    @Override
    protected DataSourceView createView(Application application) {
        return new DemoDataSourceView(application);
    }

    static void initialize() {
        DataSourceViewsManager.sharedInstance().addViewProvider(instance, Application.class);
    }

    static void unregister() {
        DataSourceViewsManager.sharedInstance().removeViewProvider(instance);
    }

    @Override
    public Set<Integer> getPluggableLocations(DataSourceView arg0) {
        return ALL_LOCATIONS;
    }
    
}
Update on 28 May 2008: The code and steps in this blog entry have been updated to reflect the VisualVM 1.0 APIs. If you want to download the complete sources of the sample discussed here, get the VisualVM Sample Collection from the Plugin Portal.

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
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today