blob: 5f67dde1aeeff78902fcbda1fa66fc0a3ef920cf [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2006-2007 Sun Microsystems, Inc. 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. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
25
26package com.sun.tools.jconsole;
27
28import javax.management.MBeanServerConnection;
29import java.beans.PropertyChangeListener;
30import 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 * <p>
43 *
44 * @since 1.6
45 */
46public 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 public enum ConnectionState {
57 /**
58 * The connection has been successfully established.
59 */
60 CONNECTED,
61 /**
62 * No connection present.
63 */
64 DISCONNECTED,
65 /**
66 * The connection is being attempted.
67 */
68 CONNECTING
69 }
70
71 /**
72 * Returns the {@link MBeanServerConnection MBeanServerConnection} for the
73 * connection to an application. The returned
74 * {@code MBeanServerConnection} object becomes invalid when
75 * the connection state is changed to the
76 * {@link ConnectionState#DISCONNECTED DISCONNECTED} state.
77 *
78 * @return the {@code MBeanServerConnection} for the
79 * connection to an application.
80 */
81 public MBeanServerConnection getMBeanServerConnection();
82
83 /**
84 * Returns the current connection state.
85 * @return the current connection state.
86 */
87 public ConnectionState getConnectionState();
88
89 /**
90 * Add a {@link java.beans.PropertyChangeListener PropertyChangeListener}
91 * to the listener list.
92 * The listener is registered for all properties.
93 * The same listener object may be added more than once, and will be called
94 * as many times as it is added.
95 * If {@code listener} is {@code null}, no exception is thrown and
96 * no action is taken.
97 *
98 * @param listener The {@code PropertyChangeListener} to be added
99 */
100 public void addPropertyChangeListener(PropertyChangeListener listener);
101
102 /**
103 * Removes a {@link java.beans.PropertyChangeListener PropertyChangeListener}
104 * from the listener list. This
105 * removes a {@code PropertyChangeListener} that was registered for all
106 * properties. If {@code listener} was added more than once to the same
107 * event source, it will be notified one less time after being removed. If
108 * {@code listener} is {@code null}, or was never added, no exception is
109 * thrown and no action is taken.
110 *
111 * @param listener the {@code PropertyChangeListener} to be removed
112 */
113 public void removePropertyChangeListener(PropertyChangeListener listener);
114}