Thread: [Mc4j-cvs] mc4j/src/org/mc4j/console/connection ConnectionNode.java,1.28,1.29
Brought to you by:
ghinkl
From: Greg H. <gh...@us...> - 2004-05-26 02:51:32
|
Update of /cvsroot/mc4j/mc4j/src/org/mc4j/console/connection In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20039/src/org/mc4j/console/connection Modified Files: ConnectionNode.java Log Message: Fix for bugs #939971, #914838, #957714, #933080 Based on patches submitted by holbitlan. Now removes mbeans from the tree when they are unregistered from the server. This is based on the 10 second, delayed refresh thread. (Not removing beans from dashboard attribute table components on unregister yet as this can cause problems depending on the dashboard match section) Index: ConnectionNode.java =================================================================== RCS file: /cvsroot/mc4j/mc4j/src/org/mc4j/console/connection/ConnectionNode.java,v retrieving revision 1.28 retrieving revision 1.29 diff -C2 -d -r1.28 -r1.29 *** ConnectionNode.java 21 Apr 2004 20:38:38 -0000 1.28 --- ConnectionNode.java 26 May 2004 02:51:22 -0000 1.29 *************** *** 20,45 **** package org.mc4j.console.connection; - import java.beans.IntrospectionException; - import java.beans.PropertyChangeEvent; - import java.beans.PropertyChangeListener; - import java.io.IOException; - import java.util.ArrayList; - import java.util.Collections; - import java.util.HashMap; - import java.util.HashSet; - import java.util.Iterator; - import java.util.List; - import java.util.Map; - import java.util.Set; - import java.util.SortedSet; - import java.util.Timer; - import java.util.TimerTask; - import java.util.TreeSet; - - import javax.management.MBeanServer; - import javax.management.ObjectInstance; - import javax.management.ObjectName; - import javax.swing.SwingUtilities; - import org.openide.ErrorManager; import org.openide.actions.OpenLocalExplorerAction; --- 20,23 ---- *************** *** 67,71 **** import org.mc4j.console.query.NewQueryAction; ! import EDU.oswego.cs.dl.util.concurrent.PooledExecutor; /** --- 45,69 ---- import org.mc4j.console.query.NewQueryAction; ! import java.beans.IntrospectionException; ! import java.beans.PropertyChangeEvent; ! import java.beans.PropertyChangeListener; ! import java.io.IOException; ! import java.util.ArrayList; ! import java.util.Collections; ! import java.util.HashMap; ! import java.util.HashSet; ! import java.util.Iterator; ! import java.util.List; ! import java.util.Map; ! import java.util.Set; ! import java.util.SortedSet; ! import java.util.Timer; ! import java.util.TimerTask; ! import java.util.TreeSet; ! ! import javax.management.MBeanServer; ! import javax.management.ObjectInstance; ! import javax.management.ObjectName; ! import javax.swing.SwingUtilities; /** *************** *** 87,91 **** /** Holds a map of ObjectNames.getCannonicalName() to MBeanNodes */ ! protected Map mbeans = new HashMap(); protected Node.PropertySet[] settingsPropertySets; --- 85,89 ---- /** Holds a map of ObjectNames.getCannonicalName() to MBeanNodes */ ! protected volatile Map mbeans = new HashMap(); protected Node.PropertySet[] settingsPropertySets; *************** *** 93,97 **** private Timer refreshTimer; ! private PooledExecutor remoteExecutor; private Set openDashboards = new HashSet(); --- 91,95 ---- private Timer refreshTimer; ! //private PooledExecutor remoteExecutor; private Set openDashboards = new HashSet(); *************** *** 101,106 **** // Setup a working pool of up to 5 threads to process remote calls ! remoteExecutor = new PooledExecutor(5); ! remoteExecutor.waitWhenBlocked(); // Set self on domain nodes so they can alert us when someone expands us --- 99,104 ---- // Setup a working pool of up to 5 threads to process remote calls ! //remoteExecutor = new PooledExecutor(5); ! //remoteExecutor.waitWhenBlocked(); // Set self on domain nodes so they can alert us when someone expands us *************** *** 114,124 **** } ! /** ! * Provides access to the remote executor used to make calls to the remote server... ! * @return The pooled executor for this connection ! */ ! public PooledExecutor getExecutor() { ! return this.remoteExecutor; ! } public void propertyChange(PropertyChangeEvent evt) { --- 112,122 ---- } ! // /** ! // * Provides access to the remote executor used to make calls to the remote server... ! // * @return The pooled executor for this connection ! // */ ! // public PooledExecutor getExecutor() { ! // return this.remoteExecutor; ! // } public void propertyChange(PropertyChangeEvent evt) { *************** *** 199,210 **** } ! Iterator iter = sortedObjectNames.iterator(); int i = 0; ! while (iter.hasNext()) { ObjectName objectName = (ObjectName) iter.next(); ! if ((this.mbeans == null) || (!this.mbeans.containsKey(objectName.getCanonicalName()))) { ! //org.openide.windows.IOProvider.getDefault().getStdOut().println("Mount MBean: " + objectInstance.getObjectName().getCanonicalName()); ! addMBean(objectName); } --- 197,216 ---- } ! // Create a secondary set that will be winowed with beans ! // that are still registered. Beans left in this set at the end ! // have been deregistered. ! HashSet oldMBeans = new HashSet(mbeans.keySet()); ! int i = 0; ! for (Iterator iter = sortedObjectNames.iterator(); iter.hasNext();) { ObjectName objectName = (ObjectName) iter.next(); ! synchronized(this) { ! if ((this.mbeans == null) || (!this.mbeans.containsKey(objectName.getCanonicalName()))) { ! //org.openide.windows.IOProvider.getDefault().getStdOut().println("Mount MBean: " + objectInstance.getObjectName().getCanonicalName()); ! addMBean(objectName); ! } else { ! oldMBeans.remove(objectName.getCanonicalName()); ! } } *************** *** 214,226 **** + "] " + i + " of " + objectNames.size()); } - // Don't refresh here, this.refresh already starts the chain of refreshes - /* else { - // refresh the existing one - //MBeanNode node = (MBeanNode) this.mbeans.get(objectInstance.getObjectName().getCanonicalName()); - //node.refresh(); - } - */ } } catch (Exception e) { StatusDisplayer.getDefault().setStatusText("Problem contacting server: " + --- 220,236 ---- + "] " + i + " of " + objectNames.size()); } } + // Clean out beans that have been unregistered + for (Iterator it = oldMBeans.iterator(); it.hasNext();) { + String mbeansKey = (String) it.next(); + + MBeanNode node = (MBeanNode) this.mbeans.get(mbeansKey); + node.getParentNode().getChildren().remove(new Node[] { node }); + + mbeans.remove(mbeansKey); + + } + } catch (Exception e) { StatusDisplayer.getDefault().setStatusText("Problem contacting server: " + *************** *** 238,259 **** */ protected void addMBean(ObjectInstance objectInstance) { ! this.addMBean(objectInstance.getObjectName()); } protected void addMBean(ObjectName objectName) { ! String domain = objectName.getDomain(); ! ! DomainNode domainNode = (DomainNode) this.getChildren().findChild(domain); ! if (domainNode == null) { ! domainNode = new DomainNode(domain); ! this.getChildren().add(new Node[] { domainNode }); ! } ! MBeanNode mbeanNode = new MBeanNode(objectName, this); ! this.mbeans.put(objectName.getCanonicalName(), mbeanNode); ! domainNode.getChildren().add( ! new Node[] { mbeanNode }); } --- 248,272 ---- */ protected void addMBean(ObjectInstance objectInstance) { ! synchronized(this) { ! this.addMBean(objectInstance.getObjectName()); ! } } protected void addMBean(ObjectName objectName) { + synchronized(this) { + String domain = objectName.getDomain(); ! DomainNode domainNode = (DomainNode) this.getChildren().findChild(domain); ! if (domainNode == null) { ! domainNode = new DomainNode(domain); ! this.getChildren().add(new Node[] { domainNode }); ! } ! MBeanNode mbeanNode = new MBeanNode(objectName, this); ! this.mbeans.put(objectName.getCanonicalName(), mbeanNode); ! domainNode.getChildren().add( ! new Node[] { mbeanNode }); ! } } *************** *** 419,423 **** // Kill any outstanding requests ! this.remoteExecutor.shutdownNow(); setIconBase("org/mc4j/console/connection/DisconnectedConnectionNodeIcon"); --- 432,436 ---- // Kill any outstanding requests ! //this.remoteExecutor.shutdownNow(); setIconBase("org/mc4j/console/connection/DisconnectedConnectionNodeIcon"); *************** *** 488,494 **** public void browseToMBean(final ObjectName objectName) { ! final String name = objectName.getCanonicalName(); ! ! final MBeanNode node = (MBeanNode) this.mbeans.get(name); if (node != null) { ExplorerUtil.browseTo(node); --- 501,505 ---- public void browseToMBean(final ObjectName objectName) { ! final MBeanNode node = getMBeanNode(objectName); if (node != null) { ExplorerUtil.browseTo(node); |