/* * Copyright (c) 2006, 2013, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package com.sun.tools.jconsole; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.util.ArrayList; import java.util.List; import javax.swing.JPanel; import javax.swing.SwingWorker; /** * A JConsole plugin class. JConsole uses the * * service provider mechanism to search the JConsole plugins. * Users can provide their JConsole plugins in a jar file * containing a file named * *
* ** META-INF/services/com.sun.tools.jconsole.JConsolePlugin
This file contains one line for each plugin, for example, * *
** com.sun.example.JTop
which is the fully qualified class name of the class implementing * {@code JConsolePlugin}. * *
To load the JConsole plugins in JConsole, run: * *
* ** jconsole -pluginpath <plugin-path>
where <plugin-path> specifies the paths of JConsole * plugins to look up which can be a directory or a jar file. Multiple * paths are separated by the path separator character of the platform. * *
When a new JConsole window is created for a connection,
* an instance of each {@code JConsolePlugin} will be created.
* The {@code JConsoleContext} object is not available at its
* construction time.
* JConsole will set the {@link JConsoleContext} object for
* a plugin after the plugin object is created. It will then
* call its {@link #getTabs getTabs} method and add the returned
* tabs to the JConsole window.
*
* @see
* java.util.ServiceLoader
*
* @since 1.6
*/
@jdk.Exported
public abstract class JConsolePlugin {
private volatile JConsoleContext context = null;
private List
* The returned map contains one entry for each tab
* to be added in the tabbed pane in a JConsole window with
* the tab name as the key
* and the {@link JPanel} object as the value.
* This method returns an empty map if no tab is added by this plugin.
* This method will be called from the Event Dispatch Thread
* once at the new connection time.
*
* @return a map of a tab name and a {@link JPanel} object
* representing the tabs to be added in the JConsole window;
* or an empty map.
*/
public abstract java.util.Map
* JConsole schedules the GUI update at an interval specified
* for a connection. This method will be called at every
* update to obtain a {@code SwingWorker} for each plugin.
*
* JConsole will invoke the {@link SwingWorker#execute execute()}
* method to schedule the returned {@code SwingWorker} for execution
* if:
*
* A plugin can schedule its own GUI update and this method
* will return null.
*
* @return a SwingWorker to perform the GUI update; or
* null.
*/
public abstract SwingWorker,?> newSwingWorker();
/**
* Dispose this plugin. This method is called by JConsole to inform
* that this plugin will be discarded and that it should free
* any resources that it has allocated.
* The {@link #getContext JConsoleContext} can be in any
* {@link JConsoleContext#getConnectionState connection state} when
* this method is called.
*/
public void dispose() {
// Default nop implementation
}
/**
* Adds a {@link PropertyChangeListener PropertyChangeListener}
* to the {@link #getContext JConsoleContext} object for this plugin.
* This method is a convenient method for this plugin to register
* a listener when the {@code JConsoleContext} object may or
* may not be available.
*
* For example, a plugin constructor can
* call this method to register a listener to listen to the
* {@link JConsoleContext.ConnectionState connectionState}
* property changes and the listener will be added to the
* {@link JConsoleContext#addPropertyChangeListener JConsoleContext}
* object when it is available.
*
* @param listener The {@code PropertyChangeListener} to be added
*
* @throws NullPointerException if {@code listener} is {@code null}.
*/
public final void addContextPropertyChangeListener(PropertyChangeListener listener) {
if (listener == null) {
throw new NullPointerException("listener is null");
}
if (context == null) {
// defer registration of the listener until setContext() is called
synchronized (this) {
// check again if context is not set
if (context == null) {
// maintain a listener list to be added later
if (listeners == null) {
listeners = new ArrayList
*
*
* Otherwise, SwingWorker object will not be scheduled to work.
*
*