hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cutt...@apache.org
Subject svn commit: r529410 [20/27] - in /lucene/hadoop/trunk: ./ src/contrib/abacus/src/examples/org/apache/hadoop/abacus/examples/ src/contrib/abacus/src/java/org/apache/hadoop/abacus/ src/contrib/data_join/src/java/org/apache/hadoop/contrib/utils/join/ src/...
Date Mon, 16 Apr 2007 21:44:46 GMT
Modified: lucene/hadoop/trunk/src/java/org/apache/hadoop/metrics/spi/AbstractMetricsContext.java
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/java/org/apache/hadoop/metrics/spi/AbstractMetricsContext.java?view=diff&rev=529410&r1=529409&r2=529410
==============================================================================
--- lucene/hadoop/trunk/src/java/org/apache/hadoop/metrics/spi/AbstractMetricsContext.java (original)
+++ lucene/hadoop/trunk/src/java/org/apache/hadoop/metrics/spi/AbstractMetricsContext.java Mon Apr 16 14:44:35 2007
@@ -48,349 +48,349 @@
  */
 public abstract class AbstractMetricsContext implements MetricsContext {
     
-    private int period = MetricsContext.DEFAULT_PERIOD;
-    private Timer timer = null;
+  private int period = MetricsContext.DEFAULT_PERIOD;
+  private Timer timer = null;
     
-    private Set<Updater> updaters = new HashSet<Updater>(1);
-    private volatile boolean isMonitoring = false;
+  private Set<Updater> updaters = new HashSet<Updater>(1);
+  private volatile boolean isMonitoring = false;
     
-    private ContextFactory factory = null;
-    private String contextName = null;
+  private ContextFactory factory = null;
+  private String contextName = null;
     
-    static class TagMap extends TreeMap<String,Object> {
-        private static final long serialVersionUID = 3546309335061952993L;
-        TagMap() {
-            super();
-        }
-        TagMap(TagMap orig) {
-            super(orig);
-        }
-    }
-    static class MetricMap extends TreeMap<String,Number> {
-        private static final long serialVersionUID = -7495051861141631609L;
-    }
+  static class TagMap extends TreeMap<String,Object> {
+    private static final long serialVersionUID = 3546309335061952993L;
+    TagMap() {
+      super();
+    }
+    TagMap(TagMap orig) {
+      super(orig);
+    }
+  }
+  static class MetricMap extends TreeMap<String,Number> {
+    private static final long serialVersionUID = -7495051861141631609L;
+  }
             
-    static class RecordMap extends HashMap<TagMap,MetricMap> {
-        private static final long serialVersionUID = 259835619700264611L;
-    }
+  static class RecordMap extends HashMap<TagMap,MetricMap> {
+    private static final long serialVersionUID = 259835619700264611L;
+  }
     
-    private Map<String,RecordMap> bufferedData = new HashMap<String,RecordMap>();
+  private Map<String,RecordMap> bufferedData = new HashMap<String,RecordMap>();
     
 
-    /**
-     * Creates a new instance of AbstractMetricsContext
-     */
-    protected AbstractMetricsContext() {
-    }
-    
-    /**
-     * Initializes the context.
-     */
-    public void init(String contextName, ContextFactory factory) 
-    {
-        this.contextName = contextName;
-        this.factory = factory;
-    }
-    
-    /**
-     * Convenience method for subclasses to access factory attributes.
-     */
-    protected String getAttribute(String attributeName) {
-        String factoryAttribute = contextName + "." + attributeName;
-        return (String) factory.getAttribute(factoryAttribute);  
-    }
-    
-    /**
-     * Returns an attribute-value map derived from the factory attributes
-     * by finding all factory attributes that begin with 
-     * <i>contextName</i>.<i>tableName</i>.  The returned map consists of
-     * those attributes with the contextName and tableName stripped off.
-     */
-    protected Map<String,String> getAttributeTable(String tableName) {
-        String prefix = contextName + "." + tableName + ".";
-        Map<String,String> result = new HashMap<String,String>();
-        for (String attributeName : factory.getAttributeNames()) {
-            if (attributeName.startsWith(prefix)) {
-                String name = attributeName.substring(prefix.length());
-                String value = (String) factory.getAttribute(attributeName);
-                result.put(name, value);
-            }
-        }
-        return result;
-    }
-    
-    /**
-     * Returns the context name.
-     */
-    public String getContextName() {
-        return contextName;
-    }
-    
-    /**
-     * Returns the factory by which this context was created.
-     */
-    public ContextFactory getContextFactory() {
-        return factory;
-    }
-    
-    /**
-     * Starts or restarts monitoring, the emitting of metrics records.
-     */
-    public synchronized void startMonitoring()
+  /**
+   * Creates a new instance of AbstractMetricsContext
+   */
+  protected AbstractMetricsContext() {
+  }
+    
+  /**
+   * Initializes the context.
+   */
+  public void init(String contextName, ContextFactory factory) 
+  {
+    this.contextName = contextName;
+    this.factory = factory;
+  }
+    
+  /**
+   * Convenience method for subclasses to access factory attributes.
+   */
+  protected String getAttribute(String attributeName) {
+    String factoryAttribute = contextName + "." + attributeName;
+    return (String) factory.getAttribute(factoryAttribute);  
+  }
+    
+  /**
+   * Returns an attribute-value map derived from the factory attributes
+   * by finding all factory attributes that begin with 
+   * <i>contextName</i>.<i>tableName</i>.  The returned map consists of
+   * those attributes with the contextName and tableName stripped off.
+   */
+  protected Map<String,String> getAttributeTable(String tableName) {
+    String prefix = contextName + "." + tableName + ".";
+    Map<String,String> result = new HashMap<String,String>();
+    for (String attributeName : factory.getAttributeNames()) {
+      if (attributeName.startsWith(prefix)) {
+        String name = attributeName.substring(prefix.length());
+        String value = (String) factory.getAttribute(attributeName);
+        result.put(name, value);
+      }
+    }
+    return result;
+  }
+    
+  /**
+   * Returns the context name.
+   */
+  public String getContextName() {
+    return contextName;
+  }
+    
+  /**
+   * Returns the factory by which this context was created.
+   */
+  public ContextFactory getContextFactory() {
+    return factory;
+  }
+    
+  /**
+   * Starts or restarts monitoring, the emitting of metrics records.
+   */
+  public synchronized void startMonitoring()
     throws IOException {
-        if (!isMonitoring) {
-            startTimer();
-            isMonitoring = true;
+    if (!isMonitoring) {
+      startTimer();
+      isMonitoring = true;
+    }
+  }
+    
+  /**
+   * Stops monitoring.  This does not free buffered data. 
+   * @see #close()
+   */
+  public synchronized void stopMonitoring() {
+    if (isMonitoring) {
+      stopTimer();
+      isMonitoring = false;
+    }
+  }
+    
+  /**
+   * Returns true if monitoring is currently in progress.
+   */
+  public boolean isMonitoring() {
+    return isMonitoring;
+  }
+    
+  /**
+   * Stops monitoring and frees buffered data, returning this
+   * object to its initial state.  
+   */
+  public synchronized void close() {
+    stopMonitoring();
+    clearUpdaters();
+  } 
+    
+  /**
+   * Creates a new AbstractMetricsRecord instance with the given <code>recordName</code>.
+   * Throws an exception if the metrics implementation is configured with a fixed
+   * set of record names and <code>recordName</code> is not in that set.
+   * 
+   * @param recordName the name of the record
+   * @throws MetricsException if recordName conflicts with configuration data
+   */
+  public final synchronized MetricsRecord createRecord(String recordName) {
+    if (bufferedData.get(recordName) == null) {
+      bufferedData.put(recordName, new RecordMap());
+    }
+    return newRecord(recordName);
+  }
+    
+  /**
+   * Subclasses should override this if they subclass MetricsRecordImpl.
+   * @param recordName the name of the record
+   * @return newly created instance of MetricsRecordImpl or subclass
+   */
+  protected MetricsRecordImpl newRecord(String recordName) {
+    return new MetricsRecordImpl(recordName, this);
+  }
+    
+  /**
+   * Registers a callback to be called at time intervals determined by
+   * the configuration.
+   *
+   * @param updater object to be run periodically; it should update
+   * some metrics records 
+   */
+  public synchronized void registerUpdater(final Updater updater) {
+    if (!updaters.contains(updater)) {
+      updaters.add(updater);
+    }
+  }
+    
+  /**
+   * Removes a callback, if it exists.
+   *
+   * @param updater object to be removed from the callback list
+   */
+  public synchronized void unregisterUpdater(Updater updater) {
+    updaters.remove(updater);
+  }
+    
+  private synchronized void clearUpdaters() {
+    updaters.clear();
+  }
+    
+  /**
+   * Starts timer if it is not already started
+   */
+  private synchronized void startTimer() {
+    if (timer == null) {
+      timer = new Timer();
+      TimerTask task = new TimerTask() {
+          public void run() {
+            try {
+              timerEvent();
+            }
+            catch (IOException ioe) {
+              ioe.printStackTrace();
+            }
+          }
+        };
+      long millis = period * 1000;
+      timer.scheduleAtFixedRate(task, millis, millis);
+    }
+  }
+    
+  /**
+   * Stops timer if it is running
+   */
+  private synchronized void stopTimer() {
+    if (timer != null) {
+      timer.cancel();
+      timer = null;
+    }
+  }
+    
+  /**
+   * Timer callback.
+   */
+  private void timerEvent() throws IOException {
+    if (isMonitoring) {
+      Collection<Updater> myUpdaters;
+      synchronized (this) {
+        myUpdaters = new ArrayList<Updater>(updaters);
+      }     
+      // Run all the registered updates without holding a lock
+      // on this context
+      for (Updater updater : myUpdaters) {
+        try {
+          updater.doUpdates(this);
+        }
+        catch (Throwable throwable) {
+          throwable.printStackTrace();
+        }
+      }
+      emitRecords();
+    }
+  }
+    
+  /**
+   *  Emits the records.
+   */
+  private synchronized void emitRecords() throws IOException {
+    for (String recordName : bufferedData.keySet()) {
+      RecordMap recordMap = bufferedData.get(recordName);
+      synchronized (recordMap) {
+        for (TagMap tagMap : recordMap.keySet()) {
+          MetricMap metricMap = recordMap.get(tagMap);
+          OutputRecord outRec = new OutputRecord(tagMap, metricMap);
+          emitRecord(contextName, recordName, outRec);
         }
+      }
     }
-    
-    /**
-     * Stops monitoring.  This does not free buffered data. 
-     * @see #close()
-     */
-    public synchronized void stopMonitoring() {
-        if (isMonitoring) {
-            stopTimer();
-            isMonitoring = false;
+    flush();
+  }
+
+  /**
+   * Sends a record to the metrics system.
+   */
+  protected abstract void emitRecord(String contextName, String recordName, 
+                                     OutputRecord outRec) throws IOException;
+    
+  /**
+   * Called each period after all records have been emitted, this method does nothing.
+   * Subclasses may override it in order to perform some kind of flush.
+   */
+  protected void flush() throws IOException {
+  }
+    
+  /**
+   * Called by MetricsRecordImpl.update().  Creates or updates a row in
+   * the internal table of metric data.
+   */
+  protected void update(MetricsRecordImpl record) {
+    String recordName = record.getRecordName();
+    TagMap tagTable = record.getTagTable();
+    Map<String,MetricValue> metricUpdates = record.getMetricTable();
+        
+    RecordMap recordMap = getRecordMap(recordName);
+    synchronized (recordMap) {
+      MetricMap metricMap = recordMap.get(tagTable);
+      if (metricMap == null) {
+        metricMap = new MetricMap();
+        TagMap tagMap = new TagMap(tagTable); // clone tags
+        recordMap.put(tagMap, metricMap);
+      }
+      for (String metricName : metricUpdates.keySet()) {
+        MetricValue updateValue = metricUpdates.get(metricName);
+        Number updateNumber = updateValue.getNumber();
+        Number currentNumber = metricMap.get(metricName);
+        if (currentNumber == null || updateValue.isAbsolute()) {
+          metricMap.put(metricName, updateNumber);
         }
-    }
-    
-    /**
-     * Returns true if monitoring is currently in progress.
-     */
-    public boolean isMonitoring() {
-        return isMonitoring;
-    }
-    
-    /**
-     * Stops monitoring and frees buffered data, returning this
-     * object to its initial state.  
-     */
-    public synchronized void close() {
-        stopMonitoring();
-        clearUpdaters();
-    } 
-    
-    /**
-     * Creates a new AbstractMetricsRecord instance with the given <code>recordName</code>.
-     * Throws an exception if the metrics implementation is configured with a fixed
-     * set of record names and <code>recordName</code> is not in that set.
-     * 
-     * @param recordName the name of the record
-     * @throws MetricsException if recordName conflicts with configuration data
-     */
-    public final synchronized MetricsRecord createRecord(String recordName) {
-        if (bufferedData.get(recordName) == null) {
-            bufferedData.put(recordName, new RecordMap());
+        else {
+          Number newNumber = sum(updateNumber, currentNumber);
+          metricMap.put(metricName, newNumber);
         }
-        return newRecord(recordName);
+      }
     }
+  }
     
-    /**
-     * Subclasses should override this if they subclass MetricsRecordImpl.
-     * @param recordName the name of the record
-     * @return newly created instance of MetricsRecordImpl or subclass
-     */
-    protected MetricsRecordImpl newRecord(String recordName) {
-        return new MetricsRecordImpl(recordName, this);
-    }
-    
-    /**
-     * Registers a callback to be called at time intervals determined by
-     * the configuration.
-     *
-     * @param updater object to be run periodically; it should update
-     * some metrics records 
-     */
-    public synchronized void registerUpdater(final Updater updater) {
-        if (!updaters.contains(updater)) {
-            updaters.add(updater);
-        }
-    }
+  private synchronized RecordMap getRecordMap(String recordName) {
+    return bufferedData.get(recordName);
+  }
     
-    /**
-     * Removes a callback, if it exists.
-     *
-     * @param updater object to be removed from the callback list
-     */
-    public synchronized void unregisterUpdater(Updater updater) {
-        updaters.remove(updater);
-    }
-    
-    private synchronized void clearUpdaters() {
-        updaters.clear();
-    }
-    
-    /**
-     * Starts timer if it is not already started
-     */
-    private synchronized void startTimer() {
-         if (timer == null) {
-            timer = new Timer();
-            TimerTask task = new TimerTask() {
-                public void run() {
-                    try {
-                        timerEvent();
-                    }
-                    catch (IOException ioe) {
-                        ioe.printStackTrace();
-                    }
-                }
-            };
-            long millis = period * 1000;
-            timer.scheduleAtFixedRate(task, millis, millis);
-         }
-    }
-    
-    /**
-     * Stops timer if it is running
-     */
-    private synchronized void stopTimer() {
-        if (timer != null) {
-            timer.cancel();
-            timer = null;
-        }
+  /**
+   * Adds two numbers, coercing the second to the type of the first.
+   *
+   */
+  private Number sum(Number a, Number b) {
+    if (a instanceof Integer) {
+      return new Integer(a.intValue() + b.intValue());
     }
-    
-    /**
-     * Timer callback.
-     */
-    private void timerEvent() throws IOException {
-        if (isMonitoring) {
-            Collection<Updater> myUpdaters;
-            synchronized (this) {
-                myUpdaters = new ArrayList<Updater>(updaters);
-            }     
-            // Run all the registered updates without holding a lock
-            // on this context
-            for (Updater updater : myUpdaters) {
-                try {
-                    updater.doUpdates(this);
-                }
-                catch (Throwable throwable) {
-                    throwable.printStackTrace();
-                }
-            }
-            emitRecords();
-        }
+    else if (a instanceof Float) {
+      return new Float(a.floatValue() + b.floatValue());
     }
-    
-    /**
-     *  Emits the records.
-     */
-    private synchronized void emitRecords() throws IOException {
-        for (String recordName : bufferedData.keySet()) {
-            RecordMap recordMap = bufferedData.get(recordName);
-            synchronized (recordMap) {
-                for (TagMap tagMap : recordMap.keySet()) {
-                    MetricMap metricMap = recordMap.get(tagMap);
-                    OutputRecord outRec = new OutputRecord(tagMap, metricMap);
-                    emitRecord(contextName, recordName, outRec);
-                }
-            }
-        }
-        flush();
+    else if (a instanceof Short) {
+      return new Short((short)(a.shortValue() + b.shortValue()));
     }
-
-    /**
-     * Sends a record to the metrics system.
-     */
-    protected abstract void emitRecord(String contextName, String recordName, 
-                                       OutputRecord outRec) throws IOException;
-    
-    /**
-     * Called each period after all records have been emitted, this method does nothing.
-     * Subclasses may override it in order to perform some kind of flush.
-     */
-    protected void flush() throws IOException {
-    }
-    
-    /**
-     * Called by MetricsRecordImpl.update().  Creates or updates a row in
-     * the internal table of metric data.
-     */
-    protected void update(MetricsRecordImpl record) {
-        String recordName = record.getRecordName();
-        TagMap tagTable = record.getTagTable();
-        Map<String,MetricValue> metricUpdates = record.getMetricTable();
-        
-        RecordMap recordMap = getRecordMap(recordName);
-        synchronized (recordMap) {
-            MetricMap metricMap = recordMap.get(tagTable);
-            if (metricMap == null) {
-                metricMap = new MetricMap();
-                TagMap tagMap = new TagMap(tagTable); // clone tags
-                recordMap.put(tagMap, metricMap);
-            }
-            for (String metricName : metricUpdates.keySet()) {
-                MetricValue updateValue = metricUpdates.get(metricName);
-                Number updateNumber = updateValue.getNumber();
-                Number currentNumber = metricMap.get(metricName);
-                if (currentNumber == null || updateValue.isAbsolute()) {
-                    metricMap.put(metricName, updateNumber);
-                }
-                else {
-                    Number newNumber = sum(updateNumber, currentNumber);
-                    metricMap.put(metricName, newNumber);
-                }
-            }
-        }
+    else if (a instanceof Byte) {
+      return new Byte((byte)(a.byteValue() + b.byteValue()));
     }
-    
-    private synchronized RecordMap getRecordMap(String recordName) {
-        return bufferedData.get(recordName);
+    else {
+      // should never happen
+      throw new MetricsException("Invalid number type");
     }
-    
-    /**
-     * Adds two numbers, coercing the second to the type of the first.
-     *
-     */
-    private Number sum(Number a, Number b) {
-        if (a instanceof Integer) {
-            return new Integer(a.intValue() + b.intValue());
-        }
-        else if (a instanceof Float) {
-            return new Float(a.floatValue() + b.floatValue());
-        }
-        else if (a instanceof Short) {
-            return new Short((short)(a.shortValue() + b.shortValue()));
-        }
-        else if (a instanceof Byte) {
-            return new Byte((byte)(a.byteValue() + b.byteValue()));
-        }
-        else {
-            // should never happen
-            throw new MetricsException("Invalid number type");
-        }
             
-    }
+  }
     
-    /**
-     * Called by MetricsRecordImpl.remove().  Removes any matching row in
-     * the internal table of metric data.  A row matches if it has the same
-     * tag names and tag values.
-     */    
-    protected void remove(MetricsRecordImpl record) {
-        String recordName = record.getRecordName();
-        TagMap tagTable = record.getTagTable();
+  /**
+   * Called by MetricsRecordImpl.remove().  Removes any matching row in
+   * the internal table of metric data.  A row matches if it has the same
+   * tag names and tag values.
+   */    
+  protected void remove(MetricsRecordImpl record) {
+    String recordName = record.getRecordName();
+    TagMap tagTable = record.getTagTable();
         
-        RecordMap recordMap = getRecordMap(recordName);
-        synchronized (recordMap) {
-            recordMap.remove(tagTable);
-        }
-    }
-    
-    /**
-     * Returns the timer period.
-     */
-    public int getPeriod() {
-        return period;
-    }
-    
-    /**
-     * Sets the timer period
-     */
-    protected void setPeriod(int period) {
-        this.period = period;
-    }
+    RecordMap recordMap = getRecordMap(recordName);
+    synchronized (recordMap) {
+      recordMap.remove(tagTable);
+    }
+  }
+    
+  /**
+   * Returns the timer period.
+   */
+  public int getPeriod() {
+    return period;
+  }
+    
+  /**
+   * Sets the timer period
+   */
+  protected void setPeriod(int period) {
+    this.period = period;
+  }
 }

Modified: lucene/hadoop/trunk/src/java/org/apache/hadoop/metrics/spi/MetricValue.java
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/java/org/apache/hadoop/metrics/spi/MetricValue.java?view=diff&rev=529410&r1=529409&r2=529410
==============================================================================
--- lucene/hadoop/trunk/src/java/org/apache/hadoop/metrics/spi/MetricValue.java (original)
+++ lucene/hadoop/trunk/src/java/org/apache/hadoop/metrics/spi/MetricValue.java Mon Apr 16 14:44:35 2007
@@ -25,28 +25,28 @@
  */
 public class MetricValue {
     
-    public static final boolean ABSOLUTE = false;
-    public static final boolean INCREMENT = true;
+  public static final boolean ABSOLUTE = false;
+  public static final boolean INCREMENT = true;
     
-    private boolean isIncrement;
-    private Number number;
+  private boolean isIncrement;
+  private Number number;
     
-    /** Creates a new instance of MetricValue */
-    public MetricValue(Number number, boolean isIncrement) {
-        this.number = number;
-        this.isIncrement = isIncrement;
-    }
+  /** Creates a new instance of MetricValue */
+  public MetricValue(Number number, boolean isIncrement) {
+    this.number = number;
+    this.isIncrement = isIncrement;
+  }
 
-    public boolean isIncrement() {
-        return isIncrement;
-    }
+  public boolean isIncrement() {
+    return isIncrement;
+  }
     
-    public boolean isAbsolute() {
-        return !isIncrement;
-    }
+  public boolean isAbsolute() {
+    return !isIncrement;
+  }
 
-    public Number getNumber() {
-        return number;
-    }
+  public Number getNumber() {
+    return number;
+  }
     
 }

Modified: lucene/hadoop/trunk/src/java/org/apache/hadoop/metrics/spi/MetricsRecordImpl.java
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/java/org/apache/hadoop/metrics/spi/MetricsRecordImpl.java?view=diff&rev=529410&r1=529409&r2=529410
==============================================================================
--- lucene/hadoop/trunk/src/java/org/apache/hadoop/metrics/spi/MetricsRecordImpl.java (original)
+++ lucene/hadoop/trunk/src/java/org/apache/hadoop/metrics/spi/MetricsRecordImpl.java Mon Apr 16 14:44:35 2007
@@ -32,202 +32,202 @@
  */
 public class MetricsRecordImpl implements MetricsRecord {
     
-    private TagMap tagTable = new TagMap();
-    private Map<String,MetricValue> metricTable = new LinkedHashMap<String,MetricValue>();
+  private TagMap tagTable = new TagMap();
+  private Map<String,MetricValue> metricTable = new LinkedHashMap<String,MetricValue>();
     
-    private String recordName;
-    private AbstractMetricsContext context;
+  private String recordName;
+  private AbstractMetricsContext context;
     
     
-    /** Creates a new instance of FileRecord */
-    protected MetricsRecordImpl(String recordName, AbstractMetricsContext context)
-    {
-        this.recordName = recordName;
-        this.context = context;
-    }
-    
-    /**
-     * Returns the record name. 
-     *
-     * @return the record name
-     */
-    public String getRecordName() {
-        return recordName;
-    }
-    
-    /**
-     * Sets the named tag to the specified value.
-     *
-     * @param tagName name of the tag
-     * @param tagValue new value of the tag
-     * @throws MetricsException if the tagName conflicts with the configuration
-     */
-    public void setTag(String tagName, String tagValue) {
-        if (tagValue == null) {
-            tagValue = "";
-        }
-        tagTable.put(tagName, tagValue);
-    }
-    
-    /**
-     * Sets the named tag to the specified value.
-     *
-     * @param tagName name of the tag
-     * @param tagValue new value of the tag
-     * @throws MetricsException if the tagName conflicts with the configuration
-     */
-    public void setTag(String tagName, int tagValue) {
-        tagTable.put(tagName, new Integer(tagValue));
-    }
-    
-    /**
-     * Sets the named tag to the specified value.
-     *
-     * @param tagName name of the tag
-     * @param tagValue new value of the tag
-     * @throws MetricsException if the tagName conflicts with the configuration
-     */
-    public void setTag(String tagName, short tagValue) {
-        tagTable.put(tagName, new Short(tagValue));
-    }
-    
-    /**
-     * Sets the named tag to the specified value.
-     *
-     * @param tagName name of the tag
-     * @param tagValue new value of the tag
-     * @throws MetricsException if the tagName conflicts with the configuration
-     */
-    public void setTag(String tagName, byte tagValue) {
-        tagTable.put(tagName, new Byte(tagValue));
-    }
-    
-    /**
-     * Sets the named metric to the specified value.
-     *
-     * @param metricName name of the metric
-     * @param metricValue new value of the metric
-     * @throws MetricsException if the metricName or the type of the metricValue 
-     * conflicts with the configuration
-     */
-    public void setMetric(String metricName, int metricValue) {
-        setAbsolute(metricName, new Integer(metricValue));
-    }
-    
-    /**
-     * Sets the named metric to the specified value.
-     *
-     * @param metricName name of the metric
-     * @param metricValue new value of the metric
-     * @throws MetricsException if the metricName or the type of the metricValue 
-     * conflicts with the configuration
-     */
-    public void setMetric(String metricName, short metricValue) {
-        setAbsolute(metricName, new Short(metricValue));
-    }
-    
-    /**
-     * Sets the named metric to the specified value.
-     *
-     * @param metricName name of the metric
-     * @param metricValue new value of the metric
-     * @throws MetricsException if the metricName or the type of the metricValue 
-     * conflicts with the configuration
-     */
-    public void setMetric(String metricName, byte metricValue) {
-        setAbsolute(metricName, new Byte(metricValue));
-    }
-    
-    /**
-     * Sets the named metric to the specified value.
-     *
-     * @param metricName name of the metric
-     * @param metricValue new value of the metric
-     * @throws MetricsException if the metricName or the type of the metricValue 
-     * conflicts with the configuration
-     */
-    public void setMetric(String metricName, float metricValue) {
-        setAbsolute(metricName, new Float(metricValue));
-    }
-    
-    /**
-     * Increments the named metric by the specified value.
-     *
-     * @param metricName name of the metric
-     * @param metricValue incremental value
-     * @throws MetricsException if the metricName or the type of the metricValue 
-     * conflicts with the configuration
-     */
-    public void incrMetric(String metricName, int metricValue) {
-        setIncrement(metricName, new Integer(metricValue));
-    }
-    
-    /**
-     * Increments the named metric by the specified value.
-     *
-     * @param metricName name of the metric
-     * @param metricValue incremental value
-     * @throws MetricsException if the metricName or the type of the metricValue 
-     * conflicts with the configuration
-     */
-    public void incrMetric(String metricName, short metricValue) {
-        setIncrement(metricName, new Short(metricValue));
-    }
-    
-    /**
-     * Increments the named metric by the specified value.
-     *
-     * @param metricName name of the metric
-     * @param metricValue incremental value
-     * @throws MetricsException if the metricName or the type of the metricValue 
-     * conflicts with the configuration
-     */
-    public void incrMetric(String metricName, byte metricValue) {
-        setIncrement(metricName, new Byte(metricValue));
-    }
-    
-    /**
-     * Increments the named metric by the specified value.
-     *
-     * @param metricName name of the metric
-     * @param metricValue incremental value
-     * @throws MetricsException if the metricName or the type of the metricValue 
-     * conflicts with the configuration
-     */
-    public void incrMetric(String metricName, float metricValue) {
-        setIncrement(metricName, new Float(metricValue));
-    }
-    
-    private void setAbsolute(String metricName, Number metricValue) {
-        metricTable.put(metricName, new MetricValue(metricValue, MetricValue.ABSOLUTE));
-    }
-    
-    private void setIncrement(String metricName, Number metricValue) {
-        metricTable.put(metricName, new MetricValue(metricValue, MetricValue.INCREMENT));
-    }
-    
-    /**
-     * Updates the table of buffered data which is to be sent periodically.
-     * If the tag values match an existing row, that row is updated; 
-     * otherwise, a new row is added.
-     */
-    public void update() {
-        context.update(this);
-    }
-    
-    /**
-     * Removes the row, if it exists, in the buffered data table having tags 
-     * that equal the tags that have been set on this record. 
-     */
-    public void remove() {
-        context.remove(this);
-    }
+  /** Creates a new instance of FileRecord */
+  protected MetricsRecordImpl(String recordName, AbstractMetricsContext context)
+  {
+    this.recordName = recordName;
+    this.context = context;
+  }
+    
+  /**
+   * Returns the record name. 
+   *
+   * @return the record name
+   */
+  public String getRecordName() {
+    return recordName;
+  }
+    
+  /**
+   * Sets the named tag to the specified value.
+   *
+   * @param tagName name of the tag
+   * @param tagValue new value of the tag
+   * @throws MetricsException if the tagName conflicts with the configuration
+   */
+  public void setTag(String tagName, String tagValue) {
+    if (tagValue == null) {
+      tagValue = "";
+    }
+    tagTable.put(tagName, tagValue);
+  }
+    
+  /**
+   * Sets the named tag to the specified value.
+   *
+   * @param tagName name of the tag
+   * @param tagValue new value of the tag
+   * @throws MetricsException if the tagName conflicts with the configuration
+   */
+  public void setTag(String tagName, int tagValue) {
+    tagTable.put(tagName, new Integer(tagValue));
+  }
+    
+  /**
+   * Sets the named tag to the specified value.
+   *
+   * @param tagName name of the tag
+   * @param tagValue new value of the tag
+   * @throws MetricsException if the tagName conflicts with the configuration
+   */
+  public void setTag(String tagName, short tagValue) {
+    tagTable.put(tagName, new Short(tagValue));
+  }
+    
+  /**
+   * Sets the named tag to the specified value.
+   *
+   * @param tagName name of the tag
+   * @param tagValue new value of the tag
+   * @throws MetricsException if the tagName conflicts with the configuration
+   */
+  public void setTag(String tagName, byte tagValue) {
+    tagTable.put(tagName, new Byte(tagValue));
+  }
+    
+  /**
+   * Sets the named metric to the specified value.
+   *
+   * @param metricName name of the metric
+   * @param metricValue new value of the metric
+   * @throws MetricsException if the metricName or the type of the metricValue 
+   * conflicts with the configuration
+   */
+  public void setMetric(String metricName, int metricValue) {
+    setAbsolute(metricName, new Integer(metricValue));
+  }
+    
+  /**
+   * Sets the named metric to the specified value.
+   *
+   * @param metricName name of the metric
+   * @param metricValue new value of the metric
+   * @throws MetricsException if the metricName or the type of the metricValue 
+   * conflicts with the configuration
+   */
+  public void setMetric(String metricName, short metricValue) {
+    setAbsolute(metricName, new Short(metricValue));
+  }
+    
+  /**
+   * Sets the named metric to the specified value.
+   *
+   * @param metricName name of the metric
+   * @param metricValue new value of the metric
+   * @throws MetricsException if the metricName or the type of the metricValue 
+   * conflicts with the configuration
+   */
+  public void setMetric(String metricName, byte metricValue) {
+    setAbsolute(metricName, new Byte(metricValue));
+  }
+    
+  /**
+   * Sets the named metric to the specified value.
+   *
+   * @param metricName name of the metric
+   * @param metricValue new value of the metric
+   * @throws MetricsException if the metricName or the type of the metricValue 
+   * conflicts with the configuration
+   */
+  public void setMetric(String metricName, float metricValue) {
+    setAbsolute(metricName, new Float(metricValue));
+  }
+    
+  /**
+   * Increments the named metric by the specified value.
+   *
+   * @param metricName name of the metric
+   * @param metricValue incremental value
+   * @throws MetricsException if the metricName or the type of the metricValue 
+   * conflicts with the configuration
+   */
+  public void incrMetric(String metricName, int metricValue) {
+    setIncrement(metricName, new Integer(metricValue));
+  }
+    
+  /**
+   * Increments the named metric by the specified value.
+   *
+   * @param metricName name of the metric
+   * @param metricValue incremental value
+   * @throws MetricsException if the metricName or the type of the metricValue 
+   * conflicts with the configuration
+   */
+  public void incrMetric(String metricName, short metricValue) {
+    setIncrement(metricName, new Short(metricValue));
+  }
+    
+  /**
+   * Increments the named metric by the specified value.
+   *
+   * @param metricName name of the metric
+   * @param metricValue incremental value
+   * @throws MetricsException if the metricName or the type of the metricValue 
+   * conflicts with the configuration
+   */
+  public void incrMetric(String metricName, byte metricValue) {
+    setIncrement(metricName, new Byte(metricValue));
+  }
+    
+  /**
+   * Increments the named metric by the specified value.
+   *
+   * @param metricName name of the metric
+   * @param metricValue incremental value
+   * @throws MetricsException if the metricName or the type of the metricValue 
+   * conflicts with the configuration
+   */
+  public void incrMetric(String metricName, float metricValue) {
+    setIncrement(metricName, new Float(metricValue));
+  }
+    
+  private void setAbsolute(String metricName, Number metricValue) {
+    metricTable.put(metricName, new MetricValue(metricValue, MetricValue.ABSOLUTE));
+  }
+    
+  private void setIncrement(String metricName, Number metricValue) {
+    metricTable.put(metricName, new MetricValue(metricValue, MetricValue.INCREMENT));
+  }
+    
+  /**
+   * Updates the table of buffered data which is to be sent periodically.
+   * If the tag values match an existing row, that row is updated; 
+   * otherwise, a new row is added.
+   */
+  public void update() {
+    context.update(this);
+  }
+    
+  /**
+   * Removes the row, if it exists, in the buffered data table having tags 
+   * that equal the tags that have been set on this record. 
+   */
+  public void remove() {
+    context.remove(this);
+  }
 
-    TagMap getTagTable() {
-        return tagTable;
-    }
+  TagMap getTagTable() {
+    return tagTable;
+  }
 
-    Map<String, MetricValue> getMetricTable() {
-        return metricTable;
-    }
+  Map<String, MetricValue> getMetricTable() {
+    return metricTable;
+  }
 }

Modified: lucene/hadoop/trunk/src/java/org/apache/hadoop/metrics/spi/NullContext.java
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/java/org/apache/hadoop/metrics/spi/NullContext.java?view=diff&rev=529410&r1=529409&r2=529410
==============================================================================
--- lucene/hadoop/trunk/src/java/org/apache/hadoop/metrics/spi/NullContext.java (original)
+++ lucene/hadoop/trunk/src/java/org/apache/hadoop/metrics/spi/NullContext.java Mon Apr 16 14:44:35 2007
@@ -27,32 +27,32 @@
  */
 public class NullContext extends AbstractMetricsContext {
     
-    /** Creates a new instance of NullContext */
-    public NullContext() {
-    }
+  /** Creates a new instance of NullContext */
+  public NullContext() {
+  }
     
-    /**
-     * Do-nothing version of startMonitoring
-     */
-    public void startMonitoring() {
-    }
+  /**
+   * Do-nothing version of startMonitoring
+   */
+  public void startMonitoring() {
+  }
     
-    /**
-     * Do-nothing version of emitRecord
-     */
-    protected void emitRecord(String contextName, String recordName,
-                              OutputRecord outRec) 
-    {}
+  /**
+   * Do-nothing version of emitRecord
+   */
+  protected void emitRecord(String contextName, String recordName,
+                            OutputRecord outRec) 
+  {}
     
-    /**
-     * Do-nothing version of update
-     */
-    protected void update(MetricsRecordImpl record) {
-    }
+  /**
+   * Do-nothing version of update
+   */
+  protected void update(MetricsRecordImpl record) {
+  }
     
-    /**
-     * Do-nothing version of remove
-     */
-    protected void remove(MetricsRecordImpl record) {
-    }
+  /**
+   * Do-nothing version of remove
+   */
+  protected void remove(MetricsRecordImpl record) {
+  }
 }

Modified: lucene/hadoop/trunk/src/java/org/apache/hadoop/metrics/spi/OutputRecord.java
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/java/org/apache/hadoop/metrics/spi/OutputRecord.java?view=diff&rev=529410&r1=529409&r2=529410
==============================================================================
--- lucene/hadoop/trunk/src/java/org/apache/hadoop/metrics/spi/OutputRecord.java (original)
+++ lucene/hadoop/trunk/src/java/org/apache/hadoop/metrics/spi/OutputRecord.java Mon Apr 16 14:44:35 2007
@@ -30,43 +30,43 @@
  */
 public class OutputRecord {
     
-    private TagMap tagMap;
-    private MetricMap metricMap;
+  private TagMap tagMap;
+  private MetricMap metricMap;
     
-    /** Creates a new instance of OutputRecord */
-    OutputRecord(TagMap tagMap, MetricMap metricMap) {
-        this.tagMap = tagMap;
-        this.metricMap = metricMap;
-    }
+  /** Creates a new instance of OutputRecord */
+  OutputRecord(TagMap tagMap, MetricMap metricMap) {
+    this.tagMap = tagMap;
+    this.metricMap = metricMap;
+  }
     
-    /**
-     * Returns the set of tag names
-     */
-    public Set<String> getTagNames() {
-        return Collections.unmodifiableSet(tagMap.keySet());
-    }
+  /**
+   * Returns the set of tag names
+   */
+  public Set<String> getTagNames() {
+    return Collections.unmodifiableSet(tagMap.keySet());
+  }
     
-    /**
-     * Returns a tag object which is can be a String, Integer, Short or Byte.
-     *
-     * @return the tag value, or null if there is no such tag
-     */
-    public Object getTag(String name) {
-        return tagMap.get(name);
-    }
+  /**
+   * Returns a tag object which is can be a String, Integer, Short or Byte.
+   *
+   * @return the tag value, or null if there is no such tag
+   */
+  public Object getTag(String name) {
+    return tagMap.get(name);
+  }
     
-    /**
-     * Returns the set of metric names.
-     */
-    public Set<String> getMetricNames() {
-        return Collections.unmodifiableSet(metricMap.keySet());
-    }
+  /**
+   * Returns the set of metric names.
+   */
+  public Set<String> getMetricNames() {
+    return Collections.unmodifiableSet(metricMap.keySet());
+  }
     
-    /**
-     * Returns the metric object which can be a Float, Integer, Short or Byte.
-     */
-    public Number getMetric(String name) {
-        return (Number) metricMap.get(name);
-    }
+  /**
+   * Returns the metric object which can be a Float, Integer, Short or Byte.
+   */
+  public Number getMetric(String name) {
+    return (Number) metricMap.get(name);
+  }
     
 }

Modified: lucene/hadoop/trunk/src/java/org/apache/hadoop/metrics/spi/Util.java
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/java/org/apache/hadoop/metrics/spi/Util.java?view=diff&rev=529410&r1=529409&r2=529410
==============================================================================
--- lucene/hadoop/trunk/src/java/org/apache/hadoop/metrics/spi/Util.java (original)
+++ lucene/hadoop/trunk/src/java/org/apache/hadoop/metrics/spi/Util.java Mon Apr 16 14:44:35 2007
@@ -31,37 +31,37 @@
  */
 public class Util {
     
-    /**
-     * This class is not intended to be instantiated
-     */
-    private Util() {}
+  /**
+   * This class is not intended to be instantiated
+   */
+  private Util() {}
     
-    /**
-     * Parses a space and/or comma separated sequence of server specifications
-     * of the form <i>hostname</i> or <i>hostname:port</i>.  If 
-     * the specs string is null, defaults to localhost:defaultPort.
-     * 
-     * @return a list of InetSocketAddress objects.
-     */
-    public static List<InetSocketAddress> parse(String specs, int defaultPort) {
-        List<InetSocketAddress> result = new ArrayList<InetSocketAddress>(1);
-        if (specs == null) {
-                result.add(new InetSocketAddress("localhost", defaultPort));
-        }
-        else {
-            String[] specStrings = specs.split("[ ,]+");
-            for (String specString : specStrings) {
-                int colon = specString.indexOf(':');
-                if (colon < 0 || colon == specString.length() - 1) {
-                    result.add(new InetSocketAddress(specString, defaultPort));
-                } else {
-                    String hostname = specString.substring(0, colon);
-                    int port = Integer.parseInt(specString.substring(colon+1));
-                    result.add(new InetSocketAddress(hostname, port));
-                }
-            }
+  /**
+   * Parses a space and/or comma separated sequence of server specifications
+   * of the form <i>hostname</i> or <i>hostname:port</i>.  If 
+   * the specs string is null, defaults to localhost:defaultPort.
+   * 
+   * @return a list of InetSocketAddress objects.
+   */
+  public static List<InetSocketAddress> parse(String specs, int defaultPort) {
+    List<InetSocketAddress> result = new ArrayList<InetSocketAddress>(1);
+    if (specs == null) {
+      result.add(new InetSocketAddress("localhost", defaultPort));
+    }
+    else {
+      String[] specStrings = specs.split("[ ,]+");
+      for (String specString : specStrings) {
+        int colon = specString.indexOf(':');
+        if (colon < 0 || colon == specString.length() - 1) {
+          result.add(new InetSocketAddress(specString, defaultPort));
+        } else {
+          String hostname = specString.substring(0, colon);
+          int port = Integer.parseInt(specString.substring(colon+1));
+          result.add(new InetSocketAddress(hostname, port));
         }
-        return result;
+      }
     }
+    return result;
+  }
     
 }

Modified: lucene/hadoop/trunk/src/java/org/apache/hadoop/net/NetworkTopology.java
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/java/org/apache/hadoop/net/NetworkTopology.java?view=diff&rev=529410&r1=529409&r2=529410
==============================================================================
--- lucene/hadoop/trunk/src/java/org/apache/hadoop/net/NetworkTopology.java (original)
+++ lucene/hadoop/trunk/src/java/org/apache/hadoop/net/NetworkTopology.java Mon Apr 16 14:44:35 2007
@@ -40,530 +40,530 @@
  *
  */
 public class NetworkTopology {
-    public final static String DEFAULT_RACK = "/default-rack";
-    public static final Log LOG = 
-        LogFactory.getLog("org.apache.hadoop.net.NetworkTopology");
+  public final static String DEFAULT_RACK = "/default-rack";
+  public static final Log LOG = 
+    LogFactory.getLog("org.apache.hadoop.net.NetworkTopology");
     
-    /* Inner Node represent a switch/router of a data center or rack.
-     * Different from a leave node, it has non-null children.
-     */
-    private class InnerNode extends NodeBase {
-        private ArrayList<Node> children=new ArrayList<Node>();
-        private int numOfLeaves;
+  /* Inner Node represent a switch/router of a data center or rack.
+   * Different from a leave node, it has non-null children.
+   */
+  private class InnerNode extends NodeBase {
+    private ArrayList<Node> children=new ArrayList<Node>();
+    private int numOfLeaves;
         
-        /** Construct an InnerNode from a path-like string */
-        InnerNode( String path ) {
-            super( path );
-        }
+    /** Construct an InnerNode from a path-like string */
+    InnerNode( String path ) {
+      super( path );
+    }
         
-        /** Construct an InnerNode from its name and its network location */
-        InnerNode( String name, String location ) {
-            super( name, location );
-        }
+    /** Construct an InnerNode from its name and its network location */
+    InnerNode( String name, String location ) {
+      super( name, location );
+    }
         
-        /** Construct an InnerNode
-         * from its name, its network location, its parent, and its level */
-        InnerNode( String name, String location, InnerNode parent, int level ) {
-            super( name, location, parent, level );
-        }
+    /** Construct an InnerNode
+     * from its name, its network location, its parent, and its level */
+    InnerNode( String name, String location, InnerNode parent, int level ) {
+      super( name, location, parent, level );
+    }
         
-        /** Get its children */
-        Collection<Node> getChildren() {return children;}
+    /** Get its children */
+    Collection<Node> getChildren() {return children;}
         
-        /** Return the number of children this node has */
-        int getNumOfChildren() {
-            return children.size();
-        }
+    /** Return the number of children this node has */
+    int getNumOfChildren() {
+      return children.size();
+    }
         
-        /** Judge if this node represents a rack 
-         * Return true if it has no child or its children are not InnerNodes
-         */ 
-        boolean isRack() {
-            if(children.isEmpty()) {
-                return true;
-            }
+    /** Judge if this node represents a rack 
+     * Return true if it has no child or its children are not InnerNodes
+     */ 
+    boolean isRack() {
+      if(children.isEmpty()) {
+        return true;
+      }
             
-            Node firstChild = children.get(0);
-            if(firstChild instanceof InnerNode) {
-                return false;
-            }
+      Node firstChild = children.get(0);
+      if(firstChild instanceof InnerNode) {
+        return false;
+      }
             
-            return true;
-        }
+      return true;
+    }
         
-        /** Judge if this node is an ancestor of node <i>n</i>
-         * 
-         * @param n: a node
-         * @return true if this node is an ancestor of <i>n</i>
-         */
-        boolean isAncestor(Node n) {
-            return getPath().equals(NodeBase.PATH_SEPARATOR_STR) ||
-                   (n.getNetworkLocation()+NodeBase.PATH_SEPARATOR_STR).
-                    startsWith(getPath()+NodeBase.PATH_SEPARATOR_STR);
-        }
-        
-        /** Judge if this node is the parent of node <i>n</i>
-         * 
-         * @param n: a node
-         * @return true if this node is the parent of <i>n</i>
-         */
-        boolean isParent( Node n ) {
-            return n.getNetworkLocation().equals( getPath() );
-        }
-        
-        /* Return a child name of this node who is an ancestor of node <i>n</i> */
-        private String getNextAncestorName( Node n ) {
-            if( !isAncestor(n)) {
-                throw new IllegalArgumentException( 
-                        this + "is not an ancestor of " + n);
-            }
-            String name = n.getNetworkLocation().substring(getPath().length());
-            if(name.charAt(0) == PATH_SEPARATOR) {
-                name = name.substring(1);
-            }
-            int index=name.indexOf(PATH_SEPARATOR);
-            if( index !=-1 )
-                name = name.substring(0, index);
-            return name;
-        }
-        
-        /** Add node <i>n</i> to the subtree of this node 
-         * @param n node to be added
-         * @return true if the node is added; false otherwise
-         */
-        boolean add( DatanodeDescriptor n ) {
-            if( !isAncestor( n ) )
-                throw new IllegalArgumentException( n.getName()+", which is located at "
-                        +n.getNetworkLocation()+", is not a decendent of "+getPath());
-            if( isParent( n ) ) {
-                // this node is the parent of n; add n directly
-                n.setParent( this );
-                n.setLevel( this.level+1 );
-                for(int i=0; i<children.size(); i++) {
-                    if(children.get(i).getName().equals(n.getName())) {
-                        children.set(i, n);
-                        return false;
-                    }
-                }
-                children.add(n);
-                numOfLeaves++;
-                return true;
-            } else {
-                // find the next ancestor node
-                String parentName = getNextAncestorName( n );
-                InnerNode parentNode = null;
-                for(int i=0; i<children.size(); i++) {
-                    if(children.get(i).getName().equals(parentName)) {
-                        parentNode = (InnerNode)children.get(i);
-                        break;
-                    }
-                }
-                if( parentNode == null ) {
-                    // create a new InnerNode
-                    parentNode = new InnerNode( parentName, getPath(),
-                        this, this.getLevel()+1 );
-                    children.add(parentNode);
-                }
-                // add n to the subtree of the next ancestor node
-                if( parentNode.add(n) ) {
-                    numOfLeaves++;
-                    return true;
-                } else {
-                    return false;
-                }
-            }
+    /** Judge if this node is an ancestor of node <i>n</i>
+     * 
+     * @param n: a node
+     * @return true if this node is an ancestor of <i>n</i>
+     */
+    boolean isAncestor(Node n) {
+      return getPath().equals(NodeBase.PATH_SEPARATOR_STR) ||
+        (n.getNetworkLocation()+NodeBase.PATH_SEPARATOR_STR).
+        startsWith(getPath()+NodeBase.PATH_SEPARATOR_STR);
+    }
+        
+    /** Judge if this node is the parent of node <i>n</i>
+     * 
+     * @param n: a node
+     * @return true if this node is the parent of <i>n</i>
+     */
+    boolean isParent( Node n ) {
+      return n.getNetworkLocation().equals( getPath() );
+    }
+        
+    /* Return a child name of this node who is an ancestor of node <i>n</i> */
+    private String getNextAncestorName( Node n ) {
+      if( !isAncestor(n)) {
+        throw new IllegalArgumentException( 
+                                           this + "is not an ancestor of " + n);
+      }
+      String name = n.getNetworkLocation().substring(getPath().length());
+      if(name.charAt(0) == PATH_SEPARATOR) {
+        name = name.substring(1);
+      }
+      int index=name.indexOf(PATH_SEPARATOR);
+      if( index !=-1 )
+        name = name.substring(0, index);
+      return name;
+    }
+        
+    /** Add node <i>n</i> to the subtree of this node 
+     * @param n node to be added
+     * @return true if the node is added; false otherwise
+     */
+    boolean add( DatanodeDescriptor n ) {
+      if( !isAncestor( n ) )
+        throw new IllegalArgumentException( n.getName()+", which is located at "
+                                            +n.getNetworkLocation()+", is not a decendent of "+getPath());
+      if( isParent( n ) ) {
+        // this node is the parent of n; add n directly
+        n.setParent( this );
+        n.setLevel( this.level+1 );
+        for(int i=0; i<children.size(); i++) {
+          if(children.get(i).getName().equals(n.getName())) {
+            children.set(i, n);
+            return false;
+          }
+        }
+        children.add(n);
+        numOfLeaves++;
+        return true;
+      } else {
+        // find the next ancestor node
+        String parentName = getNextAncestorName( n );
+        InnerNode parentNode = null;
+        for(int i=0; i<children.size(); i++) {
+          if(children.get(i).getName().equals(parentName)) {
+            parentNode = (InnerNode)children.get(i);
+            break;
+          }
+        }
+        if( parentNode == null ) {
+          // create a new InnerNode
+          parentNode = new InnerNode( parentName, getPath(),
+                                      this, this.getLevel()+1 );
+          children.add(parentNode);
+        }
+        // add n to the subtree of the next ancestor node
+        if( parentNode.add(n) ) {
+          numOfLeaves++;
+          return true;
+        } else {
+          return false;
         }
+      }
+    }
         
-        /** Remove node <i>n</i> from the subtree of this node
-         * @parameter n node to be deleted 
-         * @return true if the node is deleted; false otherwise
-         */
-        boolean remove( DatanodeDescriptor n ) {
-            String parent = n.getNetworkLocation();
-            String currentPath = getPath();
-            if(!isAncestor(n))
-                throw new IllegalArgumentException( n.getName()
-                        +", which is located at "
-                        +parent+", is not a decendent of "+currentPath);
-            if( isParent(n) ) {
-                // this node is the parent of n; remove n directly
-                for(int i=0; i<children.size(); i++) {
-                    if(children.get(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 );
-                InnerNode parentNode = null;
-                int i;
-                for(i=0; i<children.size(); i++) {
-                    if(children.get(i).getName().equals(parentName)) {
-                        parentNode = (InnerNode)children.get(i);
-                        break;
-                    }
-                }
-                if(parentNode==null) {
-                    return false;
-                }
-                // remove n from the parent node
-                boolean 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;
-            }
-        } // end of remove
+    /** Remove node <i>n</i> from the subtree of this node
+     * @parameter n node to be deleted 
+     * @return true if the node is deleted; false otherwise
+     */
+    boolean remove( DatanodeDescriptor n ) {
+      String parent = n.getNetworkLocation();
+      String currentPath = getPath();
+      if(!isAncestor(n))
+        throw new IllegalArgumentException( n.getName()
+                                            +", which is located at "
+                                            +parent+", is not a decendent of "+currentPath);
+      if( isParent(n) ) {
+        // this node is the parent of n; remove n directly
+        for(int i=0; i<children.size(); i++) {
+          if(children.get(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 );
+        InnerNode parentNode = null;
+        int i;
+        for(i=0; i<children.size(); i++) {
+          if(children.get(i).getName().equals(parentName)) {
+            parentNode = (InnerNode)children.get(i);
+            break;
+          }
+        }
+        if(parentNode==null) {
+          return false;
+        }
+        // remove n from the parent node
+        boolean 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;
+      }
+    } // end of remove
         
-        /** Given a node's string representation, return a reference to the node */ 
-        Node getLoc( String loc ) {
-            if( loc == null || loc.length() == 0 ) return this;
+    /** Given a node's string representation, return a reference to the node */ 
+    Node getLoc( String loc ) {
+      if( loc == null || loc.length() == 0 ) return this;
             
-            String[] path = loc.split(PATH_SEPARATOR_STR, 2);
-            Node childnode = null;
-            for(int i=0; i<children.size(); i++) {
-                if(children.get(i).getName().equals(path[0])) {
-                    childnode = children.get(i);
-                }
-            }
-            if(childnode == null ) return null; // non-existing node
-            if( path.length == 1 ) return childnode;
-            if( childnode instanceof InnerNode ) {
-                return ((InnerNode)childnode).getLoc(path[1]);
-            } else {
-                return null;
-            }
+      String[] path = loc.split(PATH_SEPARATOR_STR, 2);
+      Node childnode = null;
+      for(int i=0; i<children.size(); i++) {
+        if(children.get(i).getName().equals(path[0])) {
+          childnode = children.get(i);
         }
+      }
+      if(childnode == null ) return null; // non-existing node
+      if( path.length == 1 ) return childnode;
+      if( childnode instanceof InnerNode ) {
+        return ((InnerNode)childnode).getLoc(path[1]);
+      } else {
+        return null;
+      }
+    }
         
-        /** get <i>leaveIndex</i> leaf of this subtree 
-         * if it is not in the <i>excludedNode</i>*/
-        private DatanodeDescriptor getLeaf(int leaveIndex, Node excludedNode) {
-            int count=0;
-            int numOfExcludedLeaves = 1;
-            if( excludedNode instanceof InnerNode ) {
-                numOfExcludedLeaves = ((InnerNode)excludedNode).getNumOfLeaves();
-            }
-            if( isRack() ) { // children are leaves
-                // range check
-                if(leaveIndex<0 || leaveIndex>=this.getNumOfChildren()) {
-                    return null;
-                }
-                DatanodeDescriptor child =
-                    (DatanodeDescriptor)children.get(leaveIndex);
-                if(excludedNode == null || excludedNode != child) {
-                    // child is not the excludedNode
-                    return child;
-                } else { // child is the excludedNode so return the next child
-                    if(leaveIndex+1>=this.getNumOfChildren()) {
-                        return null;
-                    } else {
-                        return (DatanodeDescriptor)children.get(leaveIndex+1);
-                    }
-                }
+    /** get <i>leaveIndex</i> leaf of this subtree 
+     * if it is not in the <i>excludedNode</i>*/
+    private DatanodeDescriptor getLeaf(int leaveIndex, Node excludedNode) {
+      int count=0;
+      int numOfExcludedLeaves = 1;
+      if( excludedNode instanceof InnerNode ) {
+        numOfExcludedLeaves = ((InnerNode)excludedNode).getNumOfLeaves();
+      }
+      if( isRack() ) { // children are leaves
+        // range check
+        if(leaveIndex<0 || leaveIndex>=this.getNumOfChildren()) {
+          return null;
+        }
+        DatanodeDescriptor child =
+          (DatanodeDescriptor)children.get(leaveIndex);
+        if(excludedNode == null || excludedNode != child) {
+          // child is not the excludedNode
+          return child;
+        } else { // child is the excludedNode so return the next child
+          if(leaveIndex+1>=this.getNumOfChildren()) {
+            return null;
+          } else {
+            return (DatanodeDescriptor)children.get(leaveIndex+1);
+          }
+        }
+      } else {
+        for( int i=0; i<children.size(); i++ ) {
+          InnerNode child = (InnerNode)children.get(i);
+          if(excludedNode == null || excludedNode != child) {
+            // not the excludedNode
+            int numOfLeaves = child.getNumOfLeaves();
+            if( excludedNode != null && child.isAncestor(excludedNode) ) {
+              numOfLeaves -= numOfExcludedLeaves;
+            }
+            if( count+numOfLeaves > leaveIndex ) {
+              // the leaf is in the child subtree
+              return child.getLeaf(leaveIndex-count, excludedNode);
             } else {
-                for( int i=0; i<children.size(); i++ ) {
-                    InnerNode child = (InnerNode)children.get(i);
-                    if(excludedNode == null || excludedNode != child) {
-                        // not the excludedNode
-                        int numOfLeaves = child.getNumOfLeaves();
-                        if( excludedNode != null && child.isAncestor(excludedNode) ) {
-                            numOfLeaves -= numOfExcludedLeaves;
-                        }
-                        if( count+numOfLeaves > leaveIndex ) {
-                            // the leaf is in the child subtree
-                            return child.getLeaf(leaveIndex-count, excludedNode);
-                        } else {
-                            // go to the next child
-                            count = count+numOfLeaves;
-                        }
-                    } else { // it is the excluededNode
-                        // skip it and set the excludedNode to be null
-                        excludedNode = null;
-                    }
-                }
-                return null;
+              // go to the next child
+              count = count+numOfLeaves;
             }
+          } else { // it is the excluededNode
+            // skip it and set the excludedNode to be null
+            excludedNode = null;
+          }
         }
+        return null;
+      }
+    }
         
-        int getNumOfLeaves() {
-            return numOfLeaves;
-        }
-    } // end of InnerNode
-    
-    InnerNode clusterMap = new InnerNode( InnerNode.ROOT ); // the root
-    private int numOfRacks = 0;  // rack counter
-    
-    public NetworkTopology() {
+    int getNumOfLeaves() {
+      return numOfLeaves;
     }
+  } // end of InnerNode
     
-    /** Add a data node
-     * Update data node counter & rack counter if neccessary
-     * @param node
-     *          data node to be added
-     * @exception IllegalArgumentException if add a data node to a leave
-     */
-    public synchronized void add( DatanodeDescriptor node ) {
-        if( node==null ) return;
-        LOG.info("Adding a new node: "+node.getPath());
-        Node rack = getNode(node.getNetworkLocation());
-        if(rack != null && !(rack instanceof InnerNode) ) {
-            throw new IllegalArgumentException( "Unexpected data node " 
-                    + node.toString() 
-                    + " at an illegal network location");
-        }
-        if( clusterMap.add( node) ) {
-            if( rack == null ) {
-                numOfRacks++;
-            }
-        }
-        LOG.debug("NetworkTopology became:\n" + this.toString());
+  InnerNode clusterMap = new InnerNode( InnerNode.ROOT ); // the root
+  private int numOfRacks = 0;  // rack counter
+    
+  public NetworkTopology() {
+  }
+    
+  /** Add a data node
+   * Update data node counter & rack counter if neccessary
+   * @param node
+   *          data node to be added
+   * @exception IllegalArgumentException if add a data node to a leave
+   */
+  public synchronized void add( DatanodeDescriptor node ) {
+    if( node==null ) return;
+    LOG.info("Adding a new node: "+node.getPath());
+    Node rack = getNode(node.getNetworkLocation());
+    if(rack != null && !(rack instanceof InnerNode) ) {
+      throw new IllegalArgumentException( "Unexpected data node " 
+                                          + node.toString() 
+                                          + " at an illegal network location");
+    }
+    if( clusterMap.add( node) ) {
+      if( rack == null ) {
+        numOfRacks++;
+      }
     }
+    LOG.debug("NetworkTopology became:\n" + this.toString());
+  }
     
-    /** Remove a data node
-     * Update data node counter & rack counter if neccessary
-     * @param node
-     *          data node to be removed
-     */ 
-    public synchronized void remove( DatanodeDescriptor node ) {
-        if( node==null ) return;
-        LOG.info("Removing a node: "+node.getPath());
-        if( clusterMap.remove( node ) ) {
-            InnerNode rack = (InnerNode)getNode(node.getNetworkLocation());
-            if(rack == null) {
-                numOfRacks--;
-            }
-        }
-        LOG.debug("NetworkTopology became:\n" + this.toString());
+  /** Remove a data node
+   * Update data node counter & rack counter if neccessary
+   * @param node
+   *          data node to be removed
+   */ 
+  public synchronized void remove( DatanodeDescriptor node ) {
+    if( node==null ) return;
+    LOG.info("Removing a node: "+node.getPath());
+    if( clusterMap.remove( node ) ) {
+      InnerNode rack = (InnerNode)getNode(node.getNetworkLocation());
+      if(rack == null) {
+        numOfRacks--;
+      }
     }
+    LOG.debug("NetworkTopology became:\n" + this.toString());
+  }
        
-    /** Check if the tree contains data node <i>node</i>
-     * 
-     * @param node
-     *          a data node
-     * @return true if <i>node</i> is already in the tree; false otherwise
-     */
-    public synchronized boolean contains( DatanodeDescriptor node ) {
-        if( node == null ) return false;
-        Node parent = node.getParent();
-        for( int level=node.getLevel(); parent!=null&&level>0;
-                 parent=parent.getParent(), level-- ) {
-          if(parent == clusterMap)
-            return true;
-        }
-        return false; 
+  /** Check if the tree contains data node <i>node</i>
+   * 
+   * @param node
+   *          a data node
+   * @return true if <i>node</i> is already in the tree; false otherwise
+   */
+  public synchronized boolean contains( DatanodeDescriptor node ) {
+    if( node == null ) return false;
+    Node parent = node.getParent();
+    for( int level=node.getLevel(); parent!=null&&level>0;
+         parent=parent.getParent(), level-- ) {
+      if(parent == clusterMap)
+        return true;
+    }
+    return false; 
+  }
+    
+  /** Given a string representation of a node, return its reference
+   * 
+   * @param loc
+   *          a path-like string representation of a node
+   * @return a reference to the node; null if the node is not in the tree
+   */
+  public synchronized Node getNode( String loc ) {
+    loc = NodeBase.normalize(loc);
+    if(!NodeBase.ROOT.equals(loc))
+      loc = loc.substring(1);
+    return clusterMap.getLoc( loc );
+  }
+    
+  /** Return the total number of racks */
+  public synchronized int getNumOfRacks( ) {
+    return numOfRacks;
+  }
+    
+  /** Return the total number of data nodes */
+  public synchronized int getNumOfLeaves() {
+    return clusterMap.getNumOfLeaves();
+  }
+    
+  /** Return the distance between two data nodes
+   * It is assumed that the distance from one node to its parent is 1
+   * The distance between two nodes is calculated by summing up their distances
+   * to their closest common  ancestor.
+   * @param node1 one data node
+   * @param node2 another data node
+   * @return the distance between node1 and node2
+   * node1 or node2 do not belong to the cluster
+   */
+  public int getDistance(DatanodeDescriptor node1, DatanodeDescriptor node2 ) {
+    if( node1 == node2 ) {
+      return 0;
+    }
+    int i;
+    Node n1=node1, n2=node2;
+    int level1=node1.getLevel(), level2=node2.getLevel();
+    int dis = 0;
+    while( n1!=null && level1>level2 ) {
+      n1 = n1.getParent();
+      level1--;
+      dis++;
+    }
+    while( n2!=null && level2>level1 ) {
+      n2 = n2.getParent();
+      level2--;
+      dis++;
+    }
+    while(n1!=null && n2!=null && n1.getParent()!=n2.getParent()) {
+      n1=n1.getParent();
+      n2=n2.getParent();
+      dis+=2;
+    }
+    if (n1==null) {
+      LOG.warn("The cluster does not contain data node: "+node1.getPath());
+      return Integer.MAX_VALUE;
+    }
+    if(n2==null) {
+      LOG.warn("The cluster does not contain data node: "+node2.getPath());
+      return Integer.MAX_VALUE;
+    }
+    return dis+2;
+  } 
+    
+  /** Check if two data nodes are on the same rack
+   * @param node1 one data node
+   * @param node2 another data node
+   * @return true if node1 and node2 are pm the same rack; false otherwise
+   * @exception IllegalArgumentException when either node1 or node2 is null, or
+   * node1 or node2 do not belong to the cluster
+   */
+  public boolean isOnSameRack(
+                              DatanodeDescriptor node1, DatanodeDescriptor node2) {
+    if( node1 == null || node2 == null ) {
+      return false;
     }
-    
-    /** Given a string representation of a node, return its reference
-     * 
-     * @param loc
-     *          a path-like string representation of a node
-     * @return a reference to the node; null if the node is not in the tree
-     */
-    public synchronized Node getNode( String loc ) {
-        loc = NodeBase.normalize(loc);
-        if(!NodeBase.ROOT.equals(loc))
-            loc = loc.substring(1);
-        return clusterMap.getLoc( loc );
-    }
-    
-    /** Return the total number of racks */
-    public synchronized int getNumOfRacks( ) {
-        return numOfRacks;
-    }
-    
-    /** Return the total number of data nodes */
-    public synchronized int getNumOfLeaves() {
-        return clusterMap.getNumOfLeaves();
-    }
-    
-    /** Return the distance between two data nodes
-     * It is assumed that the distance from one node to its parent is 1
-     * The distance between two nodes is calculated by summing up their distances
-     * to their closest common  ancestor.
-     * @param node1 one data node
-     * @param node2 another data node
-     * @return the distance between node1 and node2
-     * node1 or node2 do not belong to the cluster
-     */
-    public int getDistance(DatanodeDescriptor node1, DatanodeDescriptor node2 ) {
-        if( node1 == node2 ) {
-            return 0;
-        }
-        int i;
-        Node n1=node1, n2=node2;
-        int level1=node1.getLevel(), level2=node2.getLevel();
-        int dis = 0;
-        while( n1!=null && level1>level2 ) {
-          n1 = n1.getParent();
-          level1--;
-          dis++;
-        }
-        while( n2!=null && level2>level1 ) {
-          n2 = n2.getParent();
-          level2--;
-          dis++;
-        }
-        while(n1!=null && n2!=null && n1.getParent()!=n2.getParent()) {
-          n1=n1.getParent();
-          n2=n2.getParent();
-          dis+=2;
-        }
-        if (n1==null) {
-          LOG.warn("The cluster does not contain data node: "+node1.getPath());
-          return Integer.MAX_VALUE;
-        }
-        if(n2==null) {
-          LOG.warn("The cluster does not contain data node: "+node2.getPath());
-          return Integer.MAX_VALUE;
-        }
-        return dis+2;
-    } 
-    
-    /** Check if two data nodes are on the same rack
-     * @param node1 one data node
-     * @param node2 another data node
-     * @return true if node1 and node2 are pm the same rack; false otherwise
-     * @exception IllegalArgumentException when either node1 or node2 is null, or
-     * node1 or node2 do not belong to the cluster
-     */
-    public boolean isOnSameRack(
-            DatanodeDescriptor node1, DatanodeDescriptor node2) {
-      if( node1 == null || node2 == null ) {
-        return false;
-      }
       
-        if( node1 == node2 || node1.equals(node2)) {
-            return true;
-        }
-        
-        return node1.getParent()==node2.getParent();
+    if( node1 == node2 || node1.equals(node2)) {
+      return true;
     }
+        
+    return node1.getParent()==node2.getParent();
+  }
     
-    final private static Random r = new Random();
-    /** randomly choose one node from <i>scope</i>
-     * if scope starts with ~, choose one from the all datanodes except for the
-     * ones in <i>scope</i>; otherwise, choose one from <i>scope</i>
-     * @param scope range of datanodes from which a node will be choosen
-     * @return the choosen data node
-     */
-    public DatanodeDescriptor chooseRandom(String scope) {
-        if(scope.startsWith("~")) {
-            return chooseRandom(NodeBase.ROOT, scope.substring(1));
-        } else {
-            return chooseRandom(scope, null);
-        }
+  final private static Random r = new Random();
+  /** randomly choose one node from <i>scope</i>
+   * if scope starts with ~, choose one from the all datanodes except for the
+   * ones in <i>scope</i>; otherwise, choose one from <i>scope</i>
+   * @param scope range of datanodes from which a node will be choosen
+   * @return the choosen data node
+   */
+  public DatanodeDescriptor chooseRandom(String scope) {
+    if(scope.startsWith("~")) {
+      return chooseRandom(NodeBase.ROOT, scope.substring(1));
+    } else {
+      return chooseRandom(scope, null);
+    }
+  }
+    
+  private DatanodeDescriptor chooseRandom(String scope, String excludedScope){
+    if(excludedScope != null) {
+      if(scope.startsWith(excludedScope)) {
+        return null;
+      }
+      if(!excludedScope.startsWith(scope)) {
+        excludedScope = null;
+      }
     }
-    
-    private DatanodeDescriptor chooseRandom(String scope, String excludedScope){
-        if(excludedScope != null) {
-            if(scope.startsWith(excludedScope)) {
-                return null;
-            }
-            if(!excludedScope.startsWith(scope)) {
-                excludedScope = null;
-            }
-        }
-        Node node = getNode(scope);
-        if(node instanceof DatanodeDescriptor) {
-            return (DatanodeDescriptor)node;
-        }
-       InnerNode innerNode = (InnerNode)node;
-       int numOfDatanodes = innerNode.getNumOfLeaves();
-       if(excludedScope == null) {
-           node = null;
-       } else {
-           node = getNode(excludedScope);
-           if(node instanceof DatanodeDescriptor) {
-               numOfDatanodes -= 1;
-           } else {
-               numOfDatanodes -= ((InnerNode)node).getNumOfLeaves();
-           }
-       }
-       int leaveIndex = r.nextInt(numOfDatanodes);
-       return innerNode.getLeaf(leaveIndex, node);
+    Node node = getNode(scope);
+    if(node instanceof DatanodeDescriptor) {
+      return (DatanodeDescriptor)node;
+    }
+    InnerNode innerNode = (InnerNode)node;
+    int numOfDatanodes = innerNode.getNumOfLeaves();
+    if(excludedScope == null) {
+      node = null;
+    } else {
+      node = getNode(excludedScope);
+      if(node instanceof DatanodeDescriptor) {
+        numOfDatanodes -= 1;
+      } else {
+        numOfDatanodes -= ((InnerNode)node).getNumOfLeaves();
+      }
     }
+    int leaveIndex = r.nextInt(numOfDatanodes);
+    return innerNode.getLeaf(leaveIndex, node);
+  }
        
-    /** return the number of leaves in <i>scope</i> but not in <i>excludedNodes</i>
-     * if scope starts with ~, return the number of datanodes that are not
-     * in <i>scope</i> and <i>excludedNodes</i>; 
-     * @param scope a path string that may start with ~
-     * @param excludedNodes a list of data nodes
-     * @return number of available data nodes
-     */
-    public int countNumOfAvailableNodes(String scope,
-            List<DatanodeDescriptor> excludedNodes) {
-        boolean isExcluded=false;
-        if(scope.startsWith("~")) {
-            isExcluded=true;
-            scope=scope.substring(1);
-        }
-        scope = NodeBase.normalize(scope);
-        int count=0; // the number of nodes in both scope & excludedNodes
-        for( DatanodeDescriptor node:excludedNodes) {
-            if( (node.getPath()+NodeBase.PATH_SEPARATOR_STR).
-                    startsWith(scope+NodeBase.PATH_SEPARATOR_STR)) {
-                count++;
-            }
-        }
-        Node n=getNode(scope);
-        int scopeNodeCount=1;
-        if(n instanceof InnerNode) {
-            scopeNodeCount=((InnerNode)n).getNumOfLeaves();
-        }
-        if(isExcluded) {
-            return clusterMap.getNumOfLeaves()-
-                scopeNodeCount-excludedNodes.size()+count;
-        } else {
-            return scopeNodeCount-count;
-        }
+  /** return the number of leaves in <i>scope</i> but not in <i>excludedNodes</i>
+   * if scope starts with ~, return the number of datanodes that are not
+   * in <i>scope</i> and <i>excludedNodes</i>; 
+   * @param scope a path string that may start with ~
+   * @param excludedNodes a list of data nodes
+   * @return number of available data nodes
+   */
+  public int countNumOfAvailableNodes(String scope,
+                                      List<DatanodeDescriptor> excludedNodes) {
+    boolean isExcluded=false;
+    if(scope.startsWith("~")) {
+      isExcluded=true;
+      scope=scope.substring(1);
+    }
+    scope = NodeBase.normalize(scope);
+    int count=0; // the number of nodes in both scope & excludedNodes
+    for( DatanodeDescriptor node:excludedNodes) {
+      if( (node.getPath()+NodeBase.PATH_SEPARATOR_STR).
+          startsWith(scope+NodeBase.PATH_SEPARATOR_STR)) {
+        count++;
+      }
     }
-    
-    /** convert a network tree to a string */
-    public String toString() {
-        // print the number of racks
-        StringBuffer tree = new StringBuffer();
-        tree.append( "Number of racks: " );
-        tree.append( numOfRacks );
-        tree.append( "\n" );
-        // print the number of leaves
-        int numOfLeaves = getNumOfLeaves();
-        tree.append( "Expected number of leaves:" );
-        tree.append( numOfLeaves );
-        tree.append( "\n" );
-        // print datanodes
-        for( int i=0; i<numOfLeaves; i++ ) {
-            tree.append( clusterMap.getLeaf(i, null).getPath() );
-            tree.append( "\n");
-        }
-        return tree.toString();
+    Node n=getNode(scope);
+    int scopeNodeCount=1;
+    if(n instanceof InnerNode) {
+      scopeNodeCount=((InnerNode)n).getNumOfLeaves();
+    }
+    if(isExcluded) {
+      return clusterMap.getNumOfLeaves()-
+        scopeNodeCount-excludedNodes.size()+count;
+    } else {
+      return scopeNodeCount-count;
+    }
+  }
+    
+  /** convert a network tree to a string */
+  public String toString() {
+    // print the number of racks
+    StringBuffer tree = new StringBuffer();
+    tree.append( "Number of racks: " );
+    tree.append( numOfRacks );
+    tree.append( "\n" );
+    // print the number of leaves
+    int numOfLeaves = getNumOfLeaves();
+    tree.append( "Expected number of leaves:" );
+    tree.append( numOfLeaves );
+    tree.append( "\n" );
+    // print datanodes
+    for( int i=0; i<numOfLeaves; i++ ) {
+      tree.append( clusterMap.getLeaf(i, null).getPath() );
+      tree.append( "\n");
     }
+    return tree.toString();
+  }
 
-    /* Set and used only inside sortByDistance. 
-     * This saves an allocation each time we sort.
-     */
-    private DatanodeDescriptor distFrom = null;
-    private final Comparator<DatanodeDescriptor> nodeDistanceComparator = 
-      new Comparator<DatanodeDescriptor>() {
-        public int compare(DatanodeDescriptor n1, DatanodeDescriptor n2) {
-          return getDistance(distFrom, n1) - getDistance(distFrom, n2);
-        }
+  /* Set and used only inside sortByDistance. 
+   * This saves an allocation each time we sort.
+   */
+  private DatanodeDescriptor distFrom = null;
+  private final Comparator<DatanodeDescriptor> nodeDistanceComparator = 
+    new Comparator<DatanodeDescriptor>() {
+      public int compare(DatanodeDescriptor n1, DatanodeDescriptor n2) {
+        return getDistance(distFrom, n1) - getDistance(distFrom, n2);
+      }
     };
       
-    /** Sorts nodes array by their distances to <i>reader</i>. */
-    public synchronized void sortByDistance( final DatanodeDescriptor reader,
-                                             DatanodeDescriptor[] nodes ) { 
-      if(reader != null && contains(reader)) {
-        distFrom = reader;
-        Arrays.sort( nodes, nodeDistanceComparator );
-        distFrom = null;
-      }
+  /** Sorts nodes array by their distances to <i>reader</i>. */
+  public synchronized void sortByDistance( final DatanodeDescriptor reader,
+                                           DatanodeDescriptor[] nodes ) { 
+    if(reader != null && contains(reader)) {
+      distFrom = reader;
+      Arrays.sort( nodes, nodeDistanceComparator );
+      distFrom = null;
     }
+  }
 }

Modified: lucene/hadoop/trunk/src/java/org/apache/hadoop/net/NodeBase.java
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/java/org/apache/hadoop/net/NodeBase.java?view=diff&rev=529410&r1=529409&r2=529410
==============================================================================
--- lucene/hadoop/trunk/src/java/org/apache/hadoop/net/NodeBase.java (original)
+++ lucene/hadoop/trunk/src/java/org/apache/hadoop/net/NodeBase.java Mon Apr 16 14:44:35 2007
@@ -75,7 +75,7 @@
   private void set( String name, String location ) {
     if(name != null && name.contains(PATH_SEPARATOR_STR))
       throw new IllegalArgumentException(
-          "Network location name contains /: "+name);
+                                         "Network location name contains /: "+name);
     this.name = (name==null)?"":name;
     this.location = location;      
   }
@@ -102,8 +102,8 @@
     
     if( path.charAt(0) != PATH_SEPARATOR ) {
       throw new IllegalArgumentException( 
-          "Network Location path does not start with "
-          +PATH_SEPARATOR_STR+ ": "+path);
+                                         "Network Location path does not start with "
+                                         +PATH_SEPARATOR_STR+ ": "+path);
     }
     
     int len = path.length();



Mime
View raw message