提交 412459e2 编写于 作者: L lmalvent

6655515: MBeans tab: operation return values of type Component displayed as String

6439590: MBeans tab: jconsole mbean tree not correctly refreshed
6446434: MBeans tab: Not possible to view MBean content before all MBeans have been initially loaded
6520144: Hard to find MBean Attributes, Operations, and Notifications in Java 6 jconsole
6522091: VMPanel.java contains non-ASCII character
6608334: JConsole fails to display MBean operation with <null> return type
6611445: MBeans tab: MBean tree algorithm wrongly removes intermediate nodes.
Reviewed-by: dfuchs, jfdenise
上级 ab1229d1
/* /*
* Copyright 2004-2006 Sun Microsystems, Inc. All Rights Reserved. * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
package sun.tools.jconsole; package sun.tools.jconsole;
import java.awt.BorderLayout; import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.event.MouseAdapter; import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.awt.event.MouseListener; import java.awt.event.MouseListener;
...@@ -42,7 +43,8 @@ import com.sun.tools.jconsole.JConsoleContext; ...@@ -42,7 +43,8 @@ import com.sun.tools.jconsole.JConsoleContext;
@SuppressWarnings("serial") @SuppressWarnings("serial")
public class MBeansTab extends Tab implements public class MBeansTab extends Tab implements
NotificationListener, PropertyChangeListener, TreeSelectionListener { NotificationListener, PropertyChangeListener,
TreeSelectionListener, TreeWillExpandListener {
private XTree tree; private XTree tree;
private XSheet sheet; private XSheet sheet;
...@@ -70,6 +72,7 @@ public class MBeansTab extends Tab implements ...@@ -70,6 +72,7 @@ public class MBeansTab extends Tab implements
return sheet; return sheet;
} }
@Override
public void dispose() { public void dispose() {
super.dispose(); super.dispose();
sheet.dispose(); sheet.dispose();
...@@ -79,13 +82,16 @@ public class MBeansTab extends Tab implements ...@@ -79,13 +82,16 @@ public class MBeansTab extends Tab implements
return vmPanel.getUpdateInterval(); return vmPanel.getUpdateInterval();
} }
void synchroniseMBeanServerView() { private void buildMBeanServerView() {
new SwingWorker<Set<ObjectName>, Void>() {
@Override
public Set<ObjectName> doInBackground() {
// Register listener for MBean registration/unregistration // Register listener for MBean registration/unregistration
// //
try { try {
getMBeanServerConnection().addNotificationListener( getMBeanServerConnection().addNotificationListener(
MBeanServerDelegate.DELEGATE_NAME, MBeanServerDelegate.DELEGATE_NAME,
this, MBeansTab.this,
null, null,
null); null);
} catch (InstanceNotFoundException e) { } catch (InstanceNotFoundException e) {
...@@ -100,40 +106,55 @@ public class MBeansTab extends Tab implements ...@@ -100,40 +106,55 @@ public class MBeansTab extends Tab implements
e.printStackTrace(); e.printStackTrace();
} }
vmPanel.getProxyClient().markAsDead(); vmPanel.getProxyClient().markAsDead();
return; return null;
} }
// Retrieve MBeans from MBeanServer // Retrieve MBeans from MBeanServer
// //
Set<ObjectName> newSet = null; Set<ObjectName> mbeans = null;
try { try {
newSet = getMBeanServerConnection().queryNames(null,null); mbeans = getMBeanServerConnection().queryNames(null, null);
} catch (IOException e) { } catch (IOException e) {
if (JConsole.isDebug()) { if (JConsole.isDebug()) {
e.printStackTrace(); e.printStackTrace();
} }
vmPanel.getProxyClient().markAsDead(); vmPanel.getProxyClient().markAsDead();
return; return null;
} }
// Cleanup current tree return mbeans;
// }
tree.removeAll(); @Override
protected void done() {
try {
// Wait for mbsc.queryNames() result
Set<ObjectName> mbeans = get();
// Do not display anything until the new tree has been built // Do not display anything until the new tree has been built
// //
tree.setVisible(false); tree.setVisible(false);
// Cleanup current tree
//
tree.removeAll();
// Add MBeans to tree // Add MBeans to tree
// //
for (ObjectName mbean : newSet) { tree.addMBeansToView(mbeans);
tree.addMBeanToView(mbean);
}
// Display the new tree // Display the new tree
// //
tree.setVisible(true); tree.setVisible(true);
} catch (Exception e) {
Throwable t = Utils.getActualException(e);
if (JConsole.isDebug()) {
System.err.println("Problem at MBean tree construction");
t.printStackTrace();
}
}
}
}.execute();
} }
public MBeanServerConnection getMBeanServerConnection() { public MBeanServerConnection getMBeanServerConnection() {
return vmPanel.getProxyClient().getMBeanServerConnection(); return vmPanel.getProxyClient().getMBeanServerConnection();
} }
@Override
public void update() { public void update() {
// Ping the connection to see if it is still alive. At // Ping the connection to see if it is still alive. At
// some point the ProxyClient class should centralize // some point the ProxyClient class should centralize
...@@ -160,6 +181,7 @@ public class MBeansTab extends Tab implements ...@@ -160,6 +181,7 @@ public class MBeansTab extends Tab implements
tree.getSelectionModel().setSelectionMode( tree.getSelectionModel().setSelectionMode(
TreeSelectionModel.SINGLE_TREE_SELECTION); TreeSelectionModel.SINGLE_TREE_SELECTION);
tree.addTreeSelectionListener(this); tree.addTreeSelectionListener(this);
tree.addTreeWillExpandListener(this);
tree.addMouseListener(ml); tree.addMouseListener(ml);
JScrollPane theScrollPane = new JScrollPane( JScrollPane theScrollPane = new JScrollPane(
tree, tree,
...@@ -177,8 +199,11 @@ public class MBeansTab extends Tab implements ...@@ -177,8 +199,11 @@ public class MBeansTab extends Tab implements
add(mainSplit); add(mainSplit);
} }
/* notification listener */ /* notification listener: handleNotification */
public void handleNotification(Notification notification, Object handback) { public void handleNotification(
final Notification notification, Object handback) {
EventQueue.invokeLater(new Runnable() {
public void run() {
if (notification instanceof MBeanServerNotification) { if (notification instanceof MBeanServerNotification) {
ObjectName mbean = ObjectName mbean =
((MBeanServerNotification) notification).getMBeanName(); ((MBeanServerNotification) notification).getMBeanName();
...@@ -187,45 +212,42 @@ public class MBeansTab extends Tab implements ...@@ -187,45 +212,42 @@ public class MBeansTab extends Tab implements
tree.addMBeanToView(mbean); tree.addMBeanToView(mbean);
} else if (notification.getType().equals( } else if (notification.getType().equals(
MBeanServerNotification.UNREGISTRATION_NOTIFICATION)) { MBeanServerNotification.UNREGISTRATION_NOTIFICATION)) {
tree.delMBeanFromView(mbean); tree.removeMBeanFromView(mbean);
} }
} }
} }
});
}
/* property change listener */ /* property change listener: propertyChange */
public void propertyChange(PropertyChangeEvent evt) { public void propertyChange(PropertyChangeEvent evt) {
if (evt.getPropertyName() == JConsoleContext.CONNECTION_STATE_PROPERTY) { if (JConsoleContext.CONNECTION_STATE_PROPERTY.equals(evt.getPropertyName())) {
boolean connected = (Boolean) evt.getNewValue(); boolean connected = (Boolean) evt.getNewValue();
if (connected) { if (connected) {
workerAdd(new Runnable() { buildMBeanServerView();
public void run() {
synchroniseMBeanServerView();
}
});
} else { } else {
sheet.dispose(); sheet.dispose();
} }
} }
} }
/* tree selection listener */ /* tree selection listener: valueChanged */
public void valueChanged(TreeSelectionEvent e) { public void valueChanged(TreeSelectionEvent e) {
DefaultMutableTreeNode node = DefaultMutableTreeNode node =
(DefaultMutableTreeNode) tree.getLastSelectedPathComponent(); (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
sheet.displayNode(node); sheet.displayNode(node);
} }
/* tree mouse listener: mousePressed */
/* tree mouse listener */
private MouseListener ml = new MouseAdapter() { private MouseListener ml = new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) { public void mousePressed(MouseEvent e) {
if (e.getClickCount() == 1) { if (e.getClickCount() == 1) {
int selRow = tree.getRowForLocation(e.getX(), e.getY()); int selRow = tree.getRowForLocation(e.getX(), e.getY());
if (selRow != -1) { if (selRow != -1) {
TreePath selPath = TreePath selPath =
tree.getPathForLocation(e.getX(), e.getY()); tree.getPathForLocation(e.getX(), e.getY());
DefaultMutableTreeNode node = (DefaultMutableTreeNode) DefaultMutableTreeNode node =
selPath.getLastPathComponent(); (DefaultMutableTreeNode) selPath.getLastPathComponent();
if (sheet.isMBeanNode(node)) { if (sheet.isMBeanNode(node)) {
tree.expandPath(selPath); tree.expandPath(selPath);
} }
...@@ -233,4 +255,22 @@ public class MBeansTab extends Tab implements ...@@ -233,4 +255,22 @@ public class MBeansTab extends Tab implements
} }
} }
}; };
/* tree will expand listener: treeWillExpand */
public void treeWillExpand(TreeExpansionEvent e)
throws ExpandVetoException {
TreePath path = e.getPath();
if (!tree.hasBeenExpanded(path)) {
DefaultMutableTreeNode node =
(DefaultMutableTreeNode) path.getLastPathComponent();
if (sheet.isMBeanNode(node) && !tree.hasMetadataNodes(node)) {
tree.addMetadataNodes(node);
}
}
}
/* tree will expand listener: treeWillCollapse */
public void treeWillCollapse(TreeExpansionEvent e)
throws ExpandVetoException {
}
} }
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
* CA 95054 USA or visit www.sun.com if you need additional information or * CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions. * have any questions.
*/ */
package sun.tools.jconsole; package sun.tools.jconsole;
import java.lang.management.MemoryUsage; import java.lang.management.MemoryUsage;
......
...@@ -45,6 +45,7 @@ import static sun.tools.jconsole.ProxyClient.*; ...@@ -45,6 +45,7 @@ import static sun.tools.jconsole.ProxyClient.*;
@SuppressWarnings("serial") @SuppressWarnings("serial")
public class VMPanel extends JTabbedPane implements PropertyChangeListener { public class VMPanel extends JTabbedPane implements PropertyChangeListener {
private ProxyClient proxyClient; private ProxyClient proxyClient;
private Timer timer; private Timer timer;
private int updateInterval; private int updateInterval;
...@@ -55,12 +56,9 @@ public class VMPanel extends JTabbedPane implements PropertyChangeListener { ...@@ -55,12 +56,9 @@ public class VMPanel extends JTabbedPane implements PropertyChangeListener {
private String password; private String password;
private String url; private String url;
private VMInternalFrame vmIF = null; private VMInternalFrame vmIF = null;
private static final String windowsLaF = private static final String windowsLaF =
"com.sun.java.swing.plaf.windows.WindowsLookAndFeel"; "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
private static ArrayList<TabInfo> tabInfos = new ArrayList<TabInfo>(); private static ArrayList<TabInfo> tabInfos = new ArrayList<TabInfo>();
private boolean wasConnected = false; private boolean wasConnected = false;
// The everConnected flag keeps track of whether the window can be // The everConnected flag keeps track of whether the window can be
...@@ -76,7 +74,7 @@ public class VMPanel extends JTabbedPane implements PropertyChangeListener { ...@@ -76,7 +74,7 @@ public class VMPanel extends JTabbedPane implements PropertyChangeListener {
// Each VMPanel has its own instance of the JConsolePlugin // Each VMPanel has its own instance of the JConsolePlugin
// A map of JConsolePlugin to the previous SwingWorker // A map of JConsolePlugin to the previous SwingWorker
private Map<JConsolePlugin, SwingWorker<?,?>> plugins = null; private Map<JConsolePlugin, SwingWorker<?, ?>> plugins = null;
private boolean pluginTabsAdded = false; private boolean pluginTabsAdded = false;
// Update these only on the EDT // Update these only on the EDT
...@@ -113,7 +111,7 @@ public class VMPanel extends JTabbedPane implements PropertyChangeListener { ...@@ -113,7 +111,7 @@ public class VMPanel extends JTabbedPane implements PropertyChangeListener {
} }
} }
plugins = new LinkedHashMap<JConsolePlugin, SwingWorker<?,?>>(); plugins = new LinkedHashMap<JConsolePlugin, SwingWorker<?, ?>>();
for (JConsolePlugin p : JConsole.getPlugins()) { for (JConsolePlugin p : JConsole.getPlugins()) {
p.setContext(proxyClient); p.setContext(proxyClient);
plugins.put(p, null); plugins.put(p, null);
...@@ -128,10 +126,9 @@ public class VMPanel extends JTabbedPane implements PropertyChangeListener { ...@@ -128,10 +126,9 @@ public class VMPanel extends JTabbedPane implements PropertyChangeListener {
proxyClient.addPropertyChangeListener(this); proxyClient.addPropertyChangeListener(this);
addMouseListener(new MouseAdapter() { addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) { public void mouseClicked(MouseEvent e) {
if (connectedIconBounds != null if (connectedIconBounds != null && (e.getModifiers() & MouseEvent.BUTTON1_MASK) != 0 && connectedIconBounds.contains(e.getPoint())) {
&& (e.getModifiers() & MouseEvent.BUTTON1_MASK) != 0
&& connectedIconBounds.contains(e.getPoint())) {
if (isConnected()) { if (isConnected()) {
disconnect(); disconnect();
...@@ -145,7 +142,6 @@ public class VMPanel extends JTabbedPane implements PropertyChangeListener { ...@@ -145,7 +142,6 @@ public class VMPanel extends JTabbedPane implements PropertyChangeListener {
}); });
} }
private static Icon connectedIcon16 = private static Icon connectedIcon16 =
new ImageIcon(VMPanel.class.getResource("resources/connected16.png")); new ImageIcon(VMPanel.class.getResource("resources/connected16.png"));
private static Icon connectedIcon24 = private static Icon connectedIcon24 =
...@@ -154,14 +150,13 @@ public class VMPanel extends JTabbedPane implements PropertyChangeListener { ...@@ -154,14 +150,13 @@ public class VMPanel extends JTabbedPane implements PropertyChangeListener {
new ImageIcon(VMPanel.class.getResource("resources/disconnected16.png")); new ImageIcon(VMPanel.class.getResource("resources/disconnected16.png"));
private static Icon disconnectedIcon24 = private static Icon disconnectedIcon24 =
new ImageIcon(VMPanel.class.getResource("resources/disconnected24.png")); new ImageIcon(VMPanel.class.getResource("resources/disconnected24.png"));
private Rectangle connectedIconBounds; private Rectangle connectedIconBounds;
// Override to increase right inset for tab area, // Override to increase right inset for tab area,
// in order to reserve space for the connect toggle. // in order to reserve space for the connect toggle.
public void setUI(TabbedPaneUI ui) { public void setUI(TabbedPaneUI ui) {
Insets insets = (Insets)UIManager.getLookAndFeelDefaults().get("TabbedPane.tabAreaInsets"); Insets insets = (Insets) UIManager.getLookAndFeelDefaults().get("TabbedPane.tabAreaInsets");
insets = (Insets)insets.clone(); insets = (Insets) insets.clone();
insets.right += connectedIcon24.getIconWidth() + 8; insets.right += connectedIcon24.getIconWidth() + 8;
UIManager.put("TabbedPane.tabAreaInsets", insets); UIManager.put("TabbedPane.tabAreaInsets", insets);
super.setUI(ui); super.setUI(ui);
...@@ -225,7 +220,7 @@ public class VMPanel extends JTabbedPane implements PropertyChangeListener { ...@@ -225,7 +220,7 @@ public class VMPanel extends JTabbedPane implements PropertyChangeListener {
private Tab instantiate(TabInfo tabInfo) { private Tab instantiate(TabInfo tabInfo) {
try { try {
Constructor con = tabInfo.tabClass.getConstructor(VMPanel.class); Constructor con = tabInfo.tabClass.getConstructor(VMPanel.class);
return (Tab)con.newInstance(this); return (Tab) con.newInstance(this);
} catch (Exception ex) { } catch (Exception ex) {
System.err.println(ex); System.err.println(ex);
return null; return null;
...@@ -247,11 +242,12 @@ public class VMPanel extends JTabbedPane implements PropertyChangeListener { ...@@ -247,11 +242,12 @@ public class VMPanel extends JTabbedPane implements PropertyChangeListener {
* IT IS USED TO MAKE SOME LOCAL MANIPULATIONS. * IT IS USED TO MAKE SOME LOCAL MANIPULATIONS.
*/ */
ProxyClient getProxyClient(boolean assertThread) { ProxyClient getProxyClient(boolean assertThread) {
if(assertThread) if (assertThread) {
return getProxyClient(); return getProxyClient();
else } else {
return proxyClient; return proxyClient;
} }
}
public ProxyClient getProxyClient() { public ProxyClient getProxyClient() {
String threadClass = Thread.currentThread().getClass().getName(); String threadClass = Thread.currentThread().getClass().getName();
...@@ -294,6 +290,7 @@ public class VMPanel extends JTabbedPane implements PropertyChangeListener { ...@@ -294,6 +290,7 @@ public class VMPanel extends JTabbedPane implements PropertyChangeListener {
startUpdateTimer(); startUpdateTimer();
} else { } else {
new Thread("VMPanel.connect") { new Thread("VMPanel.connect") {
public void run() { public void run() {
proxyClient.connect(); proxyClient.connect();
} }
...@@ -301,22 +298,19 @@ public class VMPanel extends JTabbedPane implements PropertyChangeListener { ...@@ -301,22 +298,19 @@ public class VMPanel extends JTabbedPane implements PropertyChangeListener {
} }
} }
// Call on EDT // Call on EDT
public void disconnect() { public void disconnect() {
proxyClient.disconnect(); proxyClient.disconnect();
updateFrameTitle(); updateFrameTitle();
} }
// Called on EDT // Called on EDT
public void propertyChange(PropertyChangeEvent ev) { public void propertyChange(PropertyChangeEvent ev) {
String prop = ev.getPropertyName(); String prop = ev.getPropertyName();
if (prop == CONNECTION_STATE_PROPERTY) { if (prop == CONNECTION_STATE_PROPERTY) {
ConnectionState oldState = (ConnectionState)ev.getOldValue(); ConnectionState oldState = (ConnectionState) ev.getOldValue();
ConnectionState newState = (ConnectionState)ev.getNewValue(); ConnectionState newState = (ConnectionState) ev.getNewValue();
switch (newState) { switch (newState) {
case CONNECTING: case CONNECTING:
onConnecting(); onConnecting();
...@@ -356,13 +350,11 @@ public class VMPanel extends JTabbedPane implements PropertyChangeListener { ...@@ -356,13 +350,11 @@ public class VMPanel extends JTabbedPane implements PropertyChangeListener {
} }
} }
// Called on EDT // Called on EDT
private void onConnecting() { private void onConnecting() {
time0 = System.currentTimeMillis(); time0 = System.currentTimeMillis();
final JConsole jc = (JConsole)SwingUtilities.getWindowAncestor(this); final JConsole jc = (JConsole) SwingUtilities.getWindowAncestor(this);
String connectionName = getConnectionName(); String connectionName = getConnectionName();
progressBar = new JProgressBar(); progressBar = new JProgressBar();
...@@ -376,13 +368,12 @@ public class VMPanel extends JTabbedPane implements PropertyChangeListener { ...@@ -376,13 +368,12 @@ public class VMPanel extends JTabbedPane implements PropertyChangeListener {
"<html><b>" + getText("connectingTo2", connectionName) + "</b></html>" "<html><b>" + getText("connectingTo2", connectionName) + "</b></html>"
}; };
optionPane = optionPane =
SheetDialog.showOptionDialog(this, SheetDialog.showOptionDialog(this,
message, message,
JOptionPane.DEFAULT_OPTION, JOptionPane.DEFAULT_OPTION,
JOptionPane.INFORMATION_MESSAGE, null, JOptionPane.INFORMATION_MESSAGE, null,
new String[] { getText("Cancel") }, new String[]{getText("Cancel")},
0); 0);
...@@ -402,6 +393,7 @@ public class VMPanel extends JTabbedPane implements PropertyChangeListener { ...@@ -402,6 +393,7 @@ public class VMPanel extends JTabbedPane implements PropertyChangeListener {
} }
} }
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(new Runnable() {
public void run() { public void run() {
optionPane.setVisible(false); optionPane.setVisible(false);
progressBar = null; progressBar = null;
...@@ -425,7 +417,7 @@ public class VMPanel extends JTabbedPane implements PropertyChangeListener { ...@@ -425,7 +417,7 @@ public class VMPanel extends JTabbedPane implements PropertyChangeListener {
private VMInternalFrame getFrame() { private VMInternalFrame getFrame() {
if (vmIF == null) { if (vmIF == null) {
vmIF = (VMInternalFrame)SwingUtilities.getAncestorOfClass(VMInternalFrame.class, vmIF = (VMInternalFrame) SwingUtilities.getAncestorOfClass(VMInternalFrame.class,
this); this);
} }
return vmIF; return vmIF;
...@@ -452,21 +444,21 @@ public class VMPanel extends JTabbedPane implements PropertyChangeListener { ...@@ -452,21 +444,21 @@ public class VMPanel extends JTabbedPane implements PropertyChangeListener {
timer.cancel(); timer.cancel();
} }
TimerTask timerTask = new TimerTask() { TimerTask timerTask = new TimerTask() {
public void run() { public void run() {
update(); update();
} }
}; };
String timerName = "Timer-"+getConnectionName(); String timerName = "Timer-" + getConnectionName();
timer = new Timer(timerName, true); timer = new Timer(timerName, true);
timer.schedule(timerTask, 0, updateInterval); timer.schedule(timerTask, 0, updateInterval);
} }
// Call on EDT // Call on EDT
private void vmPanelDied() { private void vmPanelDied() {
disconnect(); disconnect();
final JConsole jc = (JConsole)SwingUtilities.getWindowAncestor(this); final JConsole jc = (JConsole) SwingUtilities.getWindowAncestor(this);
JOptionPane optionPane; JOptionPane optionPane;
...@@ -493,10 +485,11 @@ public class VMPanel extends JTabbedPane implements PropertyChangeListener { ...@@ -493,10 +485,11 @@ public class VMPanel extends JTabbedPane implements PropertyChangeListener {
"<b>" + msgExplanation + "</b>", "<b>" + msgExplanation + "</b>",
JOptionPane.DEFAULT_OPTION, JOptionPane.DEFAULT_OPTION,
JOptionPane.WARNING_MESSAGE, null, JOptionPane.WARNING_MESSAGE, null,
new String[] { buttonStr, cancelStr }, new String[]{buttonStr, cancelStr},
0); 0);
optionPane.addPropertyChangeListener(new PropertyChangeListener() { optionPane.addPropertyChangeListener(new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent event) { public void propertyChange(PropertyChangeEvent event) {
if (event.getPropertyName().equals(JOptionPane.VALUE_PROPERTY)) { if (event.getPropertyName().equals(JOptionPane.VALUE_PROPERTY)) {
Object value = event.getNewValue(); Object value = event.getNewValue();
...@@ -518,11 +511,13 @@ public class VMPanel extends JTabbedPane implements PropertyChangeListener { ...@@ -518,11 +511,13 @@ public class VMPanel extends JTabbedPane implements PropertyChangeListener {
// Note: This method is called on a TimerTask thread. Any GUI manipulation // Note: This method is called on a TimerTask thread. Any GUI manipulation
// must be performed with invokeLater() or invokeAndWait(). // must be performed with invokeLater() or invokeAndWait().
private Object lockObject = new Object(); private Object lockObject = new Object();
private void update() { private void update() {
synchronized(lockObject) { synchronized (lockObject) {
if (!isConnected()) { if (!isConnected()) {
if (wasConnected) { if (wasConnected) {
EventQueue.invokeLater(new Runnable() { EventQueue.invokeLater(new Runnable() {
public void run() { public void run() {
vmPanelDied(); vmPanelDied();
} }
...@@ -548,6 +543,7 @@ public class VMPanel extends JTabbedPane implements PropertyChangeListener { ...@@ -548,6 +543,7 @@ public class VMPanel extends JTabbedPane implements PropertyChangeListener {
// //
if (initialUpdate) { if (initialUpdate) {
EventQueue.invokeLater(new Runnable() { EventQueue.invokeLater(new Runnable() {
public void run() { public void run() {
setEnabledAt(index, true); setEnabledAt(index, true);
} }
...@@ -569,8 +565,8 @@ public class VMPanel extends JTabbedPane implements PropertyChangeListener { ...@@ -569,8 +565,8 @@ public class VMPanel extends JTabbedPane implements PropertyChangeListener {
// plugin GUI update // plugin GUI update
for (JConsolePlugin p : plugins.keySet()) { for (JConsolePlugin p : plugins.keySet()) {
SwingWorker<?,?> sw = p.newSwingWorker(); SwingWorker<?, ?> sw = p.newSwingWorker();
SwingWorker<?,?> prevSW = plugins.get(p); SwingWorker<?, ?> prevSW = plugins.get(p);
// schedule SwingWorker to run only if the previous // schedule SwingWorker to run only if the previous
// SwingWorker has finished its task and it hasn't started. // SwingWorker has finished its task and it hasn't started.
if (prevSW == null || prevSW.isDone()) { if (prevSW == null || prevSW.isDone()) {
...@@ -583,7 +579,7 @@ public class VMPanel extends JTabbedPane implements PropertyChangeListener { ...@@ -583,7 +579,7 @@ public class VMPanel extends JTabbedPane implements PropertyChangeListener {
} }
} }
// Set the first enabled tab in the tabs list // Set the first enabled tab in the tab's list
// as the selected tab on initial update // as the selected tab on initial update
// //
if (initialUpdate) { if (initialUpdate) {
...@@ -622,7 +618,6 @@ public class VMPanel extends JTabbedPane implements PropertyChangeListener { ...@@ -622,7 +618,6 @@ public class VMPanel extends JTabbedPane implements PropertyChangeListener {
return url; return url;
} }
public String getPassword() { public String getPassword() {
return password; return password;
} }
...@@ -636,6 +631,7 @@ public class VMPanel extends JTabbedPane implements PropertyChangeListener { ...@@ -636,6 +631,7 @@ public class VMPanel extends JTabbedPane implements PropertyChangeListener {
} }
static class TabInfo { static class TabInfo {
Class<? extends Tab> tabClass; Class<? extends Tab> tabClass;
String name; String name;
boolean tabVisible; boolean tabVisible;
......
...@@ -22,8 +22,8 @@ ...@@ -22,8 +22,8 @@
* CA 95054 USA or visit www.sun.com if you need additional information or * CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions. * have any questions.
*/ */
package sun.tools.jconsole.inspector;
package sun.tools.jconsole.inspector;
// java import // java import
import java.awt.*; import java.awt.*;
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
* CA 95054 USA or visit www.sun.com if you need additional information or * CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions. * have any questions.
*/ */
package sun.tools.jconsole.inspector; package sun.tools.jconsole.inspector;
import java.util.*; import java.util.*;
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
* CA 95054 USA or visit www.sun.com if you need additional information or * CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions. * have any questions.
*/ */
package sun.tools.jconsole.inspector; package sun.tools.jconsole.inspector;
// java import // java import
......
/* /*
* Copyright 2004-2006 Sun Microsystems, Inc. All Rights Reserved. * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -29,55 +29,51 @@ import java.awt.event.*; ...@@ -29,55 +29,51 @@ import java.awt.event.*;
import java.lang.reflect.*; import java.lang.reflect.*;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.BigInteger; import java.math.BigInteger;
import java.util.*;
import java.util.concurrent.ExecutionException;
import javax.management.*; import javax.management.*;
import javax.management.openmbean.*; import javax.management.openmbean.*;
import javax.swing.*; import javax.swing.*;
import javax.swing.text.*; import javax.swing.text.*;
import java.util.*;
public class Utils { public class Utils {
private Utils() { private Utils() {
} }
private static Set<Integer> tableNavigationKeys = private static Set<Integer> tableNavigationKeys =
new HashSet<Integer>(Arrays.asList(new Integer[] { new HashSet<Integer>(Arrays.asList(new Integer[]{
KeyEvent.VK_TAB, KeyEvent.VK_ENTER, KeyEvent.VK_TAB, KeyEvent.VK_ENTER,
KeyEvent.VK_HOME, KeyEvent.VK_END, KeyEvent.VK_HOME, KeyEvent.VK_END,
KeyEvent.VK_LEFT, KeyEvent.VK_RIGHT, KeyEvent.VK_LEFT, KeyEvent.VK_RIGHT,
KeyEvent.VK_UP, KeyEvent.VK_DOWN, KeyEvent.VK_UP, KeyEvent.VK_DOWN,
KeyEvent.VK_PAGE_UP, KeyEvent.VK_PAGE_DOWN})); KeyEvent.VK_PAGE_UP, KeyEvent.VK_PAGE_DOWN
}));
private static final Set<Class<?>> primitiveWrappers = private static final Set<Class<?>> primitiveWrappers =
new HashSet<Class<?>>(Arrays.asList(new Class<?>[] { new HashSet<Class<?>>(Arrays.asList(new Class<?>[]{
Byte.class, Short.class, Integer.class, Long.class, Byte.class, Short.class, Integer.class, Long.class,
Float.class, Double.class, Character.class, Boolean.class})); Float.class, Double.class, Character.class, Boolean.class
}));
private static final Set<Class<?>> primitives = new HashSet<Class<?>>(); private static final Set<Class<?>> primitives = new HashSet<Class<?>>();
private static final Map<String, Class<?>> primitiveMap = private static final Map<String, Class<?>> primitiveMap =
new HashMap<String, Class<?>>(); new HashMap<String, Class<?>>();
private static final Map<String, Class<?>> primitiveToWrapper = private static final Map<String, Class<?>> primitiveToWrapper =
new HashMap<String, Class<?>>(); new HashMap<String, Class<?>>();
private static final Set<String> editableTypes = new HashSet<String>(); private static final Set<String> editableTypes = new HashSet<String>();
private static final Set<Class<?>> extraEditableClasses = private static final Set<Class<?>> extraEditableClasses =
new HashSet<Class<?>>(Arrays.asList(new Class<?>[] { new HashSet<Class<?>>(Arrays.asList(new Class<?>[]{
BigDecimal.class, BigInteger.class, Number.class, BigDecimal.class, BigInteger.class, Number.class,
String.class, ObjectName.class})); String.class, ObjectName.class
}));
private static final Set<String> numericalTypes = new HashSet<String>(); private static final Set<String> numericalTypes = new HashSet<String>();
private static final Set<String> extraNumericalTypes = private static final Set<String> extraNumericalTypes =
new HashSet<String>(Arrays.asList(new String[] { new HashSet<String>(Arrays.asList(new String[]{
BigDecimal.class.getName(), BigInteger.class.getName(), BigDecimal.class.getName(), BigInteger.class.getName(),
Number.class.getName()})); Number.class.getName()
}));
private static final Set<String> booleanTypes = private static final Set<String> booleanTypes =
new HashSet<String>(Arrays.asList(new String[] { new HashSet<String>(Arrays.asList(new String[]{
Boolean.TYPE.getName(), Boolean.class.getName()})); Boolean.TYPE.getName(), Boolean.class.getName()
}));
static { static {
// compute primitives/primitiveMap/primitiveToWrapper // compute primitives/primitiveMap/primitiveToWrapper
...@@ -124,8 +120,9 @@ public class Utils { ...@@ -124,8 +120,9 @@ public class Utils {
public static Class<?> getClass(String className) public static Class<?> getClass(String className)
throws ClassNotFoundException { throws ClassNotFoundException {
Class<?> c; Class<?> c;
if ((c = primitiveMap.get(className)) != null) if ((c = primitiveMap.get(className)) != null) {
return c; return c;
}
return Class.forName(className); return Class.forName(className);
} }
...@@ -155,7 +152,9 @@ public class Utils { ...@@ -155,7 +152,9 @@ public class Utils {
* structure, i.e. a data structure jconsole can render as an array. * structure, i.e. a data structure jconsole can render as an array.
*/ */
public static boolean canBeRenderedAsArray(Object elem) { public static boolean canBeRenderedAsArray(Object elem) {
if (isSupportedArray(elem)) return true; if (isSupportedArray(elem)) {
return true;
}
if (elem instanceof Collection) { if (elem instanceof Collection) {
Collection<?> c = (Collection<?>) elem; Collection<?> c = (Collection<?>) elem;
if (c.isEmpty()) { if (c.isEmpty()) {
...@@ -239,7 +238,9 @@ public class Utils { ...@@ -239,7 +238,9 @@ public class Utils {
*/ */
public static String getReadableClassName(String name) { public static String getReadableClassName(String name) {
String className = getArrayClassName(name); String className = getArrayClassName(name);
if (className == null) return name; if (className == null) {
return name;
}
int index = name.lastIndexOf("["); int index = name.lastIndexOf("[");
StringBuilder brackets = new StringBuilder(className); StringBuilder brackets = new StringBuilder(className);
for (int i = 0; i <= index; i++) { for (int i = 0; i <= index; i++) {
...@@ -388,12 +389,17 @@ public class Utils { ...@@ -388,12 +389,17 @@ public class Utils {
* If the exception is wrapped, unwrap it. * If the exception is wrapped, unwrap it.
*/ */
public static Throwable getActualException(Throwable e) { public static Throwable getActualException(Throwable e) {
if (e instanceof ExecutionException) {
e = e.getCause();
}
if (e instanceof MBeanException || if (e instanceof MBeanException ||
e instanceof RuntimeMBeanException || e instanceof RuntimeMBeanException ||
e instanceof RuntimeOperationsException || e instanceof RuntimeOperationsException ||
e instanceof ReflectionException) { e instanceof ReflectionException) {
Throwable t = e.getCause(); Throwable t = e.getCause();
if (t != null) return t; if (t != null) {
return t;
}
} }
return e; return e;
} }
...@@ -401,6 +407,7 @@ public class Utils { ...@@ -401,6 +407,7 @@ public class Utils {
@SuppressWarnings("serial") @SuppressWarnings("serial")
public static class ReadOnlyTableCellEditor public static class ReadOnlyTableCellEditor
extends DefaultCellEditor { extends DefaultCellEditor {
public ReadOnlyTableCellEditor(JTextField tf) { public ReadOnlyTableCellEditor(JTextField tf) {
super(tf); super(tf);
tf.addFocusListener(new Utils.EditFocusAdapter(this)); tf.addFocusListener(new Utils.EditFocusAdapter(this));
...@@ -409,20 +416,25 @@ public class Utils { ...@@ -409,20 +416,25 @@ public class Utils {
} }
public static class EditFocusAdapter extends FocusAdapter { public static class EditFocusAdapter extends FocusAdapter {
private CellEditor editor; private CellEditor editor;
public EditFocusAdapter(CellEditor editor) { public EditFocusAdapter(CellEditor editor) {
this.editor = editor; this.editor = editor;
} }
@Override
public void focusLost(FocusEvent e) { public void focusLost(FocusEvent e) {
editor.stopCellEditing(); editor.stopCellEditing();
} }
}; }
public static class CopyKeyAdapter extends KeyAdapter { public static class CopyKeyAdapter extends KeyAdapter {
private static final String defaultEditorKitCopyActionName = private static final String defaultEditorKitCopyActionName =
DefaultEditorKit.copyAction; DefaultEditorKit.copyAction;
private static final String transferHandlerCopyActionName = private static final String transferHandlerCopyActionName =
(String) TransferHandler.getCopyAction().getValue(Action.NAME); (String) TransferHandler.getCopyAction().getValue(Action.NAME);
@Override
public void keyPressed(KeyEvent e) { public void keyPressed(KeyEvent e) {
// Accept "copy" key strokes // Accept "copy" key strokes
KeyStroke ks = KeyStroke.getKeyStroke( KeyStroke ks = KeyStroke.getKeyStroke(
...@@ -441,6 +453,8 @@ public class Utils { ...@@ -441,6 +453,8 @@ public class Utils {
e.consume(); e.consume();
} }
} }
@Override
public void keyTyped(KeyEvent e) { public void keyTyped(KeyEvent e) {
e.consume(); e.consume();
} }
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
* CA 95054 USA or visit www.sun.com if you need additional information or * CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions. * have any questions.
*/ */
package sun.tools.jconsole.inspector; package sun.tools.jconsole.inspector;
import javax.swing.JTable; import javax.swing.JTable;
...@@ -108,6 +109,7 @@ public class XDataViewer { ...@@ -108,6 +109,7 @@ public class XDataViewer {
public Component createOperationViewer(Object value, public Component createOperationViewer(Object value,
XMBean mbean) { XMBean mbean) {
if(value instanceof Number) return null; if(value instanceof Number) return null;
if(value instanceof Component) return (Component) value;
return createAttributeViewer(value, mbean, null, null); return createAttributeViewer(value, mbean, null, null);
} }
......
/* /*
* Copyright 2004-2006 Sun Microsystems, Inc. All Rights Reserved. * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -28,48 +28,57 @@ package sun.tools.jconsole.inspector; ...@@ -28,48 +28,57 @@ package sun.tools.jconsole.inspector;
import java.io.IOException; import java.io.IOException;
import javax.management.*; import javax.management.*;
import javax.swing.Icon; import javax.swing.Icon;
import sun.tools.jconsole.JConsole;
import sun.tools.jconsole.MBeansTab; import sun.tools.jconsole.MBeansTab;
public class XMBean extends Object { public class XMBean {
private ObjectName objectName;
private final MBeansTab mbeansTab;
private final ObjectName objectName;
private Icon icon; private Icon icon;
private String text; private String text;
private boolean broadcaster; private Boolean broadcaster;
private final Object broadcasterLock = new Object();
private MBeanInfo mbeanInfo; private MBeanInfo mbeanInfo;
private MBeansTab mbeansTab; private final Object mbeanInfoLock = new Object();
public XMBean(ObjectName objectName, MBeansTab mbeansTab) public XMBean(ObjectName objectName, MBeansTab mbeansTab) {
throws InstanceNotFoundException, IntrospectionException,
ReflectionException, IOException {
this.mbeansTab = mbeansTab; this.mbeansTab = mbeansTab;
setObjectName(objectName); this.objectName = objectName;
text = objectName.getKeyProperty("name");
if (text == null) {
text = objectName.getDomain();
}
if (MBeanServerDelegate.DELEGATE_NAME.equals(objectName)) { if (MBeanServerDelegate.DELEGATE_NAME.equals(objectName)) {
icon = IconManager.MBEANSERVERDELEGATE; icon = IconManager.MBEANSERVERDELEGATE;
} else { } else {
icon = IconManager.MBEAN; icon = IconManager.MBEAN;
} }
this.broadcaster = isBroadcaster(objectName);
this.mbeanInfo = getMBeanInfo(objectName);
} }
MBeanServerConnection getMBeanServerConnection() { MBeanServerConnection getMBeanServerConnection() {
return mbeansTab.getMBeanServerConnection(); return mbeansTab.getMBeanServerConnection();
} }
public boolean isBroadcaster() { public Boolean isBroadcaster() {
return broadcaster; synchronized (broadcasterLock) {
} if (broadcaster == null) {
private boolean isBroadcaster(ObjectName name) {
try { try {
return getMBeanServerConnection().isInstanceOf( broadcaster = getMBeanServerConnection().isInstanceOf(
name, "javax.management.NotificationBroadcaster"); getObjectName(),
"javax.management.NotificationBroadcaster");
} catch (Exception e) { } catch (Exception e) {
System.out.println("Error calling isBroadcaster: " + if (JConsole.isDebug()) {
e.getMessage()); System.err.println("Couldn't check if MBean [" +
objectName + "] is a notification broadcaster");
e.printStackTrace();
} }
return false; return false;
} }
}
return broadcaster;
}
}
public Object invoke(String operationName) throws Exception { public Object invoke(String operationName) throws Exception {
Object result = getMBeanServerConnection().invoke( Object result = getMBeanServerConnection().invoke(
...@@ -119,33 +128,35 @@ public class XMBean extends Object { ...@@ -119,33 +128,35 @@ public class XMBean extends Object {
return objectName; return objectName;
} }
private void setObjectName(ObjectName objectName) { public MBeanInfo getMBeanInfo() throws InstanceNotFoundException,
this.objectName = objectName; IntrospectionException, ReflectionException, IOException {
// generate a readable name now synchronized (mbeanInfoLock) {
String name = getObjectName().getKeyProperty("name"); if (mbeanInfo == null) {
if (name == null) mbeanInfo = getMBeanServerConnection().getMBeanInfo(objectName);
setText(getObjectName().getDomain());
else
setText(name);
} }
public MBeanInfo getMBeanInfo() {
return mbeanInfo; return mbeanInfo;
} }
private MBeanInfo getMBeanInfo(ObjectName name)
throws InstanceNotFoundException, IntrospectionException,
ReflectionException, IOException {
return getMBeanServerConnection().getMBeanInfo(name);
} }
public boolean equals(Object o) { @Override
if (o instanceof XMBean) { public boolean equals(Object obj) {
XMBean mbean = (XMBean) o; if (obj == null) {
return getObjectName().equals((mbean).getObjectName()); return false;
}
if (obj == this) {
return true;
} }
if (!(obj instanceof XMBean)) {
return false; return false;
} }
XMBean that = (XMBean) obj;
return getObjectName().equals(that.getObjectName());
}
@Override
public int hashCode() {
return (objectName == null ? 0 : objectName.hashCode());
}
public String getText() { public String getText() {
return text; return text;
...@@ -163,6 +174,7 @@ public class XMBean extends Object { ...@@ -163,6 +174,7 @@ public class XMBean extends Object {
this.icon = icon; this.icon = icon;
} }
@Override
public String toString() { public String toString() {
return getText(); return getText();
} }
......
/* /*
* Copyright 2004-2006 Sun Microsystems, Inc. All Rights Reserved. * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -35,10 +35,7 @@ import javax.swing.*; ...@@ -35,10 +35,7 @@ import javax.swing.*;
import javax.swing.border.TitledBorder; import javax.swing.border.TitledBorder;
import javax.swing.event.*; import javax.swing.event.*;
import javax.swing.table.*; import javax.swing.table.*;
import javax.swing.tree.*;
import sun.tools.jconsole.JConsole;
import sun.tools.jconsole.Resources; import sun.tools.jconsole.Resources;
import sun.tools.jconsole.inspector.XNodeInfo.Type;
import static sun.tools.jconsole.Utilities.*; import static sun.tools.jconsole.Utilities.*;
...@@ -46,21 +43,20 @@ import static sun.tools.jconsole.Utilities.*; ...@@ -46,21 +43,20 @@ import static sun.tools.jconsole.Utilities.*;
public class XMBeanInfo extends JPanel { public class XMBeanInfo extends JPanel {
private static final Color lightYellow = new Color(255, 255, 128); private static final Color lightYellow = new Color(255, 255, 128);
private final int NAME_COLUMN = 0; private final int NAME_COLUMN = 0;
private final int VALUE_COLUMN = 1; private final int VALUE_COLUMN = 1;
private final String[] columnNames = { private final String[] columnNames = {
Resources.getText("Name"), Resources.getText("Name"),
Resources.getText("Value") Resources.getText("Value")
}; };
private JTable infoTable = new JTable(); private JTable infoTable = new JTable();
private JTable descTable = new JTable(); private JTable descTable = new JTable();
private JPanel infoBorderPanel = new JPanel(new BorderLayout()); private JPanel infoBorderPanel = new JPanel(new BorderLayout());
private JPanel descBorderPanel = new JPanel(new BorderLayout()); private JPanel descBorderPanel = new JPanel(new BorderLayout());
private static class ReadOnlyDefaultTableModel extends DefaultTableModel { private static class ReadOnlyDefaultTableModel extends DefaultTableModel {
@Override
public void setValueAt(Object value, int row, int col) { public void setValueAt(Object value, int row, int col) {
} }
} }
...@@ -73,17 +69,18 @@ public class XMBeanInfo extends JPanel { ...@@ -73,17 +69,18 @@ public class XMBeanInfo extends JPanel {
this.tableRowDividerText = tableRowDividerText; this.tableRowDividerText = tableRowDividerText;
} }
@Override
public String toString() { public String toString() {
return tableRowDividerText; return tableRowDividerText;
} }
} }
private static MBeanInfoTableCellRenderer renderer = private static MBeanInfoTableCellRenderer renderer =
new MBeanInfoTableCellRenderer(); new MBeanInfoTableCellRenderer();
private static class MBeanInfoTableCellRenderer private static class MBeanInfoTableCellRenderer
extends DefaultTableCellRenderer { extends DefaultTableCellRenderer {
@Override
public Component getTableCellRendererComponent( public Component getTableCellRendererComponent(
JTable table, Object value, boolean isSelected, JTable table, Object value, boolean isSelected,
boolean hasFocus, int row, int column) { boolean hasFocus, int row, int column) {
...@@ -99,15 +96,17 @@ public class XMBeanInfo extends JPanel { ...@@ -99,15 +96,17 @@ public class XMBeanInfo extends JPanel {
return comp; return comp;
} }
} }
private static TableCellEditor editor = private static TableCellEditor editor =
new MBeanInfoTableCellEditor(new JTextField()); new MBeanInfoTableCellEditor(new JTextField());
private static class MBeanInfoTableCellEditor private static class MBeanInfoTableCellEditor
extends Utils.ReadOnlyTableCellEditor { extends Utils.ReadOnlyTableCellEditor {
public MBeanInfoTableCellEditor(JTextField tf) { public MBeanInfoTableCellEditor(JTextField tf) {
super(tf); super(tf);
} }
@Override
public Component getTableCellEditorComponent( public Component getTableCellEditorComponent(
JTable table, Object value, boolean isSelected, JTable table, Object value, boolean isSelected,
int row, int column) { int row, int column) {
...@@ -172,6 +171,7 @@ public class XMBeanInfo extends JPanel { ...@@ -172,6 +171,7 @@ public class XMBeanInfo extends JPanel {
add(descBorderPanel); add(descBorderPanel);
} }
// Call on EDT
public void emptyInfoTable() { public void emptyInfoTable() {
DefaultTableModel tableModel = (DefaultTableModel) infoTable.getModel(); DefaultTableModel tableModel = (DefaultTableModel) infoTable.getModel();
while (tableModel.getRowCount() > 0) { while (tableModel.getRowCount() > 0) {
...@@ -179,6 +179,7 @@ public class XMBeanInfo extends JPanel { ...@@ -179,6 +179,7 @@ public class XMBeanInfo extends JPanel {
} }
} }
// Call on EDT
public void emptyDescTable() { public void emptyDescTable() {
DefaultTableModel tableModel = (DefaultTableModel) descTable.getModel(); DefaultTableModel tableModel = (DefaultTableModel) descTable.getModel();
while (tableModel.getRowCount() > 0) { while (tableModel.getRowCount() > 0) {
...@@ -186,6 +187,7 @@ public class XMBeanInfo extends JPanel { ...@@ -186,6 +187,7 @@ public class XMBeanInfo extends JPanel {
} }
} }
// Call on EDT
private void addDescriptor(Descriptor desc, String text) { private void addDescriptor(Descriptor desc, String text) {
if (desc != null && desc.getFieldNames().length > 0) { if (desc != null && desc.getFieldNames().length > 0) {
DefaultTableModel tableModel = (DefaultTableModel) descTable.getModel(); DefaultTableModel tableModel = (DefaultTableModel) descTable.getModel();
...@@ -223,6 +225,7 @@ public class XMBeanInfo extends JPanel { ...@@ -223,6 +225,7 @@ public class XMBeanInfo extends JPanel {
} }
} }
// Call on EDT
public void addMBeanInfo(XMBean mbean, MBeanInfo mbeanInfo) { public void addMBeanInfo(XMBean mbean, MBeanInfo mbeanInfo) {
emptyInfoTable(); emptyInfoTable();
emptyDescTable(); emptyDescTable();
...@@ -263,6 +266,7 @@ public class XMBeanInfo extends JPanel { ...@@ -263,6 +266,7 @@ public class XMBeanInfo extends JPanel {
tableModel.newDataAvailable(new TableModelEvent(tableModel)); tableModel.newDataAvailable(new TableModelEvent(tableModel));
} }
// Call on EDT
public void addMBeanAttributeInfo(MBeanAttributeInfo mbai) { public void addMBeanAttributeInfo(MBeanAttributeInfo mbai) {
emptyInfoTable(); emptyInfoTable();
emptyDescTable(); emptyDescTable();
...@@ -296,6 +300,7 @@ public class XMBeanInfo extends JPanel { ...@@ -296,6 +300,7 @@ public class XMBeanInfo extends JPanel {
tableModel.newDataAvailable(new TableModelEvent(tableModel)); tableModel.newDataAvailable(new TableModelEvent(tableModel));
} }
// Call on EDT
public void addMBeanOperationInfo(MBeanOperationInfo mboi) { public void addMBeanOperationInfo(MBeanOperationInfo mboi) {
emptyInfoTable(); emptyInfoTable();
emptyDescTable(); emptyDescTable();
...@@ -343,6 +348,7 @@ public class XMBeanInfo extends JPanel { ...@@ -343,6 +348,7 @@ public class XMBeanInfo extends JPanel {
tableModel.newDataAvailable(new TableModelEvent(tableModel)); tableModel.newDataAvailable(new TableModelEvent(tableModel));
} }
// Call on EDT
public void addMBeanNotificationInfo(MBeanNotificationInfo mbni) { public void addMBeanNotificationInfo(MBeanNotificationInfo mbni) {
emptyInfoTable(); emptyInfoTable();
emptyDescTable(); emptyDescTable();
...@@ -367,6 +373,7 @@ public class XMBeanInfo extends JPanel { ...@@ -367,6 +373,7 @@ public class XMBeanInfo extends JPanel {
tableModel.newDataAvailable(new TableModelEvent(tableModel)); tableModel.newDataAvailable(new TableModelEvent(tableModel));
} }
// Call on EDT
private void addMBeanConstructorInfo(MBeanConstructorInfo mbci, String text) { private void addMBeanConstructorInfo(MBeanConstructorInfo mbci, String text) {
DefaultTableModel tableModel = (DefaultTableModel) infoTable.getModel(); DefaultTableModel tableModel = (DefaultTableModel) infoTable.getModel();
Object rowData[] = new Object[2]; Object rowData[] = new Object[2];
...@@ -383,6 +390,7 @@ public class XMBeanInfo extends JPanel { ...@@ -383,6 +390,7 @@ public class XMBeanInfo extends JPanel {
tableModel.newDataAvailable(new TableModelEvent(tableModel)); tableModel.newDataAvailable(new TableModelEvent(tableModel));
} }
// Call on EDT
private void addMBeanParameterInfo(MBeanParameterInfo mbpi, String text) { private void addMBeanParameterInfo(MBeanParameterInfo mbpi, String text) {
DefaultTableModel tableModel = (DefaultTableModel) infoTable.getModel(); DefaultTableModel tableModel = (DefaultTableModel) infoTable.getModel();
Object rowData[] = new Object[2]; Object rowData[] = new Object[2];
...@@ -401,91 +409,4 @@ public class XMBeanInfo extends JPanel { ...@@ -401,91 +409,4 @@ public class XMBeanInfo extends JPanel {
addDescriptor(mbpi.getDescriptor(), text); addDescriptor(mbpi.getDescriptor(), text);
tableModel.newDataAvailable(new TableModelEvent(tableModel)); tableModel.newDataAvailable(new TableModelEvent(tableModel));
} }
public static void loadInfo(DefaultMutableTreeNode root) {
// Retrieve XMBean from XNodeInfo
//
XMBean mbean = (XMBean) ((XNodeInfo) root.getUserObject()).getData();
// Initialize MBean*Info
//
final MBeanInfo mbeanInfo;
try {
mbeanInfo = mbean.getMBeanInfo();
} catch (Exception e) {
if (JConsole.isDebug()) {
e.printStackTrace();
}
return;
}
MBeanAttributeInfo[] ai = mbeanInfo.getAttributes();
MBeanOperationInfo[] oi = mbeanInfo.getOperations();
MBeanNotificationInfo[] ni = mbeanInfo.getNotifications();
// MBeanAttributeInfo node
//
if (ai != null && ai.length > 0) {
DefaultMutableTreeNode attributes = new DefaultMutableTreeNode();
XNodeInfo attributesUO = new XNodeInfo(Type.ATTRIBUTES, mbean,
Resources.getText("Attributes"), null);
attributes.setUserObject(attributesUO);
root.add(attributes);
for (MBeanAttributeInfo mbai : ai) {
DefaultMutableTreeNode attribute = new DefaultMutableTreeNode();
XNodeInfo attributeUO = new XNodeInfo(Type.ATTRIBUTE,
new Object[] {mbean, mbai}, mbai.getName(), null);
attribute.setUserObject(attributeUO);
attributes.add(attribute);
}
}
// MBeanOperationInfo node
//
if (oi != null && oi.length > 0) {
DefaultMutableTreeNode operations = new DefaultMutableTreeNode();
XNodeInfo operationsUO = new XNodeInfo(Type.OPERATIONS, mbean,
Resources.getText("Operations"), null);
operations.setUserObject(operationsUO);
root.add(operations);
for (MBeanOperationInfo mboi : oi) {
// Compute the operation's tool tip text:
// "operationname(param1type,param2type,...)"
//
StringBuilder sb = new StringBuilder();
for (MBeanParameterInfo mbpi : mboi.getSignature()) {
sb.append(mbpi.getType() + ",");
}
String signature = sb.toString();
if (signature.length() > 0) {
// Remove the trailing ','
//
signature = signature.substring(0, signature.length() - 1);
}
String toolTipText = mboi.getName() + "(" + signature + ")";
// Create operation node
//
DefaultMutableTreeNode operation = new DefaultMutableTreeNode();
XNodeInfo operationUO = new XNodeInfo(Type.OPERATION,
new Object[] {mbean, mboi}, mboi.getName(), toolTipText);
operation.setUserObject(operationUO);
operations.add(operation);
}
}
// MBeanNotificationInfo node
//
if (mbean.isBroadcaster()) {
DefaultMutableTreeNode notifications = new DefaultMutableTreeNode();
XNodeInfo notificationsUO = new XNodeInfo(Type.NOTIFICATIONS, mbean,
Resources.getText("Notifications"), null);
notifications.setUserObject(notificationsUO);
root.add(notifications);
if (ni != null && ni.length > 0) {
for (MBeanNotificationInfo mbni : ni) {
DefaultMutableTreeNode notification =
new DefaultMutableTreeNode();
XNodeInfo notificationUO = new XNodeInfo(Type.NOTIFICATION,
mbni, mbni.getName(), null);
notification.setUserObject(notificationUO);
notifications.add(notification);
}
}
}
}
} }
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
* CA 95054 USA or visit www.sun.com if you need additional information or * CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions. * have any questions.
*/ */
package sun.tools.jconsole.inspector; package sun.tools.jconsole.inspector;
import javax.management.*; import javax.management.*;
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
* CA 95054 USA or visit www.sun.com if you need additional information or * CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions. * have any questions.
*/ */
package sun.tools.jconsole.inspector; package sun.tools.jconsole.inspector;
// java import // java import
......
...@@ -33,10 +33,7 @@ import java.awt.BorderLayout; ...@@ -33,10 +33,7 @@ import java.awt.BorderLayout;
import java.awt.GridLayout; import java.awt.GridLayout;
import java.awt.FlowLayout; import java.awt.FlowLayout;
import java.awt.Component; import java.awt.Component;
import java.awt.EventQueue;
import java.awt.event.*; import java.awt.event.*;
import java.awt.Insets;
import java.awt.Dimension;
import java.util.*; import java.util.*;
import java.io.*; import java.io.*;
...@@ -51,14 +48,13 @@ public abstract class XOperations extends JPanel implements ActionListener { ...@@ -51,14 +48,13 @@ public abstract class XOperations extends JPanel implements ActionListener {
public final static String OPERATION_INVOCATION_EVENT = public final static String OPERATION_INVOCATION_EVENT =
"jam.xoperations.invoke.result"; "jam.xoperations.invoke.result";
private java.util.List<NotificationListener> notificationListenersList; private java.util.List<NotificationListener> notificationListenersList;
private Hashtable<JButton, OperationEntry> operationEntryTable; private Hashtable<JButton, OperationEntry> operationEntryTable;
private XMBean mbean; private XMBean mbean;
private MBeanInfo mbeanInfo; private MBeanInfo mbeanInfo;
private MBeansTab mbeansTab; private MBeansTab mbeansTab;
public XOperations(MBeansTab mbeansTab) { public XOperations(MBeansTab mbeansTab) {
super(new GridLayout(1,1)); super(new GridLayout(1, 1));
this.mbeansTab = mbeansTab; this.mbeansTab = mbeansTab;
operationEntryTable = new Hashtable<JButton, OperationEntry>(); operationEntryTable = new Hashtable<JButton, OperationEntry>();
ArrayList<NotificationListener> l = ArrayList<NotificationListener> l =
...@@ -67,11 +63,13 @@ public abstract class XOperations extends JPanel implements ActionListener { ...@@ -67,11 +63,13 @@ public abstract class XOperations extends JPanel implements ActionListener {
Collections.synchronizedList(l); Collections.synchronizedList(l);
} }
// Call on EDT
public void removeOperations() { public void removeOperations() {
removeAll(); removeAll();
} }
public void loadOperations(XMBean mbean,MBeanInfo mbeanInfo) { // Call on EDT
public void loadOperations(XMBean mbean, MBeanInfo mbeanInfo) {
this.mbean = mbean; this.mbean = mbean;
this.mbeanInfo = mbeanInfo; this.mbeanInfo = mbeanInfo;
// add operations information // add operations information
...@@ -80,42 +78,56 @@ public abstract class XOperations extends JPanel implements ActionListener { ...@@ -80,42 +78,56 @@ public abstract class XOperations extends JPanel implements ActionListener {
// remove listeners, if any // remove listeners, if any
Component listeners[] = getComponents(); Component listeners[] = getComponents();
for (int i = 0; i < listeners.length; i++) for (int i = 0; i < listeners.length; i++) {
if (listeners[i] instanceof JButton) if (listeners[i] instanceof JButton) {
((JButton)listeners[i]).removeActionListener(this); ((JButton) listeners[i]).removeActionListener(this);
}
}
removeAll(); removeAll();
setLayout(new BorderLayout()); setLayout(new BorderLayout());
JButton methodButton; JButton methodButton;
JLabel methodLabel; JLabel methodLabel;
JPanel innerPanelLeft,innerPanelRight; JPanel innerPanelLeft, innerPanelRight;
JPanel outerPanelLeft,outerPanelRight; JPanel outerPanelLeft, outerPanelRight;
outerPanelLeft = new JPanel(new GridLayout(operations.length,1)); outerPanelLeft = new JPanel(new GridLayout(operations.length, 1));
outerPanelRight = new JPanel(new GridLayout(operations.length,1)); outerPanelRight = new JPanel(new GridLayout(operations.length, 1));
for (int i=0;i<operations.length;i++) { for (int i = 0; i < operations.length; i++) {
innerPanelLeft = new JPanel(new FlowLayout(FlowLayout.RIGHT)); innerPanelLeft = new JPanel(new FlowLayout(FlowLayout.RIGHT));
innerPanelRight = new JPanel(new FlowLayout(FlowLayout.LEFT)); innerPanelRight = new JPanel(new FlowLayout(FlowLayout.LEFT));
innerPanelLeft.add(methodLabel = String returnType = operations[i].getReturnType();
new JLabel(Utils. if (returnType == null) {
getReadableClassName(operations[i]. methodLabel = new JLabel("null", JLabel.RIGHT);
getReturnType()), if (JConsole.isDebug()) {
JLabel.RIGHT)); System.err.println(
if (methodLabel.getText().length()>20) { "WARNING: The operation's return type " +
"shouldn't be \"null\". Check how the " +
"MBeanOperationInfo for the \"" +
operations[i].getName() + "\" operation has " +
"been defined in the MBean's implementation code.");
}
} else {
methodLabel = new JLabel(
Utils.getReadableClassName(returnType), JLabel.RIGHT);
}
innerPanelLeft.add(methodLabel);
if (methodLabel.getText().length() > 20) {
methodLabel.setText(methodLabel.getText(). methodLabel.setText(methodLabel.getText().
substring(methodLabel.getText(). substring(methodLabel.getText().
lastIndexOf(".")+1, lastIndexOf(".") + 1,
methodLabel.getText().length())); methodLabel.getText().length()));
} }
methodButton = new JButton(operations[i].getName()); methodButton = new JButton(operations[i].getName());
methodButton.setToolTipText(operations[i].getDescription()); methodButton.setToolTipText(operations[i].getDescription());
boolean callable = isCallable(operations[i].getSignature()); boolean callable = isCallable(operations[i].getSignature());
if(callable) if (callable) {
methodButton.addActionListener(this); methodButton.addActionListener(this);
else } else {
methodButton.setEnabled(false); methodButton.setEnabled(false);
}
MBeanParameterInfo[] signature = operations[i].getSignature(); MBeanParameterInfo[] signature = operations[i].getSignature();
OperationEntry paramEntry = new OperationEntry(operations[i], OperationEntry paramEntry = new OperationEntry(operations[i],
...@@ -124,69 +136,73 @@ public abstract class XOperations extends JPanel implements ActionListener { ...@@ -124,69 +136,73 @@ public abstract class XOperations extends JPanel implements ActionListener {
this); this);
operationEntryTable.put(methodButton, paramEntry); operationEntryTable.put(methodButton, paramEntry);
innerPanelRight.add(methodButton); innerPanelRight.add(methodButton);
if(signature.length==0) if (signature.length == 0) {
innerPanelRight.add(new JLabel("( )",JLabel.CENTER)); innerPanelRight.add(new JLabel("( )", JLabel.CENTER));
else } else {
innerPanelRight.add(paramEntry); innerPanelRight.add(paramEntry);
}
outerPanelLeft.add(innerPanelLeft,BorderLayout.WEST); outerPanelLeft.add(innerPanelLeft, BorderLayout.WEST);
outerPanelRight.add(innerPanelRight,BorderLayout.CENTER); outerPanelRight.add(innerPanelRight, BorderLayout.CENTER);
} }
add(outerPanelLeft,BorderLayout.WEST); add(outerPanelLeft, BorderLayout.WEST);
add(outerPanelRight,BorderLayout.CENTER); add(outerPanelRight, BorderLayout.CENTER);
validate(); validate();
} }
private boolean isCallable(MBeanParameterInfo[] signature) { private boolean isCallable(MBeanParameterInfo[] signature) {
for(int i = 0; i < signature.length; i++) { for (int i = 0; i < signature.length; i++) {
if(!Utils.isEditableType(signature[i].getType())) if (!Utils.isEditableType(signature[i].getType())) {
return false; return false;
} }
}
return true; return true;
} }
// Call on EDT
public void actionPerformed(final ActionEvent e) { public void actionPerformed(final ActionEvent e) {
performInvokeRequest((JButton)e.getSource()); performInvokeRequest((JButton) e.getSource());
} }
void performInvokeRequest(final JButton button) { void performInvokeRequest(final JButton button) {
mbeansTab.workerAdd(new Runnable() { final OperationEntry entryIf = operationEntryTable.get(button);
public void run() { new SwingWorker<Object, Void>() {
@Override
public Object doInBackground() throws Exception {
return mbean.invoke(button.getText(),
entryIf.getParameters(), entryIf.getSignature());
}
@Override
protected void done() {
try { try {
OperationEntry entryIf = operationEntryTable.get(button); Object result = get();
Object result = null;
result = mbean.invoke(button.getText(),
entryIf.getParameters(),
entryIf.getSignature());
// sends result notification to upper level if // sends result notification to upper level if
// there is a return value // there is a return value
if (entryIf.getReturnType() != null && if (entryIf.getReturnType() != null &&
!entryIf.getReturnType().equals(Void.TYPE.getName()) && !entryIf.getReturnType().equals(Void.TYPE.getName()) &&
!entryIf.getReturnType().equals(Void.class.getName())) !entryIf.getReturnType().equals(Void.class.getName())) {
fireChangedNotification(OPERATION_INVOCATION_EVENT, fireChangedNotification(OPERATION_INVOCATION_EVENT, button, result);
button, } else {
result); new ThreadDialog(
else
EventQueue.invokeLater(new ThreadDialog(
button, button,
Resources.getText("Method successfully invoked"), Resources.getText("Method successfully invoked"),
Resources.getText("Info"), Resources.getText("Info"),
JOptionPane.INFORMATION_MESSAGE)); JOptionPane.INFORMATION_MESSAGE).run();
} catch (Throwable ex) { }
} catch (Throwable t) {
t = Utils.getActualException(t);
if (JConsole.isDebug()) { if (JConsole.isDebug()) {
ex.printStackTrace(); t.printStackTrace();
} }
ex = Utils.getActualException(ex); new ThreadDialog(
String message = ex.toString();
EventQueue.invokeLater(new ThreadDialog(
button, button,
Resources.getText("Problem invoking") + " " + Resources.getText("Problem invoking") + " " +
button.getText() + " : " + message, button.getText() + " : " + t.toString(),
Resources.getText("Error"), Resources.getText("Error"),
JOptionPane.ERROR_MESSAGE)); JOptionPane.ERROR_MESSAGE).run();
} }
} }
}); }.execute();
} }
public void addOperationsListener(NotificationListener nl) { public void addOperationsListener(NotificationListener nl) {
...@@ -197,14 +213,14 @@ public abstract class XOperations extends JPanel implements ActionListener { ...@@ -197,14 +213,14 @@ public abstract class XOperations extends JPanel implements ActionListener {
notificationListenersList.remove(nl); notificationListenersList.remove(nl);
} }
private void fireChangedNotification(String type, // Call on EDT
Object source, private void fireChangedNotification(
Object handback) { String type, Object source, Object handback) {
Notification e = new Notification(type,source,0); Notification n = new Notification(type, source, 0);
for(NotificationListener nl : notificationListenersList) for (NotificationListener nl : notificationListenersList) {
nl.handleNotification(e,handback); nl.handleNotification(n, handback);
}
} }
protected abstract MBeanOperationInfo[] protected abstract MBeanOperationInfo[] updateOperations(MBeanOperationInfo[] operations);
updateOperations(MBeanOperationInfo[] operations);
} }
...@@ -22,7 +22,9 @@ ...@@ -22,7 +22,9 @@
* CA 95054 USA or visit www.sun.com if you need additional information or * CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions. * have any questions.
*/ */
package sun.tools.jconsole.inspector; package sun.tools.jconsole.inspector;
import sun.tools.jconsole.Plotter; import sun.tools.jconsole.Plotter;
import javax.swing.JTable; import javax.swing.JTable;
import java.awt.Graphics; import java.awt.Graphics;
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
* CA 95054 USA or visit www.sun.com if you need additional information or * CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions. * have any questions.
*/ */
package sun.tools.jconsole.inspector; package sun.tools.jconsole.inspector;
import java.awt.*; import java.awt.*;
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
* CA 95054 USA or visit www.sun.com if you need additional information or * CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions. * have any questions.
*/ */
package sun.tools.jconsole.inspector; package sun.tools.jconsole.inspector;
import javax.swing.*; import javax.swing.*;
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
* CA 95054 USA or visit www.sun.com if you need additional information or * CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions. * have any questions.
*/ */
package sun.tools.jconsole.inspector; package sun.tools.jconsole.inspector;
import java.awt.*; import java.awt.*;
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
* CA 95054 USA or visit www.sun.com if you need additional information or * CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions. * have any questions.
*/ */
package sun.tools.jconsole.inspector; package sun.tools.jconsole.inspector;
import java.awt.Component; import java.awt.Component;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册