From 38dce547c0670ee570911103da7d4a8874aff5e0 Mon Sep 17 00:00:00 2001 From: orbiter Date: Mon, 28 Feb 2011 06:28:29 +0000 Subject: [PATCH] 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 --- source/de/anomic/server/serverCore.java | 5 ++--- source/de/anomic/yacy/yacyClient.java | 10 +++++++++- source/de/anomic/yacy/yacyNetwork.java | 5 ++--- source/de/anomic/yacy/yacySeedDB.java | 8 +++++--- source/net/yacy/cora/date/GenericFormatter.java | 2 +- source/net/yacy/kelondro/logging/Log.java | 2 +- source/net/yacy/kelondro/util/MapTools.java | 7 +++---- 7 files changed, 23 insertions(+), 16 deletions(-) diff --git a/source/de/anomic/server/serverCore.java b/source/de/anomic/server/serverCore.java index d49446782..fc0ea02e6 100644 --- a/source/de/anomic/server/serverCore.java +++ b/source/de/anomic/server/serverCore.java @@ -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(); } diff --git a/source/de/anomic/yacy/yacyClient.java b/source/de/anomic/yacy/yacyClient.java index 9cf6a8e07..d4997972c 100644 --- a/source/de/anomic/yacy/yacyClient.java +++ b/source/de/anomic/yacy/yacyClient.java @@ -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 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))); diff --git a/source/de/anomic/yacy/yacyNetwork.java b/source/de/anomic/yacy/yacyNetwork.java index 54f0fdde6..234c12dc6 100644 --- a/source/de/anomic/yacy/yacyNetwork.java +++ b/source/de/anomic/yacy/yacyNetwork.java @@ -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 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()))); diff --git a/source/de/anomic/yacy/yacySeedDB.java b/source/de/anomic/yacy/yacySeedDB.java index e726a35b7..72994c92b 100644 --- a/source/de/anomic/yacy/yacySeedDB.java +++ b/source/de/anomic/yacy/yacySeedDB.java @@ -1014,12 +1014,14 @@ public final class yacySeedDB implements AlternativeDomainNames { private yacySeed internalNext() { if (it == null || !(it.hasNext())) return null; try { + Map dna0; ConcurrentHashMap dna; while (it.hasNext()) { + dna0 = it.next(); + assert dna0 != null; + if (dna0 == null) continue; dna = new ConcurrentHashMap(); - 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 diff --git a/source/net/yacy/cora/date/GenericFormatter.java b/source/net/yacy/cora/date/GenericFormatter.java index a478e478b..8c92d9df1 100644 --- a/source/net/yacy/cora/date/GenericFormatter.java +++ b/source/net/yacy/cora/date/GenericFormatter.java @@ -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; diff --git a/source/net/yacy/kelondro/logging/Log.java b/source/net/yacy/kelondro/logging/Log.java index fba8134cd..fb1360f93 100644 --- a/source/net/yacy/kelondro/logging/Log.java +++ b/source/net/yacy/kelondro/logging/Log.java @@ -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); } diff --git a/source/net/yacy/kelondro/util/MapTools.java b/source/net/yacy/kelondro/util/MapTools.java index e85513ca6..8850801af 100644 --- a/source/net/yacy/kelondro/util/MapTools.java +++ b/source/net/yacy/kelondro/util/MapTools.java @@ -71,15 +71,14 @@ public final class MapTools { public static String map2string(final Map 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 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) {