src/jdk.jconsole/share/classes/com/sun/tools/jconsole/JConsolePlugin.java
author mgronlun
Wed, 23 May 2018 15:21:54 +0200
changeset 50234 6ba3e32a9882
parent 47216 71c04702a3d5
permissions -rw-r--r--
8203457: Add back missing full buffer notification Reviewed-by: redestad, sjohanss
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 20742
diff changeset
     2
 * Copyright (c) 2006, 2013, 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
45133
d017dbecd7db 8179460: Fix unnecessary uses of {@docRoot} in serviceability APIs
jjg
parents: 34894
diff changeset
    37
 * {@link java.util.ServiceLoader service provider}
d017dbecd7db 8179460: Fix unnecessary uses of {@docRoot} in serviceability APIs
jjg
parents: 34894
diff changeset
    38
 * mechanism to search the JConsole plugins.
2
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
 *
32769
c9520bbd6754 8133651: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 25859
diff changeset
    57
 * <p> where {@code <plugin-path>} specifies the paths of JConsole
2
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
 *
45133
d017dbecd7db 8179460: Fix unnecessary uses of {@docRoot} in serviceability APIs
jjg
parents: 34894
diff changeset
    70
 * @see java.util.ServiceLoader
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
public abstract class JConsolePlugin {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    private volatile JConsoleContext context = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    private List<PropertyChangeListener> listeners = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * Constructor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    protected JConsolePlugin() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * Sets the {@link JConsoleContext JConsoleContext} object representing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * the connection to an application.  This method will be called
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * only once after the plugin is created and before the {@link #getTabs}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * is called. The given {@code context} can be in any
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * {@link JConsoleContext#getConnectionState connection state} when
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * this method is called.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * @param context a {@code JConsoleContext} object
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    public final synchronized void setContext(JConsoleContext context) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        this.context = context;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        if (listeners != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            for (PropertyChangeListener l : listeners) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                context.addPropertyChangeListener(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            // throw away the listener list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            listeners = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * Returns the {@link JConsoleContext JConsoleContext} object representing
32769
c9520bbd6754 8133651: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 25859
diff changeset
   107
     * the connection to an application.  This method may return {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * if it is called before the {@link #setContext context} is initialized.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * @return the {@link JConsoleContext JConsoleContext} object representing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     *         the connection to an application.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    public final JConsoleContext getContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        return context;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * Returns the tabs to be added in JConsole window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * The returned map contains one entry for each tab
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * to be added in the tabbed pane in a JConsole window with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * the tab name as the key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * and the {@link JPanel} object as the value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * This method returns an empty map if no tab is added by this plugin.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * This method will be called from the <i>Event Dispatch Thread</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * once at the new connection time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * @return a map of a tab name and a {@link JPanel} object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     *         representing the tabs to be added in the JConsole window;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     *         or an empty map.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    public abstract java.util.Map<String, JPanel> getTabs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * Returns a {@link SwingWorker} to perform
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * the GUI update for this plugin at the same interval
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * as JConsole updates the GUI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * JConsole schedules the GUI update at an interval specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * for a connection.  This method will be called at every
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * update to obtain a {@code SwingWorker} for each plugin.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * JConsole will invoke the {@link SwingWorker#execute execute()}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * method to schedule the returned {@code SwingWorker} for execution
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * if:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * <ul>
32769
c9520bbd6754 8133651: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 25859
diff changeset
   147
     *   <li> the {@code SwingWorker} object has not been executed
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     *        (i.e. the {@link SwingWorker#getState} method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     *        returns {@link javax.swing.SwingWorker.StateValue#PENDING PENDING}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     *        state); and</li>
32769
c9520bbd6754 8133651: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 25859
diff changeset
   151
     *   <li> the {@code SwingWorker} object returned in the previous
c9520bbd6754 8133651: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 25859
diff changeset
   152
     *        update has completed the task if it was not {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     *        (i.e. the {@link SwingWorker#isDone SwingWorker.isDone} method
32769
c9520bbd6754 8133651: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 25859
diff changeset
   154
     *        returns {@code true}).</li>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * <br>
32769
c9520bbd6754 8133651: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 25859
diff changeset
   157
     * Otherwise, {@code SwingWorker} object will not be scheduled to work.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * A plugin can schedule its own GUI update and this method
32769
c9520bbd6754 8133651: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 25859
diff changeset
   161
     * will return {@code null}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     *
32769
c9520bbd6754 8133651: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 25859
diff changeset
   163
     * @return a {@code SwingWorker} to perform the GUI update; or
c9520bbd6754 8133651: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 25859
diff changeset
   164
     *         {@code null}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    public abstract SwingWorker<?,?> newSwingWorker();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * Dispose this plugin. This method is called by JConsole to inform
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * that this plugin will be discarded and that it should free
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * any resources that it has allocated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * The {@link #getContext JConsoleContext} can be in any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * {@link JConsoleContext#getConnectionState connection state} when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * this method is called.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    public void dispose() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        // Default nop implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * Adds a {@link PropertyChangeListener PropertyChangeListener}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * to the {@link #getContext JConsoleContext} object for this plugin.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * This method is a convenient method for this plugin to register
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * a listener when the {@code JConsoleContext} object may or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * may not be available.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * <p>For example, a plugin constructor can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * call this method to register a listener to listen to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * {@link JConsoleContext.ConnectionState connectionState}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * property changes and the listener will be added to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * {@link JConsoleContext#addPropertyChangeListener JConsoleContext}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * object when it is available.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * @param listener  The {@code PropertyChangeListener} to be added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * @throws NullPointerException if {@code listener} is {@code null}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    public final void addContextPropertyChangeListener(PropertyChangeListener listener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        if (listener == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            throw new NullPointerException("listener is null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        if (context == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            // defer registration of the listener until setContext() is called
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                // check again if context is not set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                if (context == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                    // maintain a listener list to be added later
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                    if (listeners == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                        listeners = new ArrayList<PropertyChangeListener>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                    listeners.add(listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        context.addPropertyChangeListener(listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * Removes a {@link PropertyChangeListener PropertyChangeListener}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * from the listener list of the {@link #getContext JConsoleContext}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * object for this plugin.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * If {@code listener} was never added, no exception is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * thrown and no action is taken.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * @param listener the {@code PropertyChangeListener} to be removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * @throws NullPointerException if {@code listener} is {@code null}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    public final void removeContextPropertyChangeListener(PropertyChangeListener listener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        if (listener == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            throw new NullPointerException("listener is null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        if (context == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            // defer registration of the listener until setContext() is called
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                // check again if context is not set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                if (context == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                    if (listeners != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                        listeners.remove(listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        context.removePropertyChangeListener(listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
}