Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
- removed synchronization in serverSwitch which should improve speed - fixed wrong assert in network graph - enhanced double check method in table class
orbiteraf87af0d4cdd
diff --git a/source/de/anomic/server/serverSwitch.java b/source/de/anomic/server/serverSwitch.javaindex 18c073fd5..98d639ad6 100644--- a/source/de/anomic/server/serverSwitch.java+++ b/source/de/anomic/server/serverSwitch.java@@ -63,12 +63,11 @@ public class serverSwitch {protected boolean firstInit;protected Log log;protected int serverJobs;- private Map<String, String> configProps;- private final Map<String, String> configRemoved;- private final Map<InetAddress, String> authorization;- private final TreeMap<String, BusyThread> workerThreads;- private final TreeMap<String, serverSwitchAction> switchActions;- private final serverAccessTracker accessTracker;+ private ConcurrentHashMap<String, String> configProps;+ private final ConcurrentHashMap<String, String> configRemoved;+ private final ConcurrentHashMap<InetAddress, String> authorization;+ private final TreeMap<String, BusyThread> workerThreads;+ private final serverAccessTracker accessTracker;public serverSwitch(final File dataPath, final File appPath, final String initPath, final String configPath) {// we initialize the switchboard with a property file,@@ -86,7 +85,7 @@ public class serverSwitch {new File(configFile.getParent()).mkdir();// predefine init's- Map<String, String> initProps;+ ConcurrentHashMap<String, String> initProps;if (initFile.exists())initProps = FileUtils.loadMap(initFile);else@@ -144,9 +143,6 @@ public class serverSwitch {// init thread controlworkerThreads = new TreeMap<String, BusyThread>();- // init switch actions- switchActions = new TreeMap<String, serverSwitchAction>();-// init busy state controlserverJobs = 0;@@ -202,35 +198,9 @@ public class serverSwitch {}public void setConfig(final String key, final String value) {- // perform action before setting new value- final Iterator<serverSwitchAction> bevore = switchActions.values().iterator();- final Iterator<serverSwitchAction> after = switchActions.values().iterator();- synchronized (configProps) {- serverSwitchAction action;-- while (bevore.hasNext()) {- action = bevore.next();- try {- action.doBevoreSetConfig(key, value);- } catch (final Exception e) {- log.logSevere("serverAction bevoreSetConfig '" + action.getShortDescription() + "' failed with exception: " + e.getMessage());- }- }-- // set the value- final Object oldValue = configProps.put(key, value);- saveConfig();-- // perform actions afterwards- while (after.hasNext()) {- action = after.next();- try {- action.doAfterSetConfig(key, value, (oldValue == null) ? null : (String) oldValue);- } catch (final Exception e) {- log.logSevere("serverAction afterSetConfig '" + action.getShortDescription() + "' failed with exception: " + e.getMessage());- }- }- }+ // set the value+ final String oldValue = configProps.put(key, value);+ if (oldValue == null || !value.equals(oldValue)) saveConfig();}public void removeConfig(final String key) {@@ -241,26 +211,12 @@ public class serverSwitch {* @see de.anomic.server.serverSwitch#getConfig(java.lang.String, java.lang.String)*/public String getConfig(final String key, final String dflt) {- final Iterator<serverSwitchAction> i = switchActions.values().iterator();- synchronized (configProps) {- // get the value- final Object s = configProps.get(key);-- // do action- serverSwitchAction action;- while (i.hasNext()) {- action = i.next();- try {- action.doWhenGetConfig(key, (s == null) ? null : (String) s, dflt);- } catch (final Exception e) {- log.logSevere("serverAction whenGetConfig '" + action.getShortDescription() + "' failed with exception: " + e.getMessage());- }- }+ // get the value+ final String s = configProps.get(key);- // return value- if (s == null) return dflt;- return (String) s;- }+ // return value+ if (s == null) return dflt;+ return s;}public long getConfigLong(final String key, final long dflt) {@@ -314,35 +270,19 @@ public class serverSwitch {private void saveConfig() {try {- synchronized (configProps) {- FileUtils.saveMap(configFile, configProps, configComment);- }+ ConcurrentHashMap<String, String> configPropsCopy = new ConcurrentHashMap<String, String>();+ configPropsCopy.putAll(configProps); // avoid concurrency problems+ FileUtils.saveMap(configFile, configPropsCopy, configComment);} catch (final IOException e) {log.logSevere("CONFIG: Cannot write config file " + configFile.toString() + ": " + e.getMessage());System.out.println("ERROR: cannot write config file " + configFile.toString() + ": " + e.getMessage());}}- public Map<String, String> getRemoved() {+ public ConcurrentHashMap<String, String> getRemoved() {// returns configuration that had been removed during initializationreturn configRemoved;}-- // add/remove action listener- public void deployAction(final String actionName, final String actionShortDescription, final String actionLongDescription,- final serverSwitchAction newAction) {- newAction.setLog(log);- newAction.setDescription(actionShortDescription, actionLongDescription);- switchActions.put(actionName, newAction);- log.logInfo("Deployed Action '" + actionShortDescription + "', (" + switchActions.size() + " actions registered)");- }-- public void undeployAction(final String actionName) {- final serverSwitchAction action = switchActions.get(actionName);- action.close();- switchActions.remove(actionName);- log.logInfo("Undeployed Action '" + action.getShortDescription() + "', (" + switchActions.size() + " actions registered)");- }public void deployThread(final String threadName,diff --git a/source/de/anomic/server/serverSwitchAction.java b/source/de/anomic/server/serverSwitchAction.javadeleted file mode 100644index d9955e71b..000000000--- a/source/de/anomic/server/serverSwitchAction.java+++ /dev/null@@ -1,53 +0,0 @@-// serverSwitchAction.java-// --------------------------------------// (C) by Michael Peter Christen; [email protected]-// first published on http://www.anomic.de-// Frankfurt, Germany, 2005-// last major change: 11.05.2005-//-// This program is free software; you can redistribute it and/or modify-// it under the terms of the GNU General Public License as published by-// the Free Software Foundation; either version 2 of the License, or-// (at your option) any later version.-//-// This program is distributed in the hope that it will be useful,-// but WITHOUT ANY WARRANTY; without even the implied warranty of-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-// GNU General Public License for more details.-//-// You should have received a copy of the GNU General Public License-// along with this program; if not, write to the Free Software-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA--package de.anomic.server;--import net.yacy.kelondro.logging.Log;--public interface serverSwitchAction {-- // --------------------------------------------------------------------------- // the following methods are implemented by serverSwitchAsbtractAction- // and do not need to be altered-- public void setDescription(String shortText, String longText);- // sets a visible description string-- public String getShortDescription();- // returns short description string for online display-- public String getLongDescription();- // returns long description string for online display-- public void setLog(Log log);- // defines a log where process states can be written to-- // ---------------------------------------------------------------------- // the following methods are supposed to be implemented- // by extending a serverSwitchAbstractAction object-- public void doBevoreSetConfig(String key, String newvalue);- public void doAfterSetConfig(String key, String newvalue, String oldvalue);- public void doWhenGetConfig(String key, String actualvalue, String defaultvalue);-- public void close(); // called when an action is undeployed-}diff --git a/source/de/anomic/yacy/graphics/NetworkGraph.java b/source/de/anomic/yacy/graphics/NetworkGraph.javaindex 838baa2bc..eb064b818 100644--- a/source/de/anomic/yacy/graphics/NetworkGraph.java+++ b/source/de/anomic/yacy/graphics/NetworkGraph.java@@ -253,8 +253,6 @@ public class NetworkGraph {if (communicationTimeout >= 0) {Date horizon = new Date(System.currentTimeMillis() - communicationTimeout);for (Hit event: yacyChannel.channels(yacyChannel.DHTRECEIVE)) {- assert event != null;- assert event.getPubDate() != null;if (event == null || event.getPubDate() == null) continue;if (event.getPubDate().after(horizon)) {//System.out.println("*** NETWORK-DHTRECEIVE: " + event.getLink());diff --git a/source/net/yacy/kelondro/index/HandleMap.java b/source/net/yacy/kelondro/index/HandleMap.javaindex 080358cf1..5b221ba69 100644--- a/source/net/yacy/kelondro/index/HandleMap.java+++ b/source/net/yacy/kelondro/index/HandleMap.java@@ -248,19 +248,19 @@ public final class HandleMap implements Iterable<Row.Entry> {return add(key, -1);}- public final synchronized ArrayList<Long[]> removeDoubles() throws RowSpaceExceededException {- final ArrayList<Long[]> report = new ArrayList<Long[]>();- Long[] is;+ public final synchronized ArrayList<long[]> removeDoubles() throws RowSpaceExceededException {+ final ArrayList<long[]> report = new ArrayList<long[]>();+ long[] is;int c;long l;final int initialSize = this.size();for (final RowCollection rowset: index.removeDoubles()) {- is = new Long[rowset.size()];+ is = new long[rowset.size()];c = 0;for (Row.Entry e: rowset) {l = e.getColLong(1);assert l < initialSize : "l = " + l + ", initialSize = " + initialSize;- is[c++] = Long.valueOf(l);+ is[c++] = l;}report.add(is);}diff --git a/source/net/yacy/kelondro/table/Table.java b/source/net/yacy/kelondro/table/Table.javaindex 23f433a52..60c114618 100644--- a/source/net/yacy/kelondro/table/Table.java+++ b/source/net/yacy/kelondro/table/Table.java@@ -205,7 +205,7 @@ public class Table implements Index, Iterable<Row.Entry> {// remove doublesif (!freshFile) {- final ArrayList<Long[]> doubles = index.removeDoubles();+ final ArrayList<long[]> doubles = index.removeDoubles();//assert index.size() + doubles.size() + fail == i;//System.out.println(" -removed " + doubles.size() + " doubles- done.");if (!doubles.isEmpty()) {@@ -214,15 +214,15 @@ public class Table implements Index, Iterable<Row.Entry> {// first put back one element eachfinal byte[] record = new byte[rowdef.objectsize];key = new byte[rowdef.primaryKeyLength];- for (final Long[] ds: doubles) {- this.file.get(ds[0].intValue(), record, 0);+ for (final long[] ds: doubles) {+ this.file.get((int) ds[0], record, 0);System.arraycopy(record, 0, key, 0, rowdef.primaryKeyLength);- this.index.putUnique(key, ds[0].intValue());+ this.index.putUnique(key, (int) ds[0]);}// then remove the other doubles by removing them from the table, but do a re-indexing while doing that// first aggregate all the delete positions because the elements from the top positions must be removed firstfinal TreeSet<Long> delpos = new TreeSet<Long>();- for (final Long[] ds: doubles) {+ for (final long[] ds: doubles) {for (int j = 1; j < ds.length; j++) delpos.add(ds[j]);}// now remove the entries in a sorted way (top-down)@@ -381,11 +381,11 @@ public class Table implements Index, Iterable<Row.Entry> {RowSet rows;final TreeSet<Long> d = new TreeSet<Long>();final byte[] b = new byte[rowdef.objectsize];- Long L;+ long L;Row.Entry inconsistentEntry;// iterate over all entries that have inconsistent index referenceslong lastlog = System.currentTimeMillis();- ArrayList<Long[]> doubles;+ ArrayList<long[]> doubles;try {doubles = index.removeDoubles();} catch (RowSpaceExceededException e) {@@ -393,16 +393,16 @@ public class Table implements Index, Iterable<Row.Entry> {table = null;doubles = index.removeDoubles();}- for (final Long[] is: doubles) {+ for (final long[] is: doubles) {// 'is' is the set of all indexes, that have the same reference// we collect that entries now hererows = new RowSet(this.rowdef, is.length);for (int j = 0; j < is.length; j++) {L = is[j];- assert L.intValue() < file.size() : "L.intValue() = " + L.intValue() + ", file.size = " + file.size(); // prevent ooBounds Exception+ assert (int) L < file.size() : "L.intValue() = " + (int) L + ", file.size = " + file.size(); // prevent ooBounds Exceptiond.add(L);- if (L.intValue() >= file.size()) continue; // prevent IndexOutOfBoundsException- file.get(L.intValue(), b, 0); // TODO: fix IndexOutOfBoundsException here+ if ((int) L >= file.size()) continue; // prevent IndexOutOfBoundsException+ file.get((int) L, b, 0); // TODO: fix IndexOutOfBoundsException hereinconsistentEntry = rowdef.newEntry(b);try {rows.addUnique(inconsistentEntry);diff --git a/source/net/yacy/kelondro/util/FileUtils.java b/source/net/yacy/kelondro/util/FileUtils.javaindex f868cdde5..612ab3c33 100644--- a/source/net/yacy/kelondro/util/FileUtils.java+++ b/source/net/yacy/kelondro/util/FileUtils.java@@ -43,7 +43,6 @@ import java.io.Writer;import java.nio.charset.Charset;import java.util.ArrayList;import java.util.Comparator;-import java.util.HashMap;import java.util.HashSet;import java.util.Iterator;import java.util.LinkedList;@@ -52,6 +51,7 @@ import java.util.Map;import java.util.Set;import java.util.StringTokenizer;import java.util.TreeSet;+import java.util.concurrent.ConcurrentHashMap;import java.util.zip.GZIPInputStream;import java.util.zip.GZIPOutputStream;import java.util.zip.ZipEntry;@@ -393,7 +393,7 @@ public final class FileUtils {return set;}- public static Map<String, String> loadMap(final File f) {+ public static ConcurrentHashMap<String, String> loadMap(final File f) {// load propstry {final byte[] b = read(f);@@ -500,15 +500,14 @@ public final class FileUtils {forceMove(tf, file);}-- public static Map<String, String> table(Reader r) {+ public static ConcurrentHashMap<String, String> table(Reader r) {BufferedReader br = new BufferedReader(r);return table(new StringsIterator(br));}- public static Map<String, String> table(Iterator<String> li) {+ public static ConcurrentHashMap<String, String> table(Iterator<String> li) {String line;- final HashMap<String, String> props = new HashMap<String, String>();+ final ConcurrentHashMap<String, String> props = new ConcurrentHashMap<String, String>();while (li.hasNext()) {int pos = 0;line = li.next().trim();