You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nutch.apache.org by ab...@apache.org on 2006/07/20 00:31:18 UTC
svn commit: r423641 - in
/lucene/nutch/trunk/src/java/org/apache/nutch/crawl: CrawlDatum.java
MapWritable.java
Author: ab
Date: Wed Jul 19 15:31:16 2006
New Revision: 423641
URL: http://svn.apache.org/viewvc?rev=423641&view=rev
Log:
Add a copy constructor to MapWritable, and use it in CrawlDatum.set
to ensure a deep copy of metaData (NUTCH-323).
Modified:
lucene/nutch/trunk/src/java/org/apache/nutch/crawl/CrawlDatum.java
lucene/nutch/trunk/src/java/org/apache/nutch/crawl/MapWritable.java
Modified: lucene/nutch/trunk/src/java/org/apache/nutch/crawl/CrawlDatum.java
URL: http://svn.apache.org/viewvc/lucene/nutch/trunk/src/java/org/apache/nutch/crawl/CrawlDatum.java?rev=423641&r1=423640&r2=423641&view=diff
==============================================================================
--- lucene/nutch/trunk/src/java/org/apache/nutch/crawl/CrawlDatum.java (original)
+++ lucene/nutch/trunk/src/java/org/apache/nutch/crawl/CrawlDatum.java Wed Jul 19 15:31:16 2006
@@ -210,7 +210,7 @@
this.score = that.score;
this.modifiedTime = that.modifiedTime;
this.signature = that.signature;
- this.metaData = that.metaData;
+ this.metaData = new MapWritable(that.metaData); // make a deep copy
}
Modified: lucene/nutch/trunk/src/java/org/apache/nutch/crawl/MapWritable.java
URL: http://svn.apache.org/viewvc/lucene/nutch/trunk/src/java/org/apache/nutch/crawl/MapWritable.java?rev=423641&r1=423640&r2=423641&view=diff
==============================================================================
--- lucene/nutch/trunk/src/java/org/apache/nutch/crawl/MapWritable.java (original)
+++ lucene/nutch/trunk/src/java/org/apache/nutch/crawl/MapWritable.java Wed Jul 19 15:31:16 2006
@@ -31,6 +31,8 @@
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.io.BytesWritable;
+import org.apache.hadoop.io.DataInputBuffer;
+import org.apache.hadoop.io.DataOutputBuffer;
import org.apache.hadoop.io.FloatWritable;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
@@ -39,6 +41,7 @@
import org.apache.hadoop.io.ObjectWritable;
import org.apache.hadoop.io.UTF8;
import org.apache.hadoop.io.Writable;
+import org.apache.hadoop.util.StringUtils;
/**
* A writable map, with a similar behavior as <code>java.util.HashMap</code>.
@@ -96,6 +99,29 @@
private static void addToMap(Class clazz, Byte byteId) {
CLASS_ID_MAP.put(clazz, byteId);
ID_CLASS_MAP.put(byteId, clazz);
+ }
+
+ public MapWritable() { }
+
+ /**
+ * Copy constructor. This constructor makes a deep copy, using serialization /
+ * deserialization to break any possible references to contained objects.
+ *
+ * @param map map to copy from
+ */
+ public MapWritable(MapWritable map) {
+ if (map != null) {
+ try {
+ DataOutputBuffer dob = new DataOutputBuffer();
+ map.write(dob);
+ DataInputBuffer dib = new DataInputBuffer();
+ dib.reset(dob.getData(), dob.getLength());
+ readFields(dib);
+ } catch (IOException e) {
+ throw new IllegalArgumentException("this map cannot be copied: " +
+ StringUtils.stringifyException(e));
+ }
+ }
}
public void clear() {