better handling of concurrency in seed

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@6669 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
orbiter 15 years ago
parent 6538043d89
commit d378ca4604

@ -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);

@ -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 debugging
public 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 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<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);
}
}

@ -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");

@ -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 again
if (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();

Loading…
Cancel
Save