Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
better handling of concurrency in seed
orbiterd378ca460494
diff --git a/htroot/Network.java b/htroot/Network.javaindex bdc545348..9ec7a158d 100644--- a/htroot/Network.java+++ b/htroot/Network.java@@ -31,6 +31,7 @@ import java.util.HashMap;import java.util.HashSet;import java.util.Iterator;import java.util.Map;+import java.util.concurrent.ConcurrentHashMap;import java.util.regex.Matcher;import java.util.regex.Pattern;import java.util.regex.PatternSyntaxException;@@ -180,10 +181,10 @@ public class Network {return prop;}- final HashMap<String, String> map = new HashMap<String, String>();+ final ConcurrentHashMap<String, String> map = new ConcurrentHashMap<String, String>();map.put(yacySeed.IP, post.get("peerIP"));map.put(yacySeed.PORT, post.get("peerPort"));- yacySeed peer = new yacySeed(post.get("peerHash"),map);+ yacySeed peer = new yacySeed(post.get("peerHash"), map);sb.updateMySeed();final int added = yacyClient.publishMySeed(sb.peers.mySeed(), sb.peers.peerActions, peer.getPublicAddress(), peer.hash);diff --git a/source/de/anomic/yacy/yacySeed.java b/source/de/anomic/yacy/yacySeed.javaindex c5cc1d6ee..55bff6454 100644--- a/source/de/anomic/yacy/yacySeed.java+++ b/source/de/anomic/yacy/yacySeed.java@@ -55,6 +55,7 @@ import java.util.Random;import java.util.Set;import java.util.TreeMap;import java.util.TreeSet;+import java.util.concurrent.ConcurrentHashMap;import net.yacy.kelondro.data.word.Word;import net.yacy.kelondro.order.Base64Order;@@ -169,12 +170,12 @@ public class yacySeed implements Cloneable {/** the peer-hash */public String hash;/** a set of identity founding values, eg. IP, name of the peer, YaCy-version, ...*/- private final Map<String, String> dna;+ private final ConcurrentHashMap<String, String> dna;public int available;public int selectscore = -1; // only for debuggingpublic String alternativeIP = null;- public yacySeed(final String theHash, final Map<String, String> theDna) {+ public yacySeed(final String theHash, final ConcurrentHashMap<String, String> theDna) {// create a seed with a pre-defined hash mapassert theHash != null;this.hash = theHash;@@ -186,7 +187,7 @@ public class yacySeed implements Cloneable {}public yacySeed(final String theHash) {- this.dna = new HashMap<String, String>();+ this.dna = new ConcurrentHashMap<String, String>();// settings that can only be computed by originating peer:// at first startup -@@ -776,7 +777,7 @@ public class yacySeed implements Cloneable {if (seed == null) { return null; }// extract hash- final HashMap<String, String> dna = MapTools.string2map(seed, ",");+ final ConcurrentHashMap<String, String> dna = MapTools.string2map(seed, ",");final String hash = dna.remove(yacySeed.HASH);if (hash == null) return null;final yacySeed resultSeed = new yacySeed(hash, dna);@@ -881,11 +882,10 @@ public class yacySeed implements Cloneable {return mySeed;}- @SuppressWarnings("unchecked")public final yacySeed clone() {- synchronized (this.dna) {- return new yacySeed(this.hash, (HashMap<String, String>) (new HashMap<String, String>(this.dna).clone()));- }+ ConcurrentHashMap<String, String> ndna = new ConcurrentHashMap<String, String>();+ ndna.putAll(this.dna);+ return new yacySeed(this.hash, ndna);}}diff --git a/source/de/anomic/yacy/yacySeedDB.java b/source/de/anomic/yacy/yacySeedDB.javaindex d4c77b5a9..bfa6f050b 100644--- a/source/de/anomic/yacy/yacySeedDB.java+++ b/source/de/anomic/yacy/yacySeedDB.java@@ -38,6 +38,7 @@ import java.util.Hashtable;import java.util.Iterator;import java.util.Map;import java.util.TreeMap;+import java.util.concurrent.ConcurrentHashMap;import net.yacy.kelondro.blob.MapDataMining;import net.yacy.kelondro.data.meta.DigestURI;@@ -529,9 +530,9 @@ public final class yacySeedDB implements AlternativeDomainNames {private yacySeed get(final String hash, final MapDataMining database) {if (hash == null) return null;if ((this.mySeed != null) && (hash.equals(mySeed.hash))) return mySeed;- Map<String, String> entry;+ ConcurrentHashMap<String, String> entry = new ConcurrentHashMap<String, String>();try {- entry = database.get(hash);+ entry.putAll(database.get(hash));} catch (final IOException e) {entry = null;}@@ -982,9 +983,10 @@ public final class yacySeedDB implements AlternativeDomainNames {public yacySeed internalNext() {if ((it == null) || (!(it.hasNext()))) return null;try {- Map<String, String> dna;+ ConcurrentHashMap<String, String> dna;while (it.hasNext()) {- dna = it.next();+ dna = new ConcurrentHashMap<String, String>();+ dna.putAll(it.next());assert dna != null;if (dna == null) continue;final String hash = dna.remove("key");diff --git a/source/net/yacy/kelondro/util/MapTools.java b/source/net/yacy/kelondro/util/MapTools.javaindex 3a3f65a29..3906784ea 100644--- a/source/net/yacy/kelondro/util/MapTools.java+++ b/source/net/yacy/kelondro/util/MapTools.java@@ -27,7 +27,6 @@ package net.yacy.kelondro.util;import java.util.Collections;import java.util.ConcurrentModificationException;-import java.util.HashMap;import java.util.HashSet;import java.util.Iterator;import java.util.Map;@@ -35,6 +34,7 @@ import java.util.Properties;import java.util.Set;import java.util.StringTokenizer;import java.util.Map.Entry;+import java.util.concurrent.ConcurrentHashMap;public final class MapTools {@@ -51,10 +51,10 @@ public final class MapTools {return p;}- public static HashMap<String, String> string2map(String string, final String separator) {+ public static ConcurrentHashMap<String, String> string2map(String string, final String separator) {// this can be used to parse a Map.toString() into a Map againif (string == null) return null;- final HashMap<String, String> map = new HashMap<String, String>();+ final ConcurrentHashMap<String, String> map = new ConcurrentHashMap<String, String>();int pos;if ((pos = string.indexOf('{')) >= 0) string = string.substring(pos + 1).trim();if ((pos = string.lastIndexOf('}')) >= 0) string = string.substring(0, pos).trim();