Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
Fixes and avoid of catching bad exceptions (some): - Rewrote usage of HashMap/Map to concurrent versions (to avoid a CME=ConcurrentModificationException) - Rewrote ConnectionInfo (as an example) to use a synchronized iterator instead of synchronizing an already synced HashSet (see Collections call) - This avoids catching CMEs again - Commented out noisy ConcurrentLog.logException() call
Roland Haederaaedc0405ded
diff --git a/htroot/AccessPicture_p.java b/htroot/AccessPicture_p.javaindex 34aa0257c..35a025622 100644--- a/htroot/AccessPicture_p.java+++ b/htroot/AccessPicture_p.java@@ -29,6 +29,7 @@ import java.util.Set;import net.yacy.cora.protocol.ConnectionInfo;import net.yacy.cora.protocol.RequestHeader;+import net.yacy.cora.util.ConcurrentLog;import net.yacy.search.Switchboard;import net.yacy.server.serverObjects;import net.yacy.server.serverSwitch;@@ -126,7 +127,10 @@ public class AccessPicture_p {time[h] = time2;}}- } catch (final ConcurrentModificationException e) {} // we don't want to synchronize this+ } catch (final ConcurrentModificationException e) {+ // we don't want to synchronize this+ ConcurrentLog.logException(e);+ }}// draw left column: access from outsidediff --git a/htroot/AccessTracker_p.java b/htroot/AccessTracker_p.javaindex d3b3cee8f..cc477e615 100644--- a/htroot/AccessTracker_p.java+++ b/htroot/AccessTracker_p.java@@ -37,6 +37,7 @@ import net.yacy.cora.date.GenericFormatter;import net.yacy.cora.protocol.Domains;import net.yacy.cora.protocol.HeaderFramework;import net.yacy.cora.protocol.RequestHeader;+import net.yacy.cora.util.ConcurrentLog;import net.yacy.peers.Seed;import net.yacy.search.Switchboard;import net.yacy.search.query.AccessTracker;@@ -84,7 +85,10 @@ public class AccessTracker_p {prop.putNum("page_list_" + entCount + "_countHour", sb.latestAccessCount(host, 1000 * 60 * 60));entCount++;}- } catch (final ConcurrentModificationException e) {} // we don't want to synchronize this+ } catch (final ConcurrentModificationException e) {+ // we don't want to synchronize this+ ConcurrentLog.logException(e);+ }prop.put("page_list", entCount);prop.put("page_num", entCount);@@ -95,7 +99,10 @@ public class AccessTracker_p {prop.putNum("page_bflist_" + entCount + "_countSecond", bfe.getValue());entCount++;}- } catch (final ConcurrentModificationException e) {} // we dont want to synchronize this+ } catch (final ConcurrentModificationException e) {+ // we don't want to synchronize this+ ConcurrentLog.logException(e);+ }prop.put("page_bflist", entCount);} else if (page == 1) {String host = (post == null) ? "" : post.get("host", "");@@ -114,7 +121,10 @@ public class AccessTracker_p {prop.putHTML("page_list_" + entCount + "_path", entry.getPath());entCount++;}- } catch (final ConcurrentModificationException e) {} // we don't want to synchronize this+ } catch (final ConcurrentModificationException e) {+ // we don't want to synchronize this+ ConcurrentLog.logException(e);+ }}} else {try {@@ -131,7 +141,10 @@ public class AccessTracker_p {entCount++;}}- } catch (final ConcurrentModificationException e) {} // we dont want to synchronize this+ } catch (final ConcurrentModificationException e) {+ // we don't want to synchronize this+ ConcurrentLog.logException(e);+ }}prop.put("page_list", entCount);prop.put("page_num", entCount);@@ -154,6 +167,8 @@ public class AccessTracker_p {try {query = ai.next();} catch (final ConcurrentModificationException e) {+ // we don't want to synchronize this+ ConcurrentLog.logException(e);break;}// put values in template@@ -272,7 +287,10 @@ public class AccessTracker_p {// nextm++;}- } catch (final ConcurrentModificationException e) {} // we dont want to synchronize this+ } catch (final ConcurrentModificationException e) {+ // we don't want to synchronize this+ ConcurrentLog.logException(e);+ }// return empty values to not break the table view if no results can be listedif (m==0) {prop.put("page_list", 1);diff --git a/htroot/CrawlStartScanner_p.java b/htroot/CrawlStartScanner_p.javaindex b831f9414..f3e2942c2 100644--- a/htroot/CrawlStartScanner_p.java+++ b/htroot/CrawlStartScanner_p.java@@ -269,7 +269,9 @@ public class CrawlStartScanner_pConcurrentLog.logException(e);}}- } catch (final ConcurrentModificationException e ) {+ } catch (final ConcurrentModificationException e) {+ // we don't want to synchronize this+ ConcurrentLog.logException(e);}}diff --git a/htroot/PerformanceMemory_p.java b/htroot/PerformanceMemory_p.javaindex 357f4d666..b6bf86f8a 100644--- a/htroot/PerformanceMemory_p.java+++ b/htroot/PerformanceMemory_p.java@@ -32,6 +32,7 @@ import java.util.Map;import net.yacy.cora.protocol.Domains;import net.yacy.cora.protocol.RequestHeader;+import net.yacy.cora.util.ConcurrentLog;import net.yacy.kelondro.index.Cache;import net.yacy.kelondro.index.RAMIndex;import net.yacy.kelondro.table.Table;@@ -138,6 +139,8 @@ public class PerformanceMemory_p {try {oie = oi.next();} catch (final ConcurrentModificationException e) {+ // we don't want to synchronize this+ ConcurrentLog.logException(e);break;}filename = oie.getKey();diff --git a/htroot/ServerScannerList.java b/htroot/ServerScannerList.javaindex af5e23f0f..919643964 100644--- a/htroot/ServerScannerList.java+++ b/htroot/ServerScannerList.java@@ -86,6 +86,7 @@ public class ServerScannerList {prop.put("servertable_edit_num", i);break table;} catch (final ConcurrentModificationException e) {+ ConcurrentLog.logException(e);continue table;}}diff --git a/htroot/suggest.java b/htroot/suggest.javaindex d9a1a53be..12b93576f 100644--- a/htroot/suggest.java+++ b/htroot/suggest.java@@ -28,6 +28,7 @@ import java.util.SortedSet;import net.yacy.cora.protocol.HeaderFramework;import net.yacy.cora.protocol.RequestHeader;import net.yacy.cora.protocol.ResponseHeader;+import net.yacy.cora.util.ConcurrentLog;import net.yacy.data.DidYouMean;import net.yacy.search.Switchboard;import net.yacy.server.serverObjects;@@ -85,7 +86,9 @@ public class suggest {}prop.put("suggestions_" + c + "_eol", 0);c++;- } catch (final ConcurrentModificationException e) {}+ } catch (final ConcurrentModificationException e) {+ ConcurrentLog.logException(e);+ }}}}diff --git a/htroot/yacy/hello.java b/htroot/yacy/hello.javaindex 77282b576..014ab723b 100644--- a/htroot/yacy/hello.java+++ b/htroot/yacy/hello.java@@ -29,14 +29,12 @@import java.io.IOException;import java.net.InetAddress;-import java.util.ConcurrentModificationException;import java.util.Iterator;-import java.util.Map;+import java.util.concurrent.ConcurrentMap;import net.yacy.cora.protocol.Domains;import net.yacy.cora.protocol.HeaderFramework;import net.yacy.cora.protocol.RequestHeader;-import net.yacy.cora.util.ConcurrentLog;import net.yacy.peers.Network;import net.yacy.peers.DHTSelection;import net.yacy.peers.Protocol;@@ -216,7 +214,7 @@ public final class hello {if (count > 100) { count = 100; }// latest seeds- final Map<String, Seed> ySeeds = DHTSelection.seedsByAge(sb.peers, true, count); // peerhash/yacySeed relation+ final ConcurrentMap<String, Seed> ySeeds = DHTSelection.seedsByAge(sb.peers, true, count); // peerhash/yacySeed relation// attach also my own seedseeds.append("seed0=").append(sb.peers.mySeed().genSeedStr(key)).append(serverCore.CRLF_STRING);@@ -230,14 +228,12 @@ public final class hello {String seedString;while (si.hasNext()) {s = si.next();- if ((s != null) && (s.isProper(false) == null)) try {+ if ((s != null) && (s.isProper(false) == null)) {seedString = s.genSeedStr(key);if (seedString != null) {seeds.append("seed").append(count).append('=').append(seedString).append(serverCore.CRLF_STRING);count++;}- } catch (final ConcurrentModificationException e) {- ConcurrentLog.logException(e);}}}diff --git a/htroot/yacysearch.java b/htroot/yacysearch.javaindex 12c794eb7..77ef192c6 100644--- a/htroot/yacysearch.java+++ b/htroot/yacysearch.java@@ -783,9 +783,14 @@ public class yacysearch {suggestion).toString());prop.put("didYouMean_suggestions_" + meanCount + "_sep", "|");meanCount++;- } catch (final ConcurrentModificationException e) {break meanCollect;}+ } catch (final ConcurrentModificationException e) {+ ConcurrentLog.logException(e);+ break meanCollect;+ }}- } catch (final ConcurrentModificationException e) {}+ } catch (final ConcurrentModificationException e) {+ ConcurrentLog.logException(e);+ }prop.put("didYouMean_suggestions_" + (meanCount - 1) + "_sep", "");prop.put("didYouMean", meanCount > 0 ? 1 : 0);prop.put("didYouMean_suggestions", meanCount);diff --git a/source/net/yacy/cora/document/RSSFeed.java b/source/net/yacy/cora/document/RSSFeed.javaindex 508b36009..e39a66113 100644--- a/source/net/yacy/cora/document/RSSFeed.java+++ b/source/net/yacy/cora/document/RSSFeed.java@@ -29,6 +29,8 @@ import java.util.LinkedHashMap;import java.util.Map;import java.util.Set;+import net.yacy.cora.util.ConcurrentLog;+public class RSSFeed implements Iterable<RSSMessage> {public static final int DEFAULT_MAXSIZE = 10000;@@ -146,6 +148,7 @@ public class RSSFeed implements Iterable<RSSMessage> {try {this.lastGUID = this.GUIDiterator.next();} catch (final ConcurrentModificationException e) {+ ConcurrentLog.logException(e);return null;}if (this.lastGUID == null) return null;diff --git a/source/net/yacy/cora/document/WordCache.java b/source/net/yacy/cora/document/WordCache.javaindex 1e069e0df..a6414974d 100644--- a/source/net/yacy/cora/document/WordCache.java+++ b/source/net/yacy/cora/document/WordCache.java@@ -275,7 +275,9 @@ public class WordCache {break;}}- } catch (final ConcurrentModificationException e) {}+ } catch (final ConcurrentModificationException e) {+ ConcurrentLog.logException(e);+ }return ret;}diff --git a/source/net/yacy/cora/protocol/ConnectionInfo.java b/source/net/yacy/cora/protocol/ConnectionInfo.javaindex 6091a9702..fa29226c8 100644--- a/source/net/yacy/cora/protocol/ConnectionInfo.java+++ b/source/net/yacy/cora/protocol/ConnectionInfo.java@@ -27,6 +27,7 @@ package net.yacy.cora.protocol;import java.util.Collections;import java.util.HashSet;+import java.util.Iterator;import java.util.Set;@@ -132,7 +133,7 @@ public class ConnectionInfo implements Comparable<ConnectionInfo> {* @return count of active connections*/public static int getCount() {- return allConnections.size();+ return getAllConnections().size();}/**@@ -141,22 +142,20 @@ public class ConnectionInfo implements Comparable<ConnectionInfo> {* @return load in percent*/public static int getLoadPercent() {- return getCount() * 100 / maxcount;+ return getCount() * 100 / getMaxcount();}/*** @return how many bytes queued up*/public static long getActiveUpbytes() {- long up = 0L;- try {- synchronized (allConnections) {- for(final ConnectionInfo con: allConnections) {- up += con.getUpbytes();- }+ long up = 0L;+ Iterator<ConnectionInfo> iter = getAllConnections().iterator();+ synchronized (iter) {+ while (iter.hasNext()) {+ ConnectionInfo con = iter.next();+ up += con.getUpbytes();}- } catch (final java.util.ConcurrentModificationException e) {- // there will be another try :-)}return up;}@@ -175,6 +174,7 @@ public class ConnectionInfo implements Comparable<ConnectionInfo> {* to be used in statistics** @param max connections+ * @TODO Is it correct to only set if max > 0? What if maxcount is > 0 and max = 0 ?*/public static void setMaxcount(final int max) {if (max > 0) maxcount = max;@@ -186,7 +186,7 @@ public class ConnectionInfo implements Comparable<ConnectionInfo> {* @param conInfo*/public static void addConnection(final ConnectionInfo conInfo) {- allConnections.add(conInfo);+ getAllConnections().add(conInfo);}/**@@ -195,7 +195,7 @@ public class ConnectionInfo implements Comparable<ConnectionInfo> {* @param conInfo*/protected static void removeConnection(final ConnectionInfo conInfo) {- allConnections.remove(conInfo);+ getAllConnections().remove(conInfo);}/**@@ -211,16 +211,14 @@ public class ConnectionInfo implements Comparable<ConnectionInfo> {* removes stale connections*/public static void cleanUp() {- try {- synchronized (allConnections) {- for(final ConnectionInfo con: allConnections) {- if(con.getLifetime() > staleAfterMillis) {- allConnections.remove(con);- }+ Iterator<ConnectionInfo> iter = getAllConnections().iterator();+ synchronized (iter) {+ while (iter.hasNext()) {+ ConnectionInfo con = iter.next();+ if(con.getLifetime() > staleAfterMillis) {+ getAllConnections().remove(con);}}- } catch (final java.util.ConcurrentModificationException e) {- // there will be another try :-)}}diff --git a/source/net/yacy/peers/DHTSelection.java b/source/net/yacy/peers/DHTSelection.javaindex 77a93a7a4..268357814 100644--- a/source/net/yacy/peers/DHTSelection.java+++ b/source/net/yacy/peers/DHTSelection.java@@ -33,6 +33,8 @@ import java.util.Map;import java.util.Random;import java.util.Set;import java.util.SortedMap;+import java.util.concurrent.ConcurrentHashMap;+import java.util.concurrent.ConcurrentMap;import net.yacy.cora.document.ASCII;import net.yacy.cora.federate.yacy.Distribution;@@ -461,13 +463,13 @@ public class DHTSelection {* @param count number of wanted peers* @return a hash map of peer hashes to seed object*/- public static Map<String, Seed> seedsByAge(final SeedDB seedDB, final boolean up, int count) {+ public static ConcurrentMap<String, Seed> seedsByAge(final SeedDB seedDB, final boolean up, int count) {if (count > seedDB.sizeConnected()) count = seedDB.sizeConnected();Seed ys;//long age;final Iterator<Seed> s = seedDB.seedsSortedConnected(!up, Seed.LASTSEEN);try {- final Map<String, Seed> result = new HashMap<String, Seed>();+ final ConcurrentMap<String, Seed> result = new ConcurrentHashMap<String, Seed>();while (s.hasNext() && count-- > 0) {ys = s.next();if (ys != null && ys.hash != null) {diff --git a/source/net/yacy/repository/LoaderDispatcher.java b/source/net/yacy/repository/LoaderDispatcher.javaindex c8c3d0037..230e3bc75 100644--- a/source/net/yacy/repository/LoaderDispatcher.java+++ b/source/net/yacy/repository/LoaderDispatcher.java@@ -167,8 +167,8 @@ public final class LoaderDispatcher {} catch (final IOException e) {// release the semaphore anywaycheck = this.loaderSteering.remove(request.url());- if (check != null) check.release(1000);- //Log.logException(e);+ if (check != null) check.release(1000);+ // Very noisy: ConcurrentLog.logException(e);throw new IOException(e);}}