6711106: REGRESSION: Bad usage of SnapshotMBeanServerConnection in MBeans tab and JConsole plugins

Reviewed-by: jfdenise
This commit is contained in:
Luis Miguel Alventosa 2008-06-10 13:50:06 +02:00
parent e44b665297
commit 0c259336ec
4 changed files with 35 additions and 16 deletions

View File

@ -37,6 +37,7 @@ import javax.management.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.tree.*;
import sun.tools.jconsole.ProxyClient.SnapshotMBeanServerConnection;
import sun.tools.jconsole.inspector.*;
import com.sun.tools.jconsole.JConsoleContext;
@ -154,6 +155,10 @@ public class MBeansTab extends Tab implements
return vmPanel.getProxyClient().getMBeanServerConnection();
}
public SnapshotMBeanServerConnection getSnapshotMBeanServerConnection() {
return vmPanel.getProxyClient().getSnapshotMBeanServerConnection();
}
@Override
public void update() {
// Ping the connection to see if it is still alive. At

View File

@ -28,7 +28,6 @@ package sun.tools.jconsole;
import com.sun.management.HotSpotDiagnosticMXBean;
import com.sun.tools.jconsole.JConsoleContext;
import com.sun.tools.jconsole.JConsoleContext.ConnectionState;
import java.awt.Component;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeEvent;
import java.io.IOException;
@ -78,6 +77,7 @@ public class ProxyClient implements JConsoleContext {
private String advancedUrl = null;
private JMXServiceURL jmxUrl = null;
private MBeanServerConnection mbsc = null;
private SnapshotMBeanServerConnection server = null;
private JMXConnector jmxc = null;
private RMIServer stub = null;
@ -103,7 +103,6 @@ public class ProxyClient implements JConsoleContext {
private List<MemoryPoolProxy> memoryPoolProxies = null;
private List<GarbageCollectorMXBean> garbageCollectorMBeans = null;
private String detectDeadlocksOperation = null;
final static private String HOTSPOT_DIAGNOSTIC_MXBEAN_NAME =
"com.sun.management:type=HotSpotDiagnostic";
@ -326,8 +325,8 @@ public class ProxyClient implements JConsoleContext {
if (jmxUrl == null && "localhost".equals(hostName) && port == 0) {
// Monitor self
this.jmxc = null;
this.server = Snapshot.newSnapshot(
ManagementFactory.getPlatformMBeanServer());
this.mbsc = ManagementFactory.getPlatformMBeanServer();
this.server = Snapshot.newSnapshot(mbsc);
} else {
// Monitor another process
if (lvm != null) {
@ -369,7 +368,8 @@ public class ProxyClient implements JConsoleContext {
this.jmxc = JMXConnectorFactory.connect(jmxUrl, env);
}
}
this.server = Snapshot.newSnapshot(jmxc.getMBeanServerConnection());
this.mbsc = jmxc.getMBeanServerConnection();
this.server = Snapshot.newSnapshot(mbsc);
}
this.isDead = false;
@ -518,7 +518,11 @@ public class ProxyClient implements JConsoleContext {
}
}
public MBeanServerConnection getMBeanServerConnection() {
public MBeanServerConnection getMBeanServerConnection() {
return mbsc;
}
public SnapshotMBeanServerConnection getSnapshotMBeanServerConnection() {
return server;
}

View File

@ -30,6 +30,7 @@ import javax.management.*;
import javax.swing.Icon;
import sun.tools.jconsole.JConsole;
import sun.tools.jconsole.MBeansTab;
import sun.tools.jconsole.ProxyClient.SnapshotMBeanServerConnection;
public class XMBean {
@ -60,6 +61,10 @@ public class XMBean {
return mbeansTab.getMBeanServerConnection();
}
SnapshotMBeanServerConnection getSnapshotMBeanServerConnection() {
return mbeansTab.getSnapshotMBeanServerConnection();
}
public Boolean isBroadcaster() {
synchronized (broadcasterLock) {
if (broadcaster == null) {
@ -103,14 +108,14 @@ public class XMBean {
public Object getAttribute(String attributeName)
throws AttributeNotFoundException, InstanceNotFoundException,
MBeanException, ReflectionException, IOException {
return getMBeanServerConnection().getAttribute(
return getSnapshotMBeanServerConnection().getAttribute(
getObjectName(), attributeName);
}
public AttributeList getAttributes(String attributeNames[])
throws AttributeNotFoundException, InstanceNotFoundException,
MBeanException, ReflectionException, IOException {
return getMBeanServerConnection().getAttributes(
return getSnapshotMBeanServerConnection().getAttributes(
getObjectName(), attributeNames);
}

View File

@ -349,7 +349,14 @@ public class XMBeanAttributes extends XTable {
try {
list = mbean.getAttributes(attributesInfo);
}catch(Exception e) {
} catch (Exception e) {
if (JConsole.isDebug()) {
System.err.println("Error calling getAttributes() on MBean \"" +
mbean.getObjectName() + "\". JConsole will " +
"try to get them individually calling " +
"getAttribute() instead. Exception:");
e.printStackTrace(System.err);
}
list = new AttributeList();
//Can't load all attributes, do it one after each other.
for(int i = 0; i < attributesInfo.length; i++) {
@ -357,7 +364,7 @@ public class XMBeanAttributes extends XTable {
try {
name = attributesInfo[i].getName();
Object value =
mbean.getAttribute(name);
mbean.getMBeanServerConnection().getAttribute(mbean.getObjectName(), name);
list.add(new Attribute(name, value));
}catch(Exception ex) {
if(attributesInfo[i].isReadable()) {
@ -397,8 +404,8 @@ public class XMBeanAttributes extends XTable {
// went wrong.
try {
Object v =
mbean.getAttribute(attributeInfo.
getName());
mbean.getMBeanServerConnection().getAttribute(
mbean.getObjectName(), attributeInfo.getName());
//What happens if now it is ok?
// Be pragmatic, add it to readable...
attributes.put(attributeInfo.getName(),
@ -528,10 +535,8 @@ public class XMBeanAttributes extends XTable {
}
public void refreshAttributes() {
MBeanServerConnection mbsc = mbeansTab.getMBeanServerConnection();
if (mbsc instanceof SnapshotMBeanServerConnection) {
((SnapshotMBeanServerConnection) mbsc).flush();
}
SnapshotMBeanServerConnection mbsc = mbeansTab.getSnapshotMBeanServerConnection();
mbsc.flush();
stopCellEditing();
loadAttributes(mbean, mbeanInfo);
}