better concurrency (less locking on date formatting) more logging and minor bug fixes

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@7540 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
orbiter 14 years ago
parent 85f5c02deb
commit 38dce547c0

@ -567,7 +567,7 @@ public final class serverCore extends AbstractBusyThread implements BusyThread {
}
public void writeLine(final String messg) throws IOException {
send(this.out, messg + CRLF_STRING);
send(this.out, messg);
log(true, messg);
}
@ -894,8 +894,7 @@ public final class serverCore extends AbstractBusyThread implements BusyThread {
public static void send(final OutputStream os, final String buf) throws IOException {
os.write(buf.getBytes());
// TODO make sure there was no reason to add this additional newline
//os.write(CRLF);
os.write(CRLF);
os.flush();
}

@ -43,6 +43,7 @@
package de.anomic.yacy;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
@ -614,7 +615,14 @@ public final class yacyClient {
// send request
Map<String, String> resultMap = null;
parts.put("myseed", UTF8.StringBody((mySeed == null) ? "" : mySeed.genSeedStr(parts.get("key").toString())));
String key = "";
ContentBody keyBody = parts.get("key");
if (keyBody != null) {
ByteArrayOutputStream baos = new ByteArrayOutputStream(20);
keyBody.writeTo(baos);
key = baos.toString();
}
parts.put("myseed", UTF8.StringBody((mySeed == null) ? "" : mySeed.genSeedStr(key)));
parts.put("count", UTF8.StringBody(Integer.toString(Math.max(10, count))));
parts.put("resource", UTF8.StringBody(((global) ? "global" : "local")));
parts.put("partitions", UTF8.StringBody(Integer.toString(partitions)));

@ -91,9 +91,6 @@ public class yacyNetwork {
return parts;
}
// use our own formatter to prevent concurrency locks with other processes
private final static GenericFormatter my_SHORT_SECOND_FORMATTER = new GenericFormatter(GenericFormatter.FORMAT_SHORT_SECOND, GenericFormatter.time_second);
public static final LinkedHashMap<String,ContentBody> basicRequestParts(String myHash, String targetHash, String networkName) {
// put in all the essentials for routing and network authentication
// generate a session key
@ -105,6 +102,8 @@ public class yacyNetwork {
if (targetHash != null) parts.put("youare", UTF8.StringBody(targetHash));
// time information for synchronization
// use our own formatter to prevent concurrency locks with other processes
GenericFormatter my_SHORT_SECOND_FORMATTER = new GenericFormatter(GenericFormatter.FORMAT_SHORT_SECOND, GenericFormatter.time_second);
parts.put("mytime", UTF8.StringBody(my_SHORT_SECOND_FORMATTER.format()));
parts.put("myUTC", UTF8.StringBody(Long.toString(System.currentTimeMillis())));

@ -1014,12 +1014,14 @@ public final class yacySeedDB implements AlternativeDomainNames {
private yacySeed internalNext() {
if (it == null || !(it.hasNext())) return null;
try {
Map<String, String> dna0;
ConcurrentHashMap<String, String> dna;
while (it.hasNext()) {
dna0 = it.next();
assert dna0 != null;
if (dna0 == null) continue;
dna = new ConcurrentHashMap<String, String>();
dna.putAll(it.next());
assert dna != null;
if (dna == null) continue;
dna.putAll(dna0);
final String hash = dna.remove("key");
assert hash != null;
if (hash == null) continue; // bad seed

@ -65,7 +65,7 @@ public class GenericFormatter extends AbstractFormatter implements DateFormatter
private long maxCacheDiff;
public GenericFormatter(SimpleDateFormat dateFormat, long maxCacheDiff) {
this.dateFormat = dateFormat;
this.dateFormat = (SimpleDateFormat) dateFormat.clone(); // avoid concurrency locking effects
this.last_time = 0;
this.last_format = "";
this.maxCacheDiff = maxCacheDiff;

@ -380,7 +380,7 @@ public final class Log {
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler(){
public void uncaughtException(final Thread t, final Throwable e) {
String msg = String.format("Thread %s: %s",t.getName(), e.getMessage());
exceptionLog.logWarning(msg);
exceptionLog.logSevere(msg, e);
System.err.print("Exception in thread \"" + t.getName() + "\" ");
e.printStackTrace(System.err);
}

@ -71,15 +71,14 @@ public final class MapTools {
public static String map2string(final Map<String, String> m, final String separator, final boolean braces) {
// m must be synchronized to prevent that a ConcurrentModificationException occurs
synchronized (m) {
final StringBuilder buf = new StringBuilder(20 * m.size());
final StringBuilder buf = new StringBuilder(30 * m.size());
if (braces) { buf.append("{"); }
int retry = 10;
critical: while (retry > 0) {
try {
for (final Entry<String, String> e: m.entrySet()) {
buf.append(e.getKey()).append('=');
if (e.getValue() != null) { buf.append(e.getValue()); }
buf.append(separator);
if (e.getValue() == null) continue;
buf.append(e.getKey()).append('=').append(e.getValue()).append(separator);
}
break critical; // success
} catch (final ConcurrentModificationException e) {

Loading…
Cancel
Save