bugfix for 'hello.class java.util.ConcurrentModificationException:null'

finals

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@943 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
borg-0300 20 years ago
parent 4d504da962
commit b00cd5640b

@ -69,7 +69,6 @@ import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
import de.anomic.net.natLib; import de.anomic.net.natLib;
import de.anomic.plasma.plasmaSwitchboard; import de.anomic.plasma.plasmaSwitchboard;
import de.anomic.server.serverCodings; import de.anomic.server.serverCodings;
@ -100,7 +99,6 @@ public class yacySeed {
public static final String STR_SEED = "seed"; public static final String STR_SEED = "seed";
public static final String STR_EQUAL = "="; public static final String STR_EQUAL = "=";
// class variables // class variables
public String hash; public String hash;
private Map dna; private Map dna;
@ -140,7 +138,7 @@ public class yacySeed {
dna.put("IPType", "∅"); // static/dynamic (if the ip changes often for any reason) dna.put("IPType", "∅"); // static/dynamic (if the ip changes often for any reason)
// settings that can only be computed by visiting peer // settings that can only be computed by visiting peer
dna.put("LastSeen", yacyCore.universalDateShortString(new Date())); // for last-seen date dna.put(STR_LASTSEEN, yacyCore.universalDateShortString(new Date())); // for last-seen date
dna.put("USpeed", "0"); // the computated uplink speed of the peer dna.put("USpeed", "0"); // the computated uplink speed of the peer
// settings that are needed to organize the seed round-trip // settings that are needed to organize the seed round-trip
@ -159,8 +157,8 @@ public class yacySeed {
} }
public String get(String key, String dflt) { public String get(String key, String dflt) {
Object o = dna.get(key); final Object o = dna.get(key);
if (o == null) return dflt; else return (String) o; if (o == null) { return dflt; } else { return (String) o; }
} }
public void put(String key, String value) { public void put(String key, String value) {
@ -180,22 +178,26 @@ public class yacySeed {
} }
public void incSI(int count) { public void incSI(int count) {
String v = (String) dna.get(INDEX_OUT); if (v == null) v = "0"; String v = (String) dna.get(INDEX_OUT);
if (v == null) { v = "0"; }
dna.put(INDEX_OUT, Integer.toString(Integer.parseInt(v) + count)); dna.put(INDEX_OUT, Integer.toString(Integer.parseInt(v) + count));
} }
public void incRI(int count) { public void incRI(int count) {
String v = (String) dna.get(INDEX_IN); if (v == null) v = "0"; String v = (String) dna.get(INDEX_IN);
if (v == null) { v = "0"; }
dna.put(INDEX_IN, Integer.toString(Integer.parseInt(v) + count)); dna.put(INDEX_IN, Integer.toString(Integer.parseInt(v) + count));
} }
public void incSU(int count) { public void incSU(int count) {
String v = (String) dna.get(URL_OUT); if (v == null) v = "0"; String v = (String) dna.get(URL_OUT);
if (v == null) { v = "0"; }
dna.put(URL_OUT, Integer.toString(Integer.parseInt(v) + count)); dna.put(URL_OUT, Integer.toString(Integer.parseInt(v) + count));
} }
public void incRU(int count) { public void incRU(int count) {
String v = (String) dna.get(URL_IN); if (v == null) v = "0"; String v = (String) dna.get(URL_IN);
if (v == null) { v = "0"; }
dna.put(URL_IN, Integer.toString(Integer.parseInt(v) + count)); dna.put(URL_IN, Integer.toString(Integer.parseInt(v) + count));
} }
@ -218,20 +220,24 @@ public class yacySeed {
} }
public String getAddress() { public String getAddress() {
String ip = (String) dna.get("IP"); final String ip = (String) dna.get("IP");
String port = (String) dna.get("Port"); final String port = (String) dna.get("Port");
if (ip != null && ip.length() >= 8 && port != null && port.length() >= 2) return ip + ":" + port; else return null; if (ip != null && ip.length() >= 8 && port != null && port.length() >= 2) {
return ip + ":" + port;
} else {
return null;
}
} }
public long getUTCDiff() { public long getUTCDiff() {
String utc = (String) dna.get("UTC"); String utc = (String) dna.get("UTC");
if (utc == null) utc = "+0200"; if (utc == null) { utc = "+0200"; }
return serverDate.UTCDiff(utc); return serverDate.UTCDiff(utc);
} }
public long getLastSeenTime() { public long getLastSeenTime() {
try { try {
long t = yacyCore.shortFormatter.parse(get("LastSeen", "20040101000000")).getTime(); final long t = yacyCore.shortFormatter.parse(get(STR_LASTSEEN, "20040101000000")).getTime();
// the problem here is: getTime applies a time shift according to local time zone: // the problem here is: getTime applies a time shift according to local time zone:
// it substracts the local UTF offset, but it should substract the remote UTC offset // it substracts the local UTF offset, but it should substract the remote UTC offset
// so we correct it by first adding the local UTF offset and then subtractibg the remote // so we correct it by first adding the local UTF offset and then subtractibg the remote
@ -244,11 +250,11 @@ public class yacySeed {
return System.currentTimeMillis(); return System.currentTimeMillis();
} }
} }
public int getAge() { public int getAge() {
// returns the age as number of days // returns the age as number of days
try { try {
long t = yacyCore.shortFormatter.parse(get("BDate", "20040101000000")).getTime(); final long t = yacyCore.shortFormatter.parse(get("BDate", "20040101000000")).getTime();
return (int) ((System.currentTimeMillis() - (t - getUTCDiff() + serverDate.UTCDiff())) / 1000 / 60 / 60 / 24); return (int) ((System.currentTimeMillis() - (t - getUTCDiff() + serverDate.UTCDiff())) / 1000 / 60 / 60 / 24);
} catch (java.text.ParseException e) { } catch (java.text.ParseException e) {
return -1; return -1;
@ -256,12 +262,12 @@ public class yacySeed {
return -1; return -1;
} }
} }
public void setLastSeenTime() { public void setLastSeenTime() {
// if we set a last seen time, then we need to respect the seeds UTC offset // if we set a last seen time, then we need to respect the seeds UTC offset
put("LastSeen", yacyCore.shortFormatter.format(new Date(System.currentTimeMillis() - serverDate.UTCDiff() + getUTCDiff()))); put(STR_LASTSEEN, yacyCore.shortFormatter.format(new Date(System.currentTimeMillis() - serverDate.UTCDiff() + getUTCDiff())));
} }
public int getPPM() { public int getPPM() {
try { try {
return Integer.parseInt(get("ISpeed", "0")); return Integer.parseInt(get("ISpeed", "0"));
@ -277,15 +283,15 @@ public class yacySeed {
return 0; return 0;
} }
} }
private boolean getFlag(int flag) { private boolean getFlag(int flag) {
String flags = get("Flags", "0000"); final String flags = get("Flags", "0000");
return (new bitfield(flags.getBytes())).get(flag); return (new bitfield(flags.getBytes())).get(flag);
} }
private void setFlag(int flag, boolean value) { private void setFlag(int flag, boolean value) {
String flags = get("Flags", "0000"); final String flags = get("Flags", "0000");
bitfield f = new bitfield(flags.getBytes()); final bitfield f = new bitfield(flags.getBytes());
f.set(flag, value); f.set(flag, value);
put("Flags", f.toString()); put("Flags", f.toString());
} }
@ -303,7 +309,6 @@ public class yacySeed {
//if (getVersion() < 0.335) return false; //if (getVersion() < 0.335) return false;
return getFlag(2); return getFlag(2);
} }
public boolean isVirgin() { public boolean isVirgin() {
return get(PEERTYPE, "").equals(PEERTYPE_VIRGIN); return get(PEERTYPE, "").equals(PEERTYPE_VIRGIN);
} }
@ -321,57 +326,67 @@ public class yacySeed {
} }
public String encodeLex(long c, int length) { public String encodeLex(long c, int length) {
if (length < 0) length = 0; if (length < 0) { length = 0; }
String s = ""; String s = "";
if (c == 0) s = '-' + s; if (c == 0) {
else while (c > 0) { s = '-' + s;
s = ((char) (32 + (c % 96))) + s; } else {
c = c / 96; while (c > 0) {
s = ((char) (32 + (c % 96))) + s;
c = c / 96;
}
} }
if (length != 0 && s.length() > length) if (length != 0 && s.length() > length) {
throw new RuntimeException("encodeLex result '" + s + "' exceeds demanded length of " + length + " digits"); throw new RuntimeException("encodeLex result '" + s + "' exceeds demanded length of " + length + " digits");
if (length == 0) length = 1; // rare exception for the case that c == 0 }
while (s.length() < length) s = '-' + s; if (length == 0) { length = 1; } // rare exception for the case that c == 0
while (s.length() < length) { s = '-' + s; }
return s; return s;
} }
public long decodeLex(String s) { public long decodeLex(String s) {
long c = 0; long c = 0;
for (int i = 0; i < s.length(); i++) c = c * 96 + (byte) s.charAt(i) - 32; for (int i = 0; i < s.length(); i++) {
c = c * 96 + (byte) s.charAt(i) - 32;
}
return c; return c;
} }
private static long maxLex(int len) { private static long maxLex(int len) {
// computes the maximum number that can be coded with a lex-encoded String of length len // computes the maximum number that can be coded with a lex-encoded String of length len
long c = 0; long c = 0;
for (int i = 0; i < len; i++) c = c * 96 + 90; for (int i = 0; i < len; i++) {
c = c * 96 + 90;
}
return c; return c;
} }
private static long minLex(int len) { private static long minLex(int len) {
// computes the minimum number that can be coded with a lex-encoded String of length len // computes the minimum number that can be coded with a lex-encoded String of length len
long c = 0; long c = 0;
for (int i = 0; i < len; i++) c = c * 96 + 13; for (int i = 0; i < len; i++) {
c = c * 96 + 13;
}
return c; return c;
} }
public static final long minDHTNumber = minLex(9); public static final long minDHTNumber = minLex(9);
public static final long maxDHTDistance = maxLex(9) - minDHTNumber; public static final long maxDHTDistance = maxLex(9) - minDHTNumber;
public long dhtDistance(String wordhash) { public long dhtDistance(String wordhash) {
// computes a virtual distance, the result must be set in relation to maxDHTDistace // computes a virtual distance, the result must be set in relation to maxDHTDistace
// if the distance is small, this peer is more responsible for that word hash // if the distance is small, this peer is more responsible for that word hash
// if the distance is big, this peer is less responsible for that word hash // if the distance is big, this peer is less responsible for that word hash
long myPos = decodeLex(hash.substring(0,9)); final long myPos = decodeLex(hash.substring(0,9));
long wordPos = decodeLex(wordhash.substring(0,9)); final long wordPos = decodeLex(wordhash.substring(0,9));
return (myPos > wordPos) ? (myPos - wordPos) : (myPos + maxDHTDistance - wordPos); return (myPos > wordPos) ? (myPos - wordPos) : (myPos + maxDHTDistance - wordPos);
} }
public long dhtDistance() { public long dhtDistance() {
// returns an absolute value // returns an absolute value
return decodeLex(hash.substring(0,9)) - minDHTNumber; return decodeLex(hash.substring(0,9)) - minDHTNumber;
} }
public static yacySeed genLocalSeed(plasmaSwitchboard sb) { public static yacySeed genLocalSeed(plasmaSwitchboard sb) {
// genera a seed for the local peer // genera a seed for the local peer
// this is the birthplace of a seed, that then will start to travel to other peers // this is the birthplace of a seed, that then will start to travel to other peers
@ -379,8 +394,8 @@ public class yacySeed {
// at first we need a good peer hash // at first we need a good peer hash
// that hash should be as static as possible, so that it depends mainly on system // that hash should be as static as possible, so that it depends mainly on system
// variables and can even then be reconstructed if the local seed has disappeared // variables and can even then be reconstructed if the local seed has disappeared
Properties sp = System.getProperties(); final Properties sp = System.getProperties();
String slow = final String slow =
sp.getProperty("file.encoding", "") + sp.getProperty("file.encoding", "") +
sp.getProperty("file.separator", "") + sp.getProperty("file.separator", "") +
sp.getProperty("java.class.path", "") + sp.getProperty("java.class.path", "") +
@ -393,12 +408,12 @@ public class yacySeed {
sp.getProperty("user.language", "") + sp.getProperty("user.language", "") +
sp.getProperty("user.name", "") + sp.getProperty("user.name", "") +
sp.getProperty("user.timezone", ""); sp.getProperty("user.timezone", "");
String medium = final String medium =
sp.getProperty("java.class.version", "") + sp.getProperty("java.class.version", "") +
sp.getProperty("java.version", "") + sp.getProperty("java.version", "") +
sp.getProperty("os.version", "") + sp.getProperty("os.version", "") +
sb.getConfig("peerName", "noname"); sb.getConfig("peerName", "noname");
String fast = Long.toString(System.currentTimeMillis()); final String fast = Long.toString(System.currentTimeMillis());
// the resultinh hash does not have any information than can be used to reconstruct the // the resultinh hash does not have any information than can be used to reconstruct the
// original system information that has been collected here to create the hash // original system information that has been collected here to create the hash
// We simply distinuguish three parts of the hash: slow, medium and fast changing character of system idenfification // We simply distinuguish three parts of the hash: slow, medium and fast changing character of system idenfification
@ -416,7 +431,7 @@ public class yacySeed {
System.exit(-1); System.exit(-1);
} }
yacySeed newSeed = new yacySeed(hash); final yacySeed newSeed = new yacySeed(hash);
// now calculate other information about the host // now calculate other information about the host
newSeed.dna.put("Name", sb.getConfig("peerName", "unnamed")); newSeed.dna.put("Name", sb.getConfig("peerName", "unnamed"));
@ -426,7 +441,7 @@ public class yacySeed {
newSeed.dna.put("Port", sb.getConfig("port", "8080")); newSeed.dna.put("Port", sb.getConfig("port", "8080"));
} }
newSeed.dna.put("BDate", yacyCore.universalDateShortString(new Date())); newSeed.dna.put("BDate", yacyCore.universalDateShortString(new Date()));
newSeed.dna.put("LastSeen", newSeed.dna.get("BDate")); // just as initial setting newSeed.dna.put(STR_LASTSEEN, newSeed.dna.get("BDate")); // just as initial setting
newSeed.dna.put("UTC", serverDate.UTCDiffString()); newSeed.dna.put("UTC", serverDate.UTCDiffString());
newSeed.dna.put(PEERTYPE, PEERTYPE_VIRGIN); newSeed.dna.put(PEERTYPE, PEERTYPE_VIRGIN);
@ -435,66 +450,60 @@ public class yacySeed {
public static yacySeed genRemoteSeed(String seedStr, String key) { public static yacySeed genRemoteSeed(String seedStr, String key) {
// this method is used to convert the external representation of a seed into a seed object // this method is used to convert the external representation of a seed into a seed object
if (seedStr == null) return null; if (seedStr == null || seedStr.length() < yacySeedDB.commonHashLength) { return null; }
String seed = crypt.simpleDecode(seedStr, key); final String seed = crypt.simpleDecode(seedStr, key);
if (seed == null) return null; if (seed == null) { return null; }
HashMap dna = serverCodings.string2map(seed); final HashMap dna = serverCodings.string2map(seed);
String hash = (String) dna.remove("Hash"); final String hash = (String) dna.remove("Hash");
return new yacySeed(hash, dna); return new yacySeed(hash, dna);
} }
public String toString() { public String toString() {
String s = null;
synchronized (dna) { synchronized (dna) {
// set hash into seed code structure dna.put("Hash", this.hash); // set hash into seed code structure
dna.put("Hash", this.hash); final String s = dna.toString(); // generate string representation
// generate string representation dna.remove("Hash"); // reconstruct original: hash is stored external
s = dna.toString(); return s;
// reconstruct original: hash is stored external
dna.remove("Hash");
// return string
} }
return s;
} }
public String genSeedStr(String key) { public String genSeedStr(String key) {
// use a default encoding // use a default encoding
return genSeedStr('b', key); return genSeedStr('b', key);
} }
public String genSeedStr(char method, String key) { public String genSeedStr(char method, String key) {
return crypt.simpleEncode(toString(), key, method); return crypt.simpleEncode(toString(), key, method);
} }
public String isProper() { public String isProper() {
// checks if everything is ok with that seed // checks if everything is ok with that seed
if (this.hash == null) return "hash is null"; if (this.hash == null) { return "hash is null"; }
if (this.hash.length() != yacySeedDB.commonHashLength) return "wrong hash length (" + this.hash.length() + ")"; if (this.hash.length() != yacySeedDB.commonHashLength) { return "wrong hash length (" + this.hash.length() + ")"; }
String ip = (String) dna.get("IP"); final String ip = (String) dna.get("IP");
if (ip == null) return "IP is null"; if (ip == null) { return "IP is null"; }
if (ip.length() < 8) return "IP is too short: " + ip; if (ip.length() < 8) { return "IP is too short: " + ip; }
if (!(natLib.isProper(ip))) return "IP is not proper: " + ip; if (!natLib.isProper(ip)) { return "IP is not proper: " + ip; }
return null; return null;
} }
public void save(File f) throws IOException { public void save(File f) throws IOException {
String out = genSeedStr('p', null); final String out = genSeedStr('p', null);
FileWriter fw = new FileWriter(f); final FileWriter fw = new FileWriter(f);
fw.write(out, 0, out.length()); fw.write(out, 0, out.length());
fw.close(); fw.close();
} }
public static yacySeed load(File f) throws IOException { public static yacySeed load(File f) throws IOException {
FileReader fr = new FileReader(f); final FileReader fr = new FileReader(f);
char[] b = new char[(int) f.length()]; final char[] b = new char[(int) f.length()];
fr.read(b, 0, b.length); fr.read(b, 0, b.length);
fr.close(); fr.close();
return genRemoteSeed(new String(b), null); return genRemoteSeed(new String(b), null);
} }
public Object clone() { public Object clone() {
return new yacySeed(this.hash, (HashMap) (new HashMap(dna)).clone()); return new yacySeed(this.hash, (HashMap) (new HashMap(dna)).clone());
} }
/* /*
@ -517,4 +526,4 @@ public class yacySeed {
} }
*/ */
} }
Loading…
Cancel
Save