You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nutch.apache.org by cu...@apache.org on 2005/08/26 18:51:27 UTC

svn commit: r240286 - in /lucene/nutch/branches/mapred/src/java/org/apache/nutch/crawl: FetcherOutputFormat.java Indexer.java ParseOutputFormat.java

Author: cutting
Date: Fri Aug 26 09:51:25 2005
New Revision: 240286

URL: http://svn.apache.org/viewcvs?rev=240286&view=rev
Log:
Add reporter to RecordWriter.close().

Modified:
    lucene/nutch/branches/mapred/src/java/org/apache/nutch/crawl/FetcherOutputFormat.java
    lucene/nutch/branches/mapred/src/java/org/apache/nutch/crawl/Indexer.java
    lucene/nutch/branches/mapred/src/java/org/apache/nutch/crawl/ParseOutputFormat.java

Modified: lucene/nutch/branches/mapred/src/java/org/apache/nutch/crawl/FetcherOutputFormat.java
URL: http://svn.apache.org/viewcvs/lucene/nutch/branches/mapred/src/java/org/apache/nutch/crawl/FetcherOutputFormat.java?rev=240286&r1=240285&r2=240286&view=diff
==============================================================================
--- lucene/nutch/branches/mapred/src/java/org/apache/nutch/crawl/FetcherOutputFormat.java (original)
+++ lucene/nutch/branches/mapred/src/java/org/apache/nutch/crawl/FetcherOutputFormat.java Fri Aug 26 09:51:25 2005
@@ -29,6 +29,7 @@
 import org.apache.nutch.mapred.OutputFormat;
 import org.apache.nutch.mapred.RecordWriter;
 import org.apache.nutch.mapred.JobConf;
+import org.apache.nutch.mapred.Reporter;
 
 import org.apache.nutch.protocol.Content;
 
@@ -79,13 +80,13 @@
 
         }
 
-        public void close() throws IOException {
+        public void close(Reporter reporter) throws IOException {
           fetchOut.close();
           if (contentOut != null) {
             contentOut.close();
           }
           if (parseOut != null) {
-            parseOut.close();
+            parseOut.close(reporter);
           }
         }
 

Modified: lucene/nutch/branches/mapred/src/java/org/apache/nutch/crawl/Indexer.java
URL: http://svn.apache.org/viewcvs/lucene/nutch/branches/mapred/src/java/org/apache/nutch/crawl/Indexer.java?rev=240286&r1=240285&r2=240286&view=diff
==============================================================================
--- lucene/nutch/branches/mapred/src/java/org/apache/nutch/crawl/Indexer.java (original)
+++ lucene/nutch/branches/mapred/src/java/org/apache/nutch/crawl/Indexer.java Fri Aug 26 09:51:25 2005
@@ -89,18 +89,37 @@
       writer.setSimilarity(new NutchSimilarity());
 
       return new RecordWriter() {
+          boolean closed;
 
           public void write(WritableComparable key, Writable value)
             throws IOException {                  // unwrap & index doc
             writer.addDocument((Document)((ObjectWritable)value).get());
           }
           
-          public void close() throws IOException {
-            LOG.info("Optimizing index.");        // optimize & close index
-            writer.optimize();
-            writer.close();
-            fs.completeLocalOutput(perm, temp);   // copy to ndfs
-            fs.createNewFile(new File(perm, IndexSegment.DONE_NAME));
+          public void close(final Reporter reporter) throws IOException {
+            // spawn a thread to give progress heartbeats
+            Thread prog = new Thread() {
+                public void run() {
+                  while (!closed) {
+                    try {
+                      reporter.setStatus("closing");
+                      Thread.sleep(1000);
+                    } catch (InterruptedException e) { continue; }
+                      catch (Throwable e) { return; }
+                  }
+                }
+              };
+
+            try {
+              prog.start();
+              LOG.info("Optimizing index.");        // optimize & close index
+              writer.optimize();
+              writer.close();
+              fs.completeLocalOutput(perm, temp);   // copy to ndfs
+              fs.createNewFile(new File(perm, IndexSegment.DONE_NAME));
+            } finally {
+              closed = true;
+            }
           }
         };
     }

Modified: lucene/nutch/branches/mapred/src/java/org/apache/nutch/crawl/ParseOutputFormat.java
URL: http://svn.apache.org/viewcvs/lucene/nutch/branches/mapred/src/java/org/apache/nutch/crawl/ParseOutputFormat.java?rev=240286&r1=240285&r2=240286&view=diff
==============================================================================
--- lucene/nutch/branches/mapred/src/java/org/apache/nutch/crawl/ParseOutputFormat.java (original)
+++ lucene/nutch/branches/mapred/src/java/org/apache/nutch/crawl/ParseOutputFormat.java Fri Aug 26 09:51:25 2005
@@ -79,7 +79,7 @@
           }
         }
         
-        public void close() throws IOException {
+        public void close(Reporter reporter) throws IOException {
           textOut.close();
           dataOut.close();
           crawlOut.close();