Apache Nutch is an extensible and scalable web crawler
removed old Nutch classes, mostly Writables
Julien Nioche9714c446cf88
diff --git a/src/java/org/apache/nutch/crawl/CrawlDatum.java b/src/java/org/apache/nutch/crawl/CrawlDatum.javadeleted file mode 100644index 64413df5a..000000000--- a/src/java/org/apache/nutch/crawl/CrawlDatum.java+++ /dev/null@@ -1,461 +0,0 @@-/**- * Licensed to the Apache Software Foundation (ASF) under one or more- * contributor license agreements. See the NOTICE file distributed with- * this work for additional information regarding copyright ownership.- * The ASF licenses this file to You under the Apache License, Version 2.0- * (the "License"); you may not use this file except in compliance with- * the License. You may obtain a copy of the License at- *- * http://www.apache.org/licenses/LICENSE-2.0- *- * Unless required by applicable law or agreed to in writing, software- * distributed under the License is distributed on an "AS IS" BASIS,- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.- * See the License for the specific language governing permissions and- * limitations under the License.- */--package org.apache.nutch.crawl;--import java.io.*;-import java.util.*;-import java.util.Map.Entry;--import org.apache.hadoop.io.*;-import org.apache.nutch.util.*;--/* The crawl state of a url. */-public class CrawlDatum implements WritableComparable<CrawlDatum>, Cloneable {- public static final String GENERATE_DIR_NAME = "crawl_generate";- public static final String FETCH_DIR_NAME = "crawl_fetch";- public static final String PARSE_DIR_NAME = "crawl_parse";-- private final static byte CUR_VERSION = 7;-- /** Compatibility values for on-the-fly conversion from versions < 5. */- private static final byte OLD_STATUS_SIGNATURE = 0;- private static final byte OLD_STATUS_DB_UNFETCHED = 1;- private static final byte OLD_STATUS_DB_FETCHED = 2;- private static final byte OLD_STATUS_DB_GONE = 3;- private static final byte OLD_STATUS_LINKED = 4;- private static final byte OLD_STATUS_FETCH_SUCCESS = 5;- private static final byte OLD_STATUS_FETCH_RETRY = 6;- private static final byte OLD_STATUS_FETCH_GONE = 7;-- private static HashMap<Byte, Byte> oldToNew = new HashMap<Byte, Byte>();-- /** Page was not fetched yet. */- public static final byte STATUS_DB_UNFETCHED = 0x01;- /** Page was successfully fetched. */- public static final byte STATUS_DB_FETCHED = 0x02;- /** Page no longer exists. */- public static final byte STATUS_DB_GONE = 0x03;- /** Page temporarily redirects to other page. */- public static final byte STATUS_DB_REDIR_TEMP = 0x04;- /** Page permanently redirects to other page. */- public static final byte STATUS_DB_REDIR_PERM = 0x05;- /** Page was successfully fetched and found not modified. */- public static final byte STATUS_DB_NOTMODIFIED = 0x06;-- /** Maximum value of DB-related status. */- public static final byte STATUS_DB_MAX = 0x1f;-- /** Fetching was successful. */- public static final byte STATUS_FETCH_SUCCESS = 0x21;- /** Fetching unsuccessful, needs to be retried (transient errors). */- public static final byte STATUS_FETCH_RETRY = 0x22;- /** Fetching temporarily redirected to other page. */- public static final byte STATUS_FETCH_REDIR_TEMP = 0x23;- /** Fetching permanently redirected to other page. */- public static final byte STATUS_FETCH_REDIR_PERM = 0x24;- /** Fetching unsuccessful - page is gone. */- public static final byte STATUS_FETCH_GONE = 0x25;- /** Fetching successful - page is not modified. */- public static final byte STATUS_FETCH_NOTMODIFIED = 0x26;-- /** Maximum value of fetch-related status. */- public static final byte STATUS_FETCH_MAX = 0x3f;-- /** Page signature. */- public static final byte STATUS_SIGNATURE = 0x41;- /** Page was newly injected. */- public static final byte STATUS_INJECTED = 0x42;- /** Page discovered through a link. */- public static final byte STATUS_LINKED = 0x43;--- public static final HashMap<Byte, String> statNames = new HashMap<Byte, String>();- static {- statNames.put(STATUS_DB_UNFETCHED, "db_unfetched");- statNames.put(STATUS_DB_FETCHED, "db_fetched");- statNames.put(STATUS_DB_GONE, "db_gone");- statNames.put(STATUS_DB_REDIR_TEMP, "db_redir_temp");- statNames.put(STATUS_DB_REDIR_PERM, "db_redir_perm");- statNames.put(STATUS_DB_NOTMODIFIED, "db_notmodified");- statNames.put(STATUS_SIGNATURE, "signature");- statNames.put(STATUS_INJECTED, "injected");- statNames.put(STATUS_LINKED, "linked");- statNames.put(STATUS_FETCH_SUCCESS, "fetch_success");- statNames.put(STATUS_FETCH_RETRY, "fetch_retry");- statNames.put(STATUS_FETCH_REDIR_TEMP, "fetch_redir_temp");- statNames.put(STATUS_FETCH_REDIR_PERM, "fetch_redir_perm");- statNames.put(STATUS_FETCH_GONE, "fetch_gone");- statNames.put(STATUS_FETCH_NOTMODIFIED, "fetch_notmodified");-- oldToNew.put(OLD_STATUS_DB_UNFETCHED, STATUS_DB_UNFETCHED);- oldToNew.put(OLD_STATUS_DB_FETCHED, STATUS_DB_FETCHED);- oldToNew.put(OLD_STATUS_DB_GONE, STATUS_DB_GONE);- oldToNew.put(OLD_STATUS_FETCH_GONE, STATUS_FETCH_GONE);- oldToNew.put(OLD_STATUS_FETCH_SUCCESS, STATUS_FETCH_SUCCESS);- oldToNew.put(OLD_STATUS_FETCH_RETRY, STATUS_FETCH_RETRY);- oldToNew.put(OLD_STATUS_LINKED, STATUS_LINKED);- oldToNew.put(OLD_STATUS_SIGNATURE, STATUS_SIGNATURE);- }-- private byte status;- private long fetchTime = System.currentTimeMillis();- private byte retries;- private int fetchInterval;- private float score = 1.0f;- private byte[] signature = null;- private long modifiedTime;- private org.apache.hadoop.io.MapWritable metaData;-- public static boolean hasDbStatus(CrawlDatum datum) {- if (datum.status <= STATUS_DB_MAX) return true;- return false;- }-- public static boolean hasFetchStatus(CrawlDatum datum) {- if (datum.status > STATUS_DB_MAX && datum.status <= STATUS_FETCH_MAX) return true;- return false;- }-- public CrawlDatum() {- metaData = new org.apache.hadoop.io.MapWritable();- }-- public CrawlDatum(int status, int fetchInterval) {- this();- this.status = (byte)status;- this.fetchInterval = fetchInterval;- }-- public CrawlDatum(int status, int fetchInterval, float score) {- this(status, fetchInterval);- this.score = score;- }-- //- // accessor methods- //-- public byte getStatus() { return status; }-- public static String getStatusName(byte value) {- String res = statNames.get(value);- if (res == null) res = "unknown";- return res;- }-- public void setStatus(int status) { this.status = (byte)status; }-- /**- * Returns either the time of the last fetch, or the next fetch time,- * depending on whether Fetcher or CrawlDbReducer set the time.- */- public long getFetchTime() { return fetchTime; }- /**- * Sets either the time of the last fetch or the next fetch time,- * depending on whether Fetcher or CrawlDbReducer set the time.- */- public void setFetchTime(long fetchTime) { this.fetchTime = fetchTime; }-- public long getModifiedTime() {- return modifiedTime;- }-- public void setModifiedTime(long modifiedTime) {- this.modifiedTime = modifiedTime;- }-- public byte getRetriesSinceFetch() { return retries; }- public void setRetriesSinceFetch(int retries) {this.retries = (byte)retries;}-- public int getFetchInterval() { return fetchInterval; }- public void setFetchInterval(int fetchInterval) {- this.fetchInterval = fetchInterval;- }- public void setFetchInterval(float fetchInterval) {- this.fetchInterval = Math.round(fetchInterval);- }-- public float getScore() { return score; }- public void setScore(float score) { this.score = score; }-- public byte[] getSignature() {- return signature;- }-- public void setSignature(byte[] signature) {- if (signature != null && signature.length > 256)- throw new RuntimeException("Max signature length (256) exceeded: " + signature.length);- this.signature = signature;- }-- public void setMetaData(org.apache.hadoop.io.MapWritable mapWritable) {- this.metaData = new org.apache.hadoop.io.MapWritable(mapWritable);- }-- /** Add all metadata from other CrawlDatum to this CrawlDatum.- *- * @param other CrawlDatum- */- public void putAllMetaData(CrawlDatum other) {- for (Entry<Writable, Writable> e : other.getMetaData().entrySet()) {- metaData.put(e.getKey(), e.getValue());- }- }-- /**- * returns a MapWritable if it was set or read in @see readFields(DataInput),- * returns empty map in case CrawlDatum was freshly created (lazily instantiated).- */- public org.apache.hadoop.io.MapWritable getMetaData() {- if (this.metaData == null) this.metaData = new org.apache.hadoop.io.MapWritable();- return this.metaData;- }--- //- // writable methods- //-- public static CrawlDatum read(DataInput in) throws IOException {- CrawlDatum result = new CrawlDatum();- result.readFields(in);- return result;- }-- public void readFields(DataInput in) throws IOException {- byte version = in.readByte(); // read version- if (version > CUR_VERSION) // check version- throw new VersionMismatchException(CUR_VERSION, version);-- status = in.readByte();- fetchTime = in.readLong();- retries = in.readByte();- if (version > 5) {- fetchInterval = in.readInt();- } else fetchInterval = Math.round(in.readFloat());- score = in.readFloat();- if (version > 2) {- modifiedTime = in.readLong();- int cnt = in.readByte();- if (cnt > 0) {- signature = new byte[cnt];- in.readFully(signature);- } else signature = null;- }- metaData = new org.apache.hadoop.io.MapWritable();- if (version > 3) {- if (version < 7) {- MapWritable oldMetaData = new MapWritable();- if (in.readBoolean()) {- oldMetaData.readFields(in);- }- for (Writable key : oldMetaData.keySet()) {- metaData.put(key, oldMetaData.get(key));- }- } else {- if (in.readBoolean()) {- metaData.readFields(in);- }- }- }- // translate status codes- if (version < 5) {- if (oldToNew.containsKey(status))- status = oldToNew.get(status);- else- status = STATUS_DB_UNFETCHED;-- }- }-- /** The number of bytes into a CrawlDatum that the score is stored. */- private static final int SCORE_OFFSET = 1 + 1 + 8 + 1 + 4;- private static final int SIG_OFFSET = SCORE_OFFSET + 4 + 8;-- public void write(DataOutput out) throws IOException {- out.writeByte(CUR_VERSION); // store current version- out.writeByte(status);- out.writeLong(fetchTime);- out.writeByte(retries);- out.writeInt(fetchInterval);- out.writeFloat(score);- out.writeLong(modifiedTime);- if (signature == null) {- out.writeByte(0);- } else {- out.writeByte(signature.length);- out.write(signature);- }- if (metaData.size() > 0) {- out.writeBoolean(true);- metaData.write(out);- } else {- out.writeBoolean(false);- }- }-- /** Copy the contents of another instance into this instance. */- public void set(CrawlDatum that) {- this.status = that.status;- this.fetchTime = that.fetchTime;- this.retries = that.retries;- this.fetchInterval = that.fetchInterval;- this.score = that.score;- this.modifiedTime = that.modifiedTime;- this.signature = that.signature;- this.metaData = new org.apache.hadoop.io.MapWritable(that.metaData); // make a deep copy- }--- //- // compare methods- //-- /** Sort by decreasing score. */- public int compareTo(CrawlDatum that) {- if (that.score != this.score)- return (that.score - this.score) > 0 ? 1 : -1;- if (that.status != this.status)- return this.status - that.status;- if (that.fetchTime != this.fetchTime)- return (that.fetchTime - this.fetchTime) > 0 ? 1 : -1;- if (that.retries != this.retries)- return that.retries - this.retries;- if (that.fetchInterval != this.fetchInterval)- return (that.fetchInterval - this.fetchInterval) > 0 ? 1 : -1;- if (that.modifiedTime != this.modifiedTime)- return (that.modifiedTime - this.modifiedTime) > 0 ? 1 : -1;- return SignatureComparator.compare(this.signature, that.signature);- }-- /** A Comparator optimized for CrawlDatum. */- public static class Comparator extends WritableComparator {- public Comparator() { super(CrawlDatum.class); }-- public int compare(byte[] b1, int s1, int l1, byte[] b2, int s2, int l2) {- float score1 = readFloat(b1,s1+SCORE_OFFSET);- float score2 = readFloat(b2,s2+SCORE_OFFSET);- if (score2 != score1) {- return (score2 - score1) > 0 ? 1 : -1;- }- int status1 = b1[s1+1];- int status2 = b2[s2+1];- if (status2 != status1)- return status1 - status2;- long fetchTime1 = readLong(b1, s1+1+1);- long fetchTime2 = readLong(b2, s2+1+1);- if (fetchTime2 != fetchTime1)- return (fetchTime2 - fetchTime1) > 0 ? 1 : -1;- int retries1 = b1[s1+1+1+8];- int retries2 = b2[s2+1+1+8];- if (retries2 != retries1)- return retries2 - retries1;- int fetchInterval1 = readInt(b1, s1+1+1+8+1);- int fetchInterval2 = readInt(b2, s2+1+1+8+1);- if (fetchInterval2 != fetchInterval1)- return (fetchInterval2 - fetchInterval1) > 0 ? 1 : -1;- long modifiedTime1 = readLong(b1, s1 + SCORE_OFFSET + 4);- long modifiedTime2 = readLong(b2, s2 + SCORE_OFFSET + 4);- if (modifiedTime2 != modifiedTime1)- return (modifiedTime2 - modifiedTime1) > 0 ? 1 : -1;- int sigl1 = b1[s1+SIG_OFFSET];- int sigl2 = b2[s2+SIG_OFFSET];- return SignatureComparator._compare(b1, SIG_OFFSET, sigl1, b2, SIG_OFFSET, sigl2);- }- }-- static { // register this comparator- WritableComparator.define(CrawlDatum.class, new Comparator());- }--- //- // basic methods- //-- public String toString() {- StringBuilder buf = new StringBuilder();- buf.append("Version: " + CUR_VERSION + "\n");- buf.append("Status: " + getStatus() + " (" + getStatusName(getStatus()) + ")\n");- buf.append("Fetch time: " + new Date(getFetchTime()) + "\n");- buf.append("Modified time: " + new Date(getModifiedTime()) + "\n");- buf.append("Retries since fetch: " + getRetriesSinceFetch() + "\n");- buf.append("Retry interval: " + getFetchInterval() + " seconds (" +- (getFetchInterval() / FetchSchedule.SECONDS_PER_DAY) + " days)\n");- buf.append("Score: " + getScore() + "\n");- buf.append("Signature: " + StringUtil.toHexString(getSignature()) + "\n");- buf.append("Metadata: ");- for (Entry<Writable, Writable> e : metaData.entrySet()) {- buf.append(e.getKey());- buf.append(": ");- buf.append(e.getValue());- }- buf.append('\n');- return buf.toString();- }-- private boolean metadataEquals(org.apache.hadoop.io.MapWritable otherMetaData) {- HashSet<Entry<Writable, Writable>> set1 =- new HashSet<Entry<Writable,Writable>>(metaData.entrySet());- HashSet<Entry<Writable, Writable>> set2 =- new HashSet<Entry<Writable,Writable>>(otherMetaData.entrySet());- return set1.equals(set2);- }-- public boolean equals(Object o) {- if (!(o instanceof CrawlDatum))- return false;- CrawlDatum other = (CrawlDatum)o;- boolean res =- (this.status == other.status) &&- (this.fetchTime == other.fetchTime) &&- (this.modifiedTime == other.modifiedTime) &&- (this.retries == other.retries) &&- (this.fetchInterval == other.fetchInterval) &&- (SignatureComparator.compare(this.signature, other.signature) == 0) &&- (this.score == other.score);- if (!res) return res;- return metadataEquals(other.metaData);- }-- public int hashCode() {- int res = 0;- if (signature != null) {- for (int i = 0; i < signature.length / 4; i += 4) {- res ^= (int)(signature[i] << 24 + signature[i+1] << 16 +- signature[i+2] << 8 + signature[i+3]);- }- }- res ^= metaData.entrySet().hashCode();- return- res ^ status ^- ((int)fetchTime) ^- ((int)modifiedTime) ^- retries ^- fetchInterval ^- Float.floatToIntBits(score);- }-- public Object clone() {- try {- return super.clone();- } catch (CloneNotSupportedException e) {- throw new RuntimeException(e);- }- }-}diff --git a/src/java/org/apache/nutch/crawl/CrawlDb.java b/src/java/org/apache/nutch/crawl/CrawlDb.javadeleted file mode 100644index fe430f7b8..000000000--- a/src/java/org/apache/nutch/crawl/CrawlDb.java+++ /dev/null@@ -1,26 +0,0 @@-/**- * Licensed to the Apache Software Foundation (ASF) under one or more- * contributor license agreements. See the NOTICE file distributed with- * this work for additional information regarding copyright ownership.- * The ASF licenses this file to You under the Apache License, Version 2.0- * (the "License"); you may not use this file except in compliance with- * the License. You may obtain a copy of the License at- *- * http://www.apache.org/licenses/LICENSE-2.0- *- * Unless required by applicable law or agreed to in writing, software- * distributed under the License is distributed on an "AS IS" BASIS,- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.- * See the License for the specific language governing permissions and- * limitations under the License.- */--package org.apache.nutch.crawl;--public interface CrawlDb {- public static final String CRAWLDB_ADDITIONS_ALLOWED = "db.update.additions.allowed";-- public static final String CURRENT_NAME = "current";-- public static final String LOCK_NAME = ".locked";-}diff --git a/src/java/org/apache/nutch/crawl/DbUpdateReducer.java b/src/java/org/apache/nutch/crawl/DbUpdateReducer.javaindex 8bdf644b9..3ebf22746 100644--- a/src/java/org/apache/nutch/crawl/DbUpdateReducer.java+++ b/src/java/org/apache/nutch/crawl/DbUpdateReducer.java@@ -23,6 +23,8 @@ import org.gora.mapreduce.GoraReducer;public class DbUpdateReducerextends GoraReducer<String, NutchWritable, String, WebPage> {+ public static final String CRAWLDB_ADDITIONS_ALLOWED = "db.update.additions.allowed";+public static final Log LOG = DbUpdaterJob.LOG;private int retryMax;@@ -36,7 +38,7 @@ extends GoraReducer<String, NutchWritable, String, WebPage> {protected void setup(Context context) throws IOException, InterruptedException {Configuration conf = context.getConfiguration();retryMax = conf.getInt("db.fetch.retry.max", 3);- additionsAllowed = conf.getBoolean(CrawlDb.CRAWLDB_ADDITIONS_ALLOWED, true);+ additionsAllowed = conf.getBoolean(CRAWLDB_ADDITIONS_ALLOWED, true);maxInterval = conf.getInt("db.fetch.interval.max", 0 );schedule = FetchScheduleFactory.getFetchSchedule(conf);scoringFilters = new ScoringFilters(conf);diff --git a/src/java/org/apache/nutch/crawl/MapWritable.java b/src/java/org/apache/nutch/crawl/MapWritable.javadeleted file mode 100644index dd2c80c0b..000000000--- a/src/java/org/apache/nutch/crawl/MapWritable.java+++ /dev/null@@ -1,517 +0,0 @@-/**- * Licensed to the Apache Software Foundation (ASF) under one or more- * contributor license agreements. See the NOTICE file distributed with- * this work for additional information regarding copyright ownership.- * The ASF licenses this file to You under the Apache License, Version 2.0- * (the "License"); you may not use this file except in compliance with- * the License. You may obtain a copy of the License at- *- * http://www.apache.org/licenses/LICENSE-2.0- *- * Unless required by applicable law or agreed to in writing, software- * distributed under the License is distributed on an "AS IS" BASIS,- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.- * See the License for the specific language governing permissions and- * limitations under the License.- */--package org.apache.nutch.crawl;--import java.io.DataInput;-import java.io.DataOutput;-import java.io.IOException;-import java.util.Collection;-import java.util.HashMap;-import java.util.HashSet;-import java.util.Iterator;-import java.util.LinkedList;-import java.util.Map;-import java.util.Set;--// Commons Logging imports-import org.apache.commons.logging.Log;-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;-import org.apache.hadoop.io.MD5Hash;-import org.apache.hadoop.io.NullWritable;-import org.apache.hadoop.io.ObjectWritable;-import org.apache.hadoop.io.Text;-import org.apache.hadoop.io.Writable;-import org.apache.hadoop.util.StringUtils;-import org.apache.nutch.protocol.ProtocolStatus;--/**- * A writable map, with a similar behavior as <code>java.util.HashMap</code>.- * In addition to the size of key and value writable tuple two additional bytes- * are stored to identify the Writable classes. This means that a maximum of- * 255 different class types can be used for key and value objects.- * A binary-id to class mapping is defined in a static block of this class.- * However it is possible to use custom implementations of Writable.- * For these custom Writables we write the byte id - utf class name tuple- * into the header of each MapWritable that uses these types.- *- * @author Stefan Groschupf- * @deprecated Use org.apache.hadoop.io.MapWritable instead.- */-public class MapWritable implements Writable {-- public static final Log LOG = LogFactory.getLog(MapWritable.class);-- private KeyValueEntry fFirst;-- private KeyValueEntry fLast;-- private KeyValueEntry fOld;-- private int fSize = 0;-- private int fIdCount = 0;-- private ClassIdEntry fIdLast;-- private ClassIdEntry fIdFirst;-- private static Map<Class, Byte> CLASS_ID_MAP = new HashMap<Class, Byte>();-- private static Map<Byte, Class> ID_CLASS_MAP = new HashMap<Byte, Class>();-- static {-- addToMap(NullWritable.class, new Byte((byte) -127));- addToMap(LongWritable.class, new Byte((byte) -126));- addToMap(Text.class, new Byte((byte) -125));- addToMap(MD5Hash.class, new Byte((byte) -124));- addToMap(org.apache.nutch.fetcher.FetcherOutput.class,- new Byte((byte) -123));- addToMap(org.apache.nutch.protocol.Content.class, new Byte((byte) -122));- addToMap(org.apache.nutch.parse.ParseText.class, new Byte((byte) -121));- addToMap(org.apache.nutch.parse.ParseData.class, new Byte((byte) -120));- addToMap(MapWritable.class, new Byte((byte) -119));- addToMap(BytesWritable.class, new Byte((byte) -118));- addToMap(FloatWritable.class, new Byte((byte) -117));- addToMap(IntWritable.class, new Byte((byte) -116));- addToMap(ObjectWritable.class, new Byte((byte) -115));- addToMap(ProtocolStatus.class, new Byte((byte) -114));-- }-- 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() {- fOld = fFirst;- fFirst = fLast = null;- fSize = 0;- }-- public boolean containsKey(Writable key) {- return findEntryByKey(key) != null;- }-- public boolean containsValue(Writable value) {- KeyValueEntry entry = fFirst;- while (entry != null) {- if (entry.fValue.equals(value)) {- return true;- }- entry = entry.fNextEntry;- }- return false;- }-- public Writable get(Writable key) {- KeyValueEntry entry = findEntryByKey(key);- if (entry != null) {- return entry.fValue;- }- return null;- }-- public int hashCode() {- final int seed = 23;- int hash = 0;- KeyValueEntry entry = fFirst;- while (entry != null) {- hash += entry.fKey.hashCode() * seed;- hash += entry.fValue.hashCode() * seed;- entry = entry.fNextEntry;- }- return hash;-- }-- public boolean isEmpty() {- return fFirst == null;- }-- public Set<Writable> keySet() {- HashSet<Writable> set = new HashSet<Writable>();- if (isEmpty()) return set;- set.add(fFirst.fKey);- KeyValueEntry entry = fFirst;- while ((entry = entry.fNextEntry) != null) {- set.add(entry.fKey);- }- return set;- }-- public Writable put(Writable key, Writable value) {- KeyValueEntry entry = findEntryByKey(key);- if (entry != null) {- Writable oldValue = entry.fValue;- entry.fValue = value;- return oldValue;- }- KeyValueEntry newEntry = new KeyValueEntry(key, value);- fSize++;- if (fLast != null) {- fLast = fLast.fNextEntry = newEntry;- return null;- }- fLast = fFirst = newEntry;- return null;-- }-- public void putAll(MapWritable map) {- if (map == null || map.size() == 0) {- return;- }- Iterator<Writable> iterator = map.keySet().iterator();- while (iterator.hasNext()) {- Writable key = iterator.next();- Writable value = map.get(key);- put(key, value);- }- }-- public Writable remove(Writable key) {- Writable oldValue = null;- KeyValueEntry entry = fFirst;- KeyValueEntry predecessor = null;- while (entry != null) {- if (entry.fKey.equals(key)) {- oldValue = entry.fValue;- if (predecessor == null) {- fFirst = fFirst.fNextEntry;- } else {- predecessor.fNextEntry = entry.fNextEntry;- }- if (fLast.equals(entry)) {- fLast = predecessor;- }- fSize--;- return oldValue;- }- predecessor = entry;- entry = entry.fNextEntry;- }- return oldValue;- }-- public int size() {- return fSize;- }-- public Collection<Writable> values() {- LinkedList<Writable> list = new LinkedList<Writable>();- KeyValueEntry entry = fFirst;- while (entry != null) {- list.add(entry.fValue);- entry = entry.fNextEntry;- }- return list;- }-- public boolean equals(Object obj) {- if (obj instanceof MapWritable) {- MapWritable map = (MapWritable) obj;- if (fSize != map.fSize) return false;- HashSet<KeyValueEntry> set1 = new HashSet<KeyValueEntry>();- KeyValueEntry e1 = fFirst;- while (e1 != null) {- set1.add(e1);- e1 = e1.fNextEntry;- }- HashSet<KeyValueEntry> set2 = new HashSet<KeyValueEntry>();- KeyValueEntry e2 = map.fFirst;- while (e2 != null) {- set2.add(e2);- e2 = e2.fNextEntry;- }- return set1.equals(set2);- }- return false;- }-- public String toString() {- if (fFirst != null) {- StringBuffer buffer = new StringBuffer();- KeyValueEntry entry = fFirst;- while (entry != null) {- buffer.append(entry.toString());- buffer.append(" ");- entry = entry.fNextEntry;- }- return buffer.toString();- }- return null;- }-- private KeyValueEntry findEntryByKey(final Writable key) {- KeyValueEntry entry = fFirst;- while (entry != null && !entry.fKey.equals(key)) {- entry = entry.fNextEntry;- }- return entry;- }-- // serialization methods-- public void write(DataOutput out) throws IOException {- out.writeInt(size());-- if (size() > 0) {- // scan for unknown classes;- createInternalIdClassEntries();- // write internal map- out.writeByte(fIdCount);- if (fIdCount > 0) {- ClassIdEntry entry = fIdFirst;- while (entry != null) {- out.writeByte(entry.fId);- Text.writeString(out, entry.fclazz.getName());- entry = entry.fNextIdEntry;- }- }- // write meta data- KeyValueEntry entry = fFirst;- while (entry != null) {- out.writeByte(entry.fKeyClassId);- out.writeByte(entry.fValueClassId);-- entry.fKey.write(out);- entry.fValue.write(out);-- entry = entry.fNextEntry;- }-- }-- }-- public void readFields(DataInput in) throws IOException {- clear();- fSize = in.readInt();- if (fSize > 0) {- // read class-id map- fIdCount = in.readByte();- byte id;- Class clazz;- for (int i = 0; i < fIdCount; i++) {- try {- id = in.readByte();- clazz = Class.forName(Text.readString(in));- addIdEntry(id, clazz);- } catch (Exception e) {- if (LOG.isWarnEnabled()) {- LOG.warn("Unable to load internal map entry" + e.toString());- }- fIdCount--;- }- }- KeyValueEntry entry;- for (int i = 0; i < fSize; i++) {- try {- entry = getKeyValueEntry(in.readByte(), in.readByte());- entry.fKey.readFields(in);- entry.fValue.readFields(in);- if (fFirst == null) {- fFirst = fLast = entry;- } else {- fLast = fLast.fNextEntry = entry;- }- } catch (IOException e) {- if (LOG.isWarnEnabled()) {- LOG.warn("Unable to load meta data entry, ignoring.. : " +- e.toString());- }- fSize--;- }- }- }- }-- private void createInternalIdClassEntries() {- KeyValueEntry entry = fFirst;- byte id;- while (entry != null) {- id = getClassId(entry.fKey.getClass());- if (id == -128) {- id = addIdEntry((byte) (-128 + CLASS_ID_MAP.size() + ++fIdCount),- entry.fKey.getClass());- }- entry.fKeyClassId = id;- id = getClassId(entry.fValue.getClass());- if (id == -128) {- id = addIdEntry((byte) (-128 + CLASS_ID_MAP.size() + ++fIdCount),- entry.fValue.getClass());- }- entry.fValueClassId = id;- entry = entry.fNextEntry;- }- }-- private byte addIdEntry(byte id, Class clazz) {- if (fIdFirst == null) {- fIdFirst = fIdLast = new ClassIdEntry(id, clazz);- } else {- fIdLast.fNextIdEntry = fIdLast = new ClassIdEntry(id, clazz);- }- return id;- }-- private byte getClassId(Class clazz) {- Byte classId = CLASS_ID_MAP.get(clazz);- if (classId != null) {- return classId.byteValue();- }- ClassIdEntry entry = fIdFirst;- while (entry != null) {- if (entry.fclazz.equals(clazz)) {- return entry.fId;- }- entry = entry.fNextIdEntry;- }- return -128;- }-- private KeyValueEntry getKeyValueEntry(final byte keyId, final byte valueId)- throws IOException {- KeyValueEntry entry = fOld;- KeyValueEntry last = null;- byte entryKeyId;- byte entryValueId;- while (entry != null) {- entryKeyId = getClassId(entry.fKey.getClass());- entryValueId = getClassId(entry.fValue.getClass());- if (entryKeyId == keyId && entryValueId == valueId) {- if (last != null) {- last.fNextEntry = entry.fNextEntry;- } else {- fOld = entry.fNextEntry;- }- entry.fNextEntry = null; // reset next entry- return entry;- }- last = entry;- entry = entry.fNextEntry;- }- Class keyClass = getClass(keyId);- Class valueClass = getClass(valueId);- try {- return new KeyValueEntry((Writable) keyClass.newInstance(),- (Writable) valueClass.newInstance());- } catch (Exception e) {- throw new IOException("unable to instantiate class: " + e.toString());- }-- }-- private Class getClass(final byte id) throws IOException {- Class clazz = ID_CLASS_MAP.get(new Byte(id));- if (clazz == null) {- ClassIdEntry entry = fIdFirst;- while (entry != null) {- if (entry.fId == id) {- return entry.fclazz;- }-- entry = entry.fNextIdEntry;- }- } else {- return clazz;- }- throw new IOException("unable to load class for id: " + id);- }-- /** an entry holds writable key and value */- private class KeyValueEntry {- private byte fKeyClassId;-- private byte fValueClassId;-- private Writable fKey;-- private Writable fValue;-- private KeyValueEntry fNextEntry;-- public KeyValueEntry(Writable key, Writable value) {- this.fKey = key;- this.fValue = value;- }-- public String toString() {- return fKey.toString() + ":" + fValue.toString();- }-- public boolean equals(Object obj) {- if (obj instanceof KeyValueEntry) {- KeyValueEntry entry = (KeyValueEntry) obj;- return entry.fKey.equals(fKey) && entry.fValue.equals(fValue);- }- return false;- }-- public int hashCode() {- return toString().hashCode();- }- }-- /** container for Id class tuples */- private class ClassIdEntry {- public ClassIdEntry(byte id, Class clazz) {- fId = id;- fclazz = clazz;- }-- private byte fId;-- private Class fclazz;-- private ClassIdEntry fNextIdEntry;- }--}diff --git a/src/java/org/apache/nutch/crawl/NutchWritable.java b/src/java/org/apache/nutch/crawl/NutchWritable.javaindex bab8bdf30..3e3a85b49 100644--- a/src/java/org/apache/nutch/crawl/NutchWritable.java+++ b/src/java/org/apache/nutch/crawl/NutchWritable.java@@ -25,30 +25,8 @@ public class NutchWritable extends GenericWritableConfigurable {static {CLASSES = new Class[] {- org.apache.hadoop.io.NullWritable.class,- org.apache.hadoop.io.LongWritable.class,- org.apache.hadoop.io.BytesWritable.class,- org.apache.hadoop.io.FloatWritable.class,- org.apache.hadoop.io.IntWritable.class,- org.apache.hadoop.io.Text.class,- org.apache.hadoop.io.MD5Hash.class,- org.apache.nutch.crawl.CrawlDatum.class,- org.apache.nutch.crawl.Inlink.class,- org.apache.nutch.crawl.Inlinks.class,- org.apache.nutch.crawl.MapWritable.class,- org.apache.nutch.fetcher.FetcherOutput.class,- org.apache.nutch.metadata.Metadata.class,- org.apache.nutch.parse.Outlink.class,- org.apache.nutch.parse.ParseText.class,- org.apache.nutch.parse.ParseData.class,- org.apache.nutch.parse.ParseStatus.class,- org.apache.nutch.protocol.Content.class,- org.apache.nutch.protocol.ProtocolStatus.class,-// org.apache.nutch.searcher.Hit.class,-// org.apache.nutch.searcher.HitDetails.class,-// org.apache.nutch.searcher.Hits.class,org.apache.nutch.scoring.ScoreDatum.class,- org.apache.nutch.util.WebPageWritable.class,+ org.apache.nutch.util.WebPageWritable.class};}diff --git a/src/java/org/apache/nutch/crawl/WebTableReader.java b/src/java/org/apache/nutch/crawl/WebTableReader.javaindex 3371ea5a3..9da8f217f 100644--- a/src/java/org/apache/nutch/crawl/WebTableReader.java+++ b/src/java/org/apache/nutch/crawl/WebTableReader.java@@ -16,7 +16,6 @@ import org.apache.hadoop.conf.Configuration;import org.apache.hadoop.conf.Configured;import org.apache.hadoop.fs.FileSystem;import org.apache.hadoop.fs.Path;-import org.apache.hadoop.hbase.util.Bytes;import org.apache.hadoop.io.LongWritable;import org.apache.hadoop.io.SequenceFile;import org.apache.hadoop.io.Text;@@ -37,6 +36,7 @@ import org.gora.mapreduce.GoraMapper;import org.gora.query.Query;import org.gora.query.Result;import org.gora.store.DataStore;+import org.apache.hadoop.hbase.util.Bytes;/*** Displays information about the entries of the webtable@@ -281,7 +281,7 @@ public class WebTableReader extends Configured implements Tool {LOG.info(" " + st[2] + " :\t" + val);elseLOG.info(st[0] + " " + code + " ("- + CrawlDatum.getStatusName((byte) code) + "):\t" + val);+ + CrawlStatus.getName((byte) code) + "):\t" + val);} elseLOG.info(k + ":\t" + val);}diff --git a/src/java/org/apache/nutch/fetcher/FetcherOutput.java b/src/java/org/apache/nutch/fetcher/FetcherOutput.javadeleted file mode 100644index adafa8f1d..000000000--- a/src/java/org/apache/nutch/fetcher/FetcherOutput.java+++ /dev/null@@ -1,32 +0,0 @@-/**- * Licensed to the Apache Software Foundation (ASF) under one or more- * contributor license agreements. See the NOTICE file distributed with- * this work for additional information regarding copyright ownership.- * The ASF licenses this file to You under the Apache License, Version 2.0- * (the "License"); you may not use this file except in compliance with- * the License. You may obtain a copy of the License at- *- * http://www.apache.org/licenses/LICENSE-2.0- *- * Unless required by applicable law or agreed to in writing, software- * distributed under the License is distributed on an "AS IS" BASIS,- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.- * See the License for the specific language governing permissions and- * limitations under the License.- */--package org.apache.nutch.fetcher;--import java.io.DataInput;-import java.io.DataOutput;-import java.io.IOException;--import org.apache.hadoop.io.Writable;--/* An entry in the fetcher's output. */-public final class FetcherOutput implements Writable {-- public final void readFields(DataInput in) throws IOException { }-- public final void write(DataOutput out) throws IOException { }-}