/// <summary>
 /// Remove a node
 /// Update node counter and rack counter if necessary
 /// </summary>
 /// <param name="node">node to be removed; can be null</param>
 public virtual void Remove(Node node)
 {
     if (node == null)
     {
         return;
     }
     if (node is NetworkTopology.InnerNode)
     {
         throw new ArgumentException("Not allow to remove an inner node: " + NodeBase.GetPath
                                         (node));
     }
     Log.Info("Removing a node: " + NodeBase.GetPath(node));
     netlock.WriteLock().Lock();
     try
     {
         if (clusterMap.Remove(node))
         {
             NetworkTopology.InnerNode rack = (NetworkTopology.InnerNode)GetNode(node.GetNetworkLocation
                                                                                     ());
             if (rack == null)
             {
                 numOfRacks--;
             }
         }
         if (Log.IsDebugEnabled())
         {
             Log.Debug("NetworkTopology became:\n" + this.ToString());
         }
     }
     finally
     {
         netlock.WriteLock().Unlock();
     }
 }
            /// <summary>Remove node <i>n</i> from the subtree of this node</summary>
            /// <param name="n">node to be deleted</param>
            /// <returns>true if the node is deleted; false otherwise</returns>
            internal virtual bool Remove(Node n)
            {
                string parent      = n.GetNetworkLocation();
                string currentPath = GetPath(this);

                if (!IsAncestor(n))
                {
                    throw new ArgumentException(n.GetName() + ", which is located at " + parent + ", is not a descendent of "
                                                + currentPath);
                }
                if (IsParent(n))
                {
                    // this node is the parent of n; remove n directly
                    for (int i = 0; i < children.Count; i++)
                    {
                        if (children[i].GetName().Equals(n.GetName()))
                        {
                            children.Remove(i);
                            numOfLeaves--;
                            n.SetParent(null);
                            return(true);
                        }
                    }
                    return(false);
                }
                else
                {
                    // find the next ancestor node: the parent node
                    string parentName = GetNextAncestorName(n);
                    NetworkTopology.InnerNode parentNode = null;
                    int i;
                    for (i = 0; i < children.Count; i++)
                    {
                        if (children[i].GetName().Equals(parentName))
                        {
                            parentNode = (NetworkTopology.InnerNode)children[i];
                            break;
                        }
                    }
                    if (parentNode == null)
                    {
                        return(false);
                    }
                    // remove n from the parent node
                    bool isRemoved = parentNode.Remove(n);
                    // if the parent node has no children, remove the parent node too
                    if (isRemoved)
                    {
                        if (parentNode.GetNumOfChildren() == 0)
                        {
                            children.Remove(i);
                        }
                        numOfLeaves--;
                    }
                    return(isRemoved);
                }
            }