changeset 338:7e5e83dfd285

6711106: REGRESSION: Bad usage of SnapshotMBeanServerConnection in MBeans tab and JConsole plugins. Reviewed-by: jfdenise
author lmalvent
date Tue, 10 Jun 2008 13:50:06 +0200
parents 513d733e571d
children e49bf258e60c b6c42daa86d5
files src/share/classes/sun/tools/jconsole/MBeansTab.java src/share/classes/sun/tools/jconsole/ProxyClient.java src/share/classes/sun/tools/jconsole/inspector/XMBean.java src/share/classes/sun/tools/jconsole/inspector/XMBeanAttributes.java
diffstat 4 files changed, 35 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/sun/tools/jconsole/MBeansTab.java	Sat Jun 07 16:11:57 2008 +0100
+++ b/src/share/classes/sun/tools/jconsole/MBeansTab.java	Tue Jun 10 13:50:06 2008 +0200
@@ -37,6 +37,7 @@
 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 @@
         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
--- a/src/share/classes/sun/tools/jconsole/ProxyClient.java	Sat Jun 07 16:11:57 2008 +0100
+++ b/src/share/classes/sun/tools/jconsole/ProxyClient.java	Tue Jun 10 13:50:06 2008 +0200
@@ -28,7 +28,6 @@
 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 @@
     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 @@
 
     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 @@
         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 @@
                     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 MBeanServerConnection getMBeanServerConnection() {
+   public MBeanServerConnection getMBeanServerConnection() {
+       return mbsc;
+   }
+
+    public SnapshotMBeanServerConnection getSnapshotMBeanServerConnection() {
         return server;
     }
 
--- a/src/share/classes/sun/tools/jconsole/inspector/XMBean.java	Sat Jun 07 16:11:57 2008 +0100
+++ b/src/share/classes/sun/tools/jconsole/inspector/XMBean.java	Tue Jun 10 13:50:06 2008 +0200
@@ -30,6 +30,7 @@
 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 @@
         return mbeansTab.getMBeanServerConnection();
     }
 
+    SnapshotMBeanServerConnection getSnapshotMBeanServerConnection() {
+        return mbeansTab.getSnapshotMBeanServerConnection();
+    }
+
     public Boolean isBroadcaster() {
         synchronized (broadcasterLock) {
             if (broadcaster == null) {
@@ -103,14 +108,14 @@
     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);
     }
 
--- a/src/share/classes/sun/tools/jconsole/inspector/XMBeanAttributes.java	Sat Jun 07 16:11:57 2008 +0100
+++ b/src/share/classes/sun/tools/jconsole/inspector/XMBeanAttributes.java	Tue Jun 10 13:50:06 2008 +0200
@@ -349,7 +349,14 @@
 
         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 @@
                 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 @@
                             // 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 void refreshAttributes() {
-         MBeanServerConnection mbsc = mbeansTab.getMBeanServerConnection();
-         if (mbsc instanceof SnapshotMBeanServerConnection) {
-             ((SnapshotMBeanServerConnection) mbsc).flush();
-         }
+         SnapshotMBeanServerConnection mbsc = mbeansTab.getSnapshotMBeanServerConnection();
+         mbsc.flush();
          stopCellEditing();
          loadAttributes(mbean, mbeanInfo);
      }