1 /*
   2  * Copyright (c) 2006, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.tools.jconsole;
  27 
  28 import javax.management.MBeanServerConnection;
  29 import java.beans.PropertyChangeListener;
  30 import javax.swing.event.SwingPropertyChangeSupport;
  31 
  32 /**
  33  * {@code JConsoleContext} represents a JConsole connection to a target
  34  * application.
  35  * <p>
  36  * {@code JConsoleContext} notifies any {@code PropertyChangeListeners}
  37  * about the {@linkplain #CONNECTION_STATE_PROPERTY <i>ConnectionState</i>}
  38  * property change to {@link ConnectionState#CONNECTED CONNECTED} and
  39  * {@link ConnectionState#DISCONNECTED DISCONNECTED}.
  40  * The {@code JConsoleContext} instance will be the source for
  41  * any generated events.
  42  *
  43  * @since 1.6
  44  */
  45 @jdk.Exported
  46 public interface JConsoleContext {
  47     /**
  48      * The {@link ConnectionState ConnectionState} bound property name.
  49      */
  50     public static String CONNECTION_STATE_PROPERTY = "connectionState";
  51 
  52     /**
  53      * Values for the {@linkplain #CONNECTION_STATE_PROPERTY
  54      * <i>ConnectionState</i>} bound property.
  55      */
  56     @jdk.Exported
  57     public enum ConnectionState {
  58         /**
  59          * The connection has been successfully established.
  60          */
  61         CONNECTED,
  62         /**
  63          * No connection present.
  64          */
  65         DISCONNECTED,
  66         /**
  67          * The connection is being attempted.
  68          */
  69         CONNECTING
  70     }
  71 
  72     /**
  73      * Returns the {@link MBeanServerConnection MBeanServerConnection} for the
  74      * connection to an application.  The returned
  75      * {@code MBeanServerConnection} object becomes invalid when
  76      * the connection state is changed to the
  77      * {@link ConnectionState#DISCONNECTED DISCONNECTED} state.
  78      *
  79      * @return the {@code MBeanServerConnection} for the
  80      * connection to an application.
  81      */
  82     public MBeanServerConnection getMBeanServerConnection();
  83 
  84     /**
  85      * Returns the current connection state.
  86      * @return the current connection state.
  87      */
  88     public ConnectionState getConnectionState();
  89 
  90     /**
  91      * Add a {@link java.beans.PropertyChangeListener PropertyChangeListener}
  92      * to the listener list.
  93      * The listener is registered for all properties.
  94      * The same listener object may be added more than once, and will be called
  95      * as many times as it is added.
  96      * If {@code listener} is {@code null}, no exception is thrown and
  97      * no action is taken.
  98      *
  99      * @param listener  The {@code PropertyChangeListener} to be added
 100      */
 101     public void addPropertyChangeListener(PropertyChangeListener listener);
 102 
 103     /**
 104      * Removes a {@link java.beans.PropertyChangeListener PropertyChangeListener}
 105      * from the listener list. This
 106      * removes a {@code PropertyChangeListener} that was registered for all
 107      * properties. If {@code listener} was added more than once to the same
 108      * event source, it will be notified one less time after being removed. If
 109      * {@code listener} is {@code null}, or was never added, no exception is
 110      * thrown and no action is taken.
 111      *
 112      * @param listener the {@code PropertyChangeListener} to be removed
 113      */
 114     public void removePropertyChangeListener(PropertyChangeListener listener);
 115 }