diff --git a/htroot/Network.java b/htroot/Network.java index 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 map = new HashMap(); + final ConcurrentHashMap map = new ConcurrentHashMap(); 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.java index 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 dna; + private final ConcurrentHashMap dna; public int available; public int selectscore = -1; // only for debugging public String alternativeIP = null; - public yacySeed(final String theHash, final Map theDna) { + public yacySeed(final String theHash, final ConcurrentHashMap theDna) { // create a seed with a pre-defined hash map assert theHash != null; this.hash = theHash; @@ -186,7 +187,7 @@ public class yacySeed implements Cloneable { } public yacySeed(final String theHash) { - this.dna = new HashMap(); + this.dna = new ConcurrentHashMap(); // 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 dna = MapTools.string2map(seed, ","); + final ConcurrentHashMap 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) (new HashMap(this.dna).clone())); - } + ConcurrentHashMap ndna = new ConcurrentHashMap(); + 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.java index 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 entry; + ConcurrentHashMap entry = new ConcurrentHashMap(); 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 dna; + ConcurrentHashMap dna; while (it.hasNext()) { - dna = it.next(); + dna = new ConcurrentHashMap(); + 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.java index 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 string2map(String string, final String separator) { + public static ConcurrentHashMap string2map(String string, final String separator) { // this can be used to parse a Map.toString() into a Map again if (string == null) return null; - final HashMap map = new HashMap(); + final ConcurrentHashMap map = new ConcurrentHashMap(); int pos; if ((pos = string.indexOf('{')) >= 0) string = string.substring(pos + 1).trim(); if ((pos = string.lastIndexOf('}')) >= 0) string = string.substring(0, pos).trim();