jdk/src/share/classes/com/sun/tools/jconsole/JConsolePlugin.java
author alanb
Wed, 09 Oct 2013 09:20:12 +0100
changeset 20742 4ae78e8060d6
parent 5506 202f599c92aa
child 23010 6dadb192ad81
permissions -rw-r--r--
8008662: Add @jdk.Exported to JDK-specific/exported APIs Reviewed-by: chegar, vinnie, dfuchs, mchung, mullan, darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2006, 2007, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package com.sun.tools.jconsole;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.beans.PropertyChangeEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.beans.PropertyChangeListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.ArrayList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.List;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import javax.swing.JPanel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import javax.swing.SwingWorker;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * A JConsole plugin class.  JConsole uses the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * <a href="{@docRoot}/../../../../api/java/util/ServiceLoader.html">
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * service provider</a> mechanism to search the JConsole plugins.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * Users can provide their JConsole plugins in a jar file
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * containing a file named
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * <blockquote><pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * META-INF/services/com.sun.tools.jconsole.JConsolePlugin</pre></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * <p> This file contains one line for each plugin, for example,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * <blockquote><pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * com.sun.example.JTop</pre></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * <p> which is the fully qualified class name of the class implementing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * {@code JConsolePlugin}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * <p> To load the JConsole plugins in JConsole, run:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * <blockquote><pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * jconsole -pluginpath &lt;plugin-path&gt; </pre></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * <p> where <tt>&lt;plugin-path&gt;</tt> specifies the paths of JConsole
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * plugins to look up which can be a directory or a jar file. Multiple
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * paths are separated by the path separator character of the platform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * <p> When a new JConsole window is created for a connection,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * an instance of each {@code JConsolePlugin} will be created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * The {@code JConsoleContext} object is not available at its
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * construction time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * JConsole will set the {@link JConsoleContext} object for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * a plugin after the plugin object is created.  It will then
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * call its {@link #getTabs getTabs} method and add the returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * tabs to the JConsole window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * @see <a href="{@docRoot}/../../../../api/java/util/ServiceLoader.html">
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * java.util.ServiceLoader</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 */
20742
4ae78e8060d6 8008662: Add @jdk.Exported to JDK-specific/exported APIs
alanb
parents: 5506
diff changeset
    75
@jdk.Exported
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
public abstract class JConsolePlugin {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    private volatile JConsoleContext context = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    private List<PropertyChangeListener> listeners = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * Constructor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    protected JConsolePlugin() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * Sets the {@link JConsoleContext JConsoleContext} object representing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * the connection to an application.  This method will be called
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * only once after the plugin is created and before the {@link #getTabs}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * is called. The given {@code context} can be in any
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * {@link JConsoleContext#getConnectionState connection state} when
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * this method is called.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * @param context a {@code JConsoleContext} object
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    public final synchronized void setContext(JConsoleContext context) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        this.context = context;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        if (listeners != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            for (PropertyChangeListener l : listeners) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                context.addPropertyChangeListener(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            // throw away the listener list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            listeners = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * Returns the {@link JConsoleContext JConsoleContext} object representing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * the connection to an application.  This method may return <tt>null</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * if it is called before the {@link #setContext context} is initialized.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * @return the {@link JConsoleContext JConsoleContext} object representing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     *         the connection to an application.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    public final JConsoleContext getContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        return context;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * Returns the tabs to be added in JConsole window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * The returned map contains one entry for each tab
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * to be added in the tabbed pane in a JConsole window with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * the tab name as the key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * and the {@link JPanel} object as the value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * This method returns an empty map if no tab is added by this plugin.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * This method will be called from the <i>Event Dispatch Thread</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * once at the new connection time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * @return a map of a tab name and a {@link JPanel} object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     *         representing the tabs to be added in the JConsole window;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     *         or an empty map.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    public abstract java.util.Map<String, JPanel> getTabs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * Returns a {@link SwingWorker} to perform
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * the GUI update for this plugin at the same interval
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * as JConsole updates the GUI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * JConsole schedules the GUI update at an interval specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * for a connection.  This method will be called at every
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * update to obtain a {@code SwingWorker} for each plugin.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * JConsole will invoke the {@link SwingWorker#execute execute()}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * method to schedule the returned {@code SwingWorker} for execution
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * if:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     *   <li> the <tt>SwingWorker</tt> object has not been executed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     *        (i.e. the {@link SwingWorker#getState} method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     *        returns {@link javax.swing.SwingWorker.StateValue#PENDING PENDING}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     *        state); and</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     *   <li> the <tt>SwingWorker</tt> object returned in the previous
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     *        update has completed the task if it was not <tt>null</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     *        (i.e. the {@link SwingWorker#isDone SwingWorker.isDone} method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     *        returns <tt>true</tt>).</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * <br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * Otherwise, <tt>SwingWorker</tt> object will not be scheduled to work.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * A plugin can schedule its own GUI update and this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * will return <tt>null</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * @return a <tt>SwingWorker</tt> to perform the GUI update; or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     *         <tt>null</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    public abstract SwingWorker<?,?> newSwingWorker();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * Dispose this plugin. This method is called by JConsole to inform
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * that this plugin will be discarded and that it should free
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * any resources that it has allocated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * The {@link #getContext JConsoleContext} can be in any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * {@link JConsoleContext#getConnectionState connection state} when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * this method is called.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    public void dispose() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        // Default nop implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * Adds a {@link PropertyChangeListener PropertyChangeListener}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * to the {@link #getContext JConsoleContext} object for this plugin.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * This method is a convenient method for this plugin to register
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * a listener when the {@code JConsoleContext} object may or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * may not be available.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * <p>For example, a plugin constructor can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * call this method to register a listener to listen to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * {@link JConsoleContext.ConnectionState connectionState}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * property changes and the listener will be added to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * {@link JConsoleContext#addPropertyChangeListener JConsoleContext}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * object when it is available.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * @param listener  The {@code PropertyChangeListener} to be added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * @throws NullPointerException if {@code listener} is {@code null}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    public final void addContextPropertyChangeListener(PropertyChangeListener listener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        if (listener == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            throw new NullPointerException("listener is null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        if (context == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            // defer registration of the listener until setContext() is called
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                // check again if context is not set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                if (context == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                    // maintain a listener list to be added later
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                    if (listeners == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                        listeners = new ArrayList<PropertyChangeListener>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                    listeners.add(listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        context.addPropertyChangeListener(listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * Removes a {@link PropertyChangeListener PropertyChangeListener}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * from the listener list of the {@link #getContext JConsoleContext}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * object for this plugin.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * If {@code listener} was never added, no exception is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * thrown and no action is taken.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * @param listener the {@code PropertyChangeListener} to be removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * @throws NullPointerException if {@code listener} is {@code null}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    public final void removeContextPropertyChangeListener(PropertyChangeListener listener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        if (listener == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            throw new NullPointerException("listener is null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        if (context == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            // defer registration of the listener until setContext() is called
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                // check again if context is not set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                if (context == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                    if (listeners != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                        listeners.remove(listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        context.removePropertyChangeListener(listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
}