hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cutt...@apache.org
Subject svn commit: r405874 - in /lucene/hadoop/trunk: ./ src/java/org/apache/hadoop/metrics/ src/java/org/apache/hadoop/metrics/spi/
Date Fri, 12 May 2006 21:12:56 GMT
Author: cutting
Date: Fri May 12 14:12:55 2006
New Revision: 405874

URL: http://svn.apache.org/viewcvs?rev=405874&view=rev
Log:
HADOOP-204.  Tweaks to metrics package.  Contributed by David Bowen.

Modified:
    lucene/hadoop/trunk/CHANGES.txt
    lucene/hadoop/trunk/build.xml
    lucene/hadoop/trunk/src/java/org/apache/hadoop/metrics/MetricsContext.java
    lucene/hadoop/trunk/src/java/org/apache/hadoop/metrics/MetricsException.java
    lucene/hadoop/trunk/src/java/org/apache/hadoop/metrics/spi/AbstractMetricsContext.java
    lucene/hadoop/trunk/src/java/org/apache/hadoop/metrics/spi/MetricsRecordImpl.java
    lucene/hadoop/trunk/src/java/org/apache/hadoop/metrics/spi/Util.java

Modified: lucene/hadoop/trunk/CHANGES.txt
URL: http://svn.apache.org/viewcvs/lucene/hadoop/trunk/CHANGES.txt?rev=405874&r1=405873&r2=405874&view=diff
==============================================================================
--- lucene/hadoop/trunk/CHANGES.txt (original)
+++ lucene/hadoop/trunk/CHANGES.txt Fri May 12 14:12:55 2006
@@ -6,6 +6,8 @@
  1. HADOOP-208.  Enhance MapReduce web interface, adding new pages
     for failed tasks, and tasktrackers.  (omalley via cutting)
 
+ 2. HADOOP-204.  Tweaks to metrics package.  (David Bowen via cutting)
+
 
 Release 0.2.1 - 2006-05-12
 

Modified: lucene/hadoop/trunk/build.xml
URL: http://svn.apache.org/viewcvs/lucene/hadoop/trunk/build.xml?rev=405874&r1=405873&r2=405874&view=diff
==============================================================================
--- lucene/hadoop/trunk/build.xml (original)
+++ lucene/hadoop/trunk/build.xml Fri May 12 14:12:55 2006
@@ -188,6 +188,20 @@
   </target>
 
   <!-- ================================================================== -->
+  <!-- Make the Hadoop metrics jar. (for use outside Hadoop)              -->
+  <!-- ================================================================== -->
+  <!--                                                                    -->
+  <!-- ================================================================== -->
+  <target name="metrics.jar" depends="compile">
+    <jar jarfile="${build.dir}/hadoop-metrics-${version}.jar"
+         basedir="${build.classes}">
+      <include name="**/metrics/**" />
+      <exclude name="**/package.html" />
+    </jar>
+  </target>
+
+
+  <!-- ================================================================== -->
   <!-- Compile test code                                                  --> 
   <!-- ================================================================== -->
   <target name="compile-test" depends="compile, jar">

Modified: lucene/hadoop/trunk/src/java/org/apache/hadoop/metrics/MetricsContext.java
URL: http://svn.apache.org/viewcvs/lucene/hadoop/trunk/src/java/org/apache/hadoop/metrics/MetricsContext.java?rev=405874&r1=405873&r2=405874&view=diff
==============================================================================
--- lucene/hadoop/trunk/src/java/org/apache/hadoop/metrics/MetricsContext.java (original)
+++ lucene/hadoop/trunk/src/java/org/apache/hadoop/metrics/MetricsContext.java Fri May 12
14:12:55 2006
@@ -19,8 +19,6 @@
 package org.apache.hadoop.metrics;
 
 import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
 
 /**
  * The main interface to the metrics package. 

Modified: lucene/hadoop/trunk/src/java/org/apache/hadoop/metrics/MetricsException.java
URL: http://svn.apache.org/viewcvs/lucene/hadoop/trunk/src/java/org/apache/hadoop/metrics/MetricsException.java?rev=405874&r1=405873&r2=405874&view=diff
==============================================================================
--- lucene/hadoop/trunk/src/java/org/apache/hadoop/metrics/MetricsException.java (original)
+++ lucene/hadoop/trunk/src/java/org/apache/hadoop/metrics/MetricsException.java Fri May 12
14:12:55 2006
@@ -23,7 +23,9 @@
  */
 public class MetricsException extends RuntimeException {
     
-    /** Creates a new instance of MetricsException */
+	private static final long serialVersionUID = -1643257498540498497L;
+
+	/** Creates a new instance of MetricsException */
     public MetricsException() {
     }
     

Modified: lucene/hadoop/trunk/src/java/org/apache/hadoop/metrics/spi/AbstractMetricsContext.java
URL: http://svn.apache.org/viewcvs/lucene/hadoop/trunk/src/java/org/apache/hadoop/metrics/spi/AbstractMetricsContext.java?rev=405874&r1=405873&r2=405874&view=diff
==============================================================================
--- 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
Fri May 12 14:12:55 2006
@@ -57,7 +57,8 @@
     
     //static class TagMap extends TreeMap<String,Object> {
     static class TagMap extends TreeMap {
-        TagMap() {
+		private static final long serialVersionUID = 3546309335061952993L;
+		TagMap() {
             super();
         }
         TagMap(TagMap orig) {
@@ -65,10 +66,14 @@
         }
     }
     //static class MetricMap extends TreeMap<String,Number> {}
-    static class MetricMap extends TreeMap {}
+    static class MetricMap extends TreeMap {
+		private static final long serialVersionUID = -7495051861141631609L;
+    }
             
     //static class RecordMap extends HashMap<TagMap,MetricMap> {}
-    static class RecordMap extends HashMap {}
+    static class RecordMap extends HashMap {
+		private static final long serialVersionUID = 259835619700264611L;
+    }
     
     //private Map<String,RecordMap> bufferedData = new HashMap<String,RecordMap>();
     private Map bufferedData = new HashMap();
@@ -181,11 +186,20 @@
      * @param recordName the name of the record
      * @throws MetricsException if recordName conflicts with configuration data
      */
-    public synchronized MetricsRecord createRecord(String recordName) {
+    public final synchronized MetricsRecord createRecord(String recordName) {
         if (bufferedData.get(recordName) == null) {
             bufferedData.put(recordName, new RecordMap());
         }
-        return new MetricsRecordImpl(recordName, this);
+        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);
     }
     
     /**
@@ -222,7 +236,12 @@
             timer = new Timer();
             TimerTask task = new TimerTask() {
                 public void run() {
-                    timerEvent();
+                	try {
+                		timerEvent();
+                	}
+                	catch (IOException ioe) {
+                		ioe.printStackTrace();
+                	}
                 }
             };
             long millis = period * 1000;
@@ -243,7 +262,7 @@
     /**
      * Timer callback.
      */
-    private synchronized void timerEvent() {
+    private synchronized void timerEvent() throws IOException {
         if (isMonitoring) {
             // Run all the registered updates
             // for (Updater updater : updaters) {
@@ -265,18 +284,13 @@
                 String recordName = (String) recordIt.next();
                 RecordMap recordMap = (RecordMap) bufferedData.get(recordName);
                 synchronized (recordMap) {
-                    try {
-                        //for (TagMap tagMap : recordMap.keySet()) {
-                        Iterator tagIt = recordMap.keySet().iterator();
-                        while (tagIt.hasNext()) {
-                            TagMap tagMap = (TagMap) tagIt.next();
-                            MetricMap metricMap = (MetricMap) recordMap.get(tagMap);
-                            OutputRecord outRec = new OutputRecord(tagMap, metricMap);
-                            emitRecord(contextName, recordName, outRec);
-                        }
-                    }
-                    catch (IOException ioe) {
-                        ioe.printStackTrace();
+                    //for (TagMap tagMap : recordMap.keySet()) {
+                    Iterator tagIt = recordMap.keySet().iterator();
+                    while (tagIt.hasNext()) {
+                        TagMap tagMap = (TagMap) tagIt.next();
+                        MetricMap metricMap = (MetricMap) recordMap.get(tagMap);
+                        OutputRecord outRec = new OutputRecord(tagMap, metricMap);
+                        emitRecord(contextName, recordName, outRec);
                     }
                 }
             }
@@ -294,7 +308,7 @@
      * 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() {
+    protected void flush() throws IOException {
     }
     
     /**

Modified: lucene/hadoop/trunk/src/java/org/apache/hadoop/metrics/spi/MetricsRecordImpl.java
URL: http://svn.apache.org/viewcvs/lucene/hadoop/trunk/src/java/org/apache/hadoop/metrics/spi/MetricsRecordImpl.java?rev=405874&r1=405873&r2=405874&view=diff
==============================================================================
--- 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 Fri
May 12 14:12:55 2006
@@ -39,7 +39,7 @@
     
     
     /** Creates a new instance of FileRecord */
-    MetricsRecordImpl(String recordName, AbstractMetricsContext context)
+    protected MetricsRecordImpl(String recordName, AbstractMetricsContext context)
     {
         this.recordName = recordName;
         this.context = context;

Modified: lucene/hadoop/trunk/src/java/org/apache/hadoop/metrics/spi/Util.java
URL: http://svn.apache.org/viewcvs/lucene/hadoop/trunk/src/java/org/apache/hadoop/metrics/spi/Util.java?rev=405874&r1=405873&r2=405874&view=diff
==============================================================================
--- 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 Fri May 12 14:12:55
2006
@@ -20,7 +20,6 @@
 package org.apache.hadoop.metrics.spi;
 
 import java.net.InetSocketAddress;
-import java.net.SocketAddress;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -30,32 +29,35 @@
 public class Util {
     
     /**
-     * Not intended to be instantiated
+     * 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>.  
+     * 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 SocketAddress objects.
+     * @return a list of InetSocketAddress objects.
      */
-    //public static List<SocketAddress> parse(String specs, int defaultPort) {
     public static List parse(String specs, int defaultPort) {
-        String[] specStrings = specs.split("[ ,]+");
-        //List<SocketAddress> result = new ArrayList<SocketAddress>();
-        List result = new ArrayList();
-        
-        //for (String specString : specStrings) {
-        for (int i = 0; i < specStrings.length; i++) {
-            String specString = specStrings[i];
-            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));
+        List result = new ArrayList(1); // ArrayList<InetSocketAddress>
+        if (specs == null) {
+                result.add(new InetSocketAddress("localhost", defaultPort));
+        }
+        else {
+            String[] specStrings = specs.split("[ ,]+");
+            //for (String specString : specStrings) {
+            for (int i = 0; i < specStrings.length; i++) {
+                String specString = specStrings[i];
+                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;



Mime
View raw message