Skip to content

Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance

implemented serverSwitchActions - action-hooks

orbiterb4030e5023d0
diff --git a/htroot/Config_p.java b/htroot/Config_p.java
index 3d47a4115..d5b15f2c3 100644
--- a/htroot/Config_p.java
+++ b/htroot/Config_p.java
@@ -46,7 +46,7 @@
// javac -classpath .:../Classes Config_p.java
// if the shell's current path is HTROOT
-import java.util.Enumeration;
+import java.util.Iterator;
import de.anomic.http.httpHeader;
import de.anomic.server.serverObjects;
@@ -58,7 +58,7 @@ public class Config_p {
// return variable that accumulates replacements
serverObjects prop = new serverObjects();
int count=0;
- Enumeration keys = env.configKeys();
+ Iterator keys = env.configKeys();
String key="";
//change a Key
@@ -70,8 +70,8 @@ public class Config_p {
}
}
- while(keys.hasMoreElements()){
- key=(String)keys.nextElement();
+ while(keys.hasNext()){
+ key=(String)keys.next();
prop.put("options_"+count+"_key", key);
prop.put("options_"+count+"_value", env.getConfig(key, "ERROR"));
count++;
diff --git a/htroot/yacy/transferRWI.java b/htroot/yacy/transferRWI.java
index 8bb66cd2b..f68e93176 100644
--- a/htroot/yacy/transferRWI.java
+++ b/htroot/yacy/transferRWI.java
@@ -123,9 +123,9 @@ public class transferRWI {
while (it.hasNext()) unknownURLs += "," + (String) it.next();
if (unknownURLs.length() > 0) unknownURLs = unknownURLs.substring(1);
if (wordhashes.length == 0)
- switchboard.log.logInfo("Received 0 Words from peer " + iam + ", requested " + unknownURL.size() + " URL's");
+ switchboard.getLog().logInfo("Received 0 Words from peer " + iam + ", requested " + unknownURL.size() + " URL's");
else
- switchboard.log.logInfo("Received " + received + " Words [" + wordhashes[0] + " .. " + wordhashes[wordhashes.length - 1] + "] from peer " + iam + ", requested " + unknownURL.size() + " URL's");
+ switchboard.getLog().logInfo("Received " + received + " Words [" + wordhashes[0] + " .. " + wordhashes[wordhashes.length - 1] + "] from peer " + iam + ", requested " + unknownURL.size() + " URL's");
result = "ok";
} else {
result = "error_not_granted";
diff --git a/htroot/yacy/transferURL.java b/htroot/yacy/transferURL.java
index 75def96eb..ba2ad78f0 100644
--- a/htroot/yacy/transferURL.java
+++ b/htroot/yacy/transferURL.java
@@ -87,8 +87,8 @@ public class transferURL {
// return rewrite properties
int more = switchboard.loadedURL.size() - sizeBefore;
doublevalues = "" + (received - more);
- switchboard.log.logInfo("Received " + received + " URL's from peer " + iam);
- if ((received - more) > 0) switchboard.log.logError("Received " + doublevalues + " double URL's from peer " + iam);
+ switchboard.getLog().logInfo("Received " + received + " URL's from peer " + iam);
+ if ((received - more) > 0) switchboard.getLog().logError("Received " + doublevalues + " double URL's from peer " + iam);
result = "ok";
} else {
result = "error_not_granted";
diff --git a/makerelease.sh b/makerelease.sh
index 6e616b041..6f78f1266 100755
--- a/makerelease.sh
+++ b/makerelease.sh
@@ -45,7 +45,7 @@
# Contributions and changes to the program code must be marked as such.
# define variables
-version='0.372'
+version='0.373'
datestr=`date +%Y%m%d`
#release='yacy_v'$version'_'$datestr
release='yacy_dev_v'$version'_'$datestr
diff --git a/source/de/anomic/plasma/plasmaHTCache.java b/source/de/anomic/plasma/plasmaHTCache.java
index 4d1b2fdd9..23cbc74a2 100644
--- a/source/de/anomic/plasma/plasmaHTCache.java
+++ b/source/de/anomic/plasma/plasmaHTCache.java
@@ -360,7 +360,8 @@ public final class plasmaHTCache {
public static boolean isText(httpHeader response) {
Object ct = response.get("Content-Type");
if (ct == null) return false;
- return ((String)ct).toUpperCase().startsWith("TEXT");
+ String t = ((String)ct).toLowerCase();
+ return ((t.startsWith("text")) || (t.equals("application/xhtml+xml")));
}
public static boolean noIndexingURL(String urlString) {
diff --git a/source/de/anomic/plasma/plasmaSwitchboard.java b/source/de/anomic/plasma/plasmaSwitchboard.java
index 656150ba5..30786cb92 100644
--- a/source/de/anomic/plasma/plasmaSwitchboard.java
+++ b/source/de/anomic/plasma/plasmaSwitchboard.java
@@ -170,7 +170,6 @@ public class plasmaSwitchboard extends serverAbstractSwitch implements serverSwi
public plasmaHTCache cacheManager;
public plasmaCrawlLoader cacheLoader;
public LinkedList processStack = new LinkedList();
- public serverLog log;
public messageBoard messageDB;
public wikiBoard wikiDB;
public String remoteProxyHost;
@@ -191,9 +190,9 @@ public class plasmaSwitchboard extends serverAbstractSwitch implements serverSwi
public plasmaSwitchboard(String rootPath, String initPath, String configPath) throws IOException {
super(rootPath, initPath, configPath);
- // set loglevel
+ // set loglevel and log
int loglevel = Integer.parseInt(getConfig("plasmaLoglevel", "2"));
- log = new serverLog("PLASMA", loglevel);
+ setLog(new serverLog("PLASMA", loglevel));
// load values from configs
plasmaPath = new File(rootPath, getConfig("dbPath", "DATABASE"));
@@ -308,22 +307,22 @@ public class plasmaSwitchboard extends serverAbstractSwitch implements serverSwi
// deploy threads
deployThread("90_cleanup", "Cleanup", "simple cleaning process for monitoring information" ,
- new serverInstantThread(this, "cleanupJob", "cleanupJobSize"), log, 10000); // all 5 Minutes
+ new serverInstantThread(this, "cleanupJob", "cleanupJobSize"), 10000); // all 5 Minutes
deployThread("80_dequeue", "Indexing Dequeue", "thread that creates database entries from scraped web content and performes indexing" ,
- new serverInstantThread(this, "deQueue", "queueSize"), log, 10000);
+ new serverInstantThread(this, "deQueue", "queueSize"), 10000);
deployThread("70_cachemanager", "Proxy Cache Enqueue", "job takes new proxy files from RAM stack, stores them, and hands over to the Indexing Stack",
- new serverInstantThread(cacheManager, "job", "size"), log, 10000);
+ new serverInstantThread(cacheManager, "job", "size"), 10000);
deployThread("60_globalcrawl", "Global Crawl", "thread that performes a single crawl/indexing step of a web page for global crawling",
- new serverInstantThread(this, "globalCrawlJob", "globalCrawlJobSize"), log, 30000);
+ new serverInstantThread(this, "globalCrawlJob", "globalCrawlJobSize"), 30000);
deployThread("50_localcrawl", "Local Crawl", "thread that performes a single crawl step from the local crawl queue",
- new serverInstantThread(this, "localCrawlJob", "localCrawlJobSize"), log, 10000);
+ new serverInstantThread(this, "localCrawlJob", "localCrawlJobSize"), 10000);
deployThread("40_peerseedcycle", "Seed-List Upload", "task that a principal peer performes to generate and upload a seed-list to a ftp account",
- new serverInstantThread(yc, "publishSeedList", null), yc.log, 180000);
+ new serverInstantThread(yc, "publishSeedList", null), 180000);
deployThread("30_peerping", "YaCy Core", "this is the p2p-control and peer-ping task",
- new serverInstantThread(yc, "peerPing", null), yc.log, 2000);
+ new serverInstantThread(yc, "peerPing", null), 2000);
indexDistribution = new distributeIndex(100 /*indexCount*/, 8000, 1 /*peerCount*/);
deployThread("20_dhtdistribution", "DHT Distribution (currently by juniors only)", "selection, transfer and deletion of index entries that are not searched on your peer, but on others",
- new serverInstantThread(indexDistribution, "job", null), log, 120000);
+ new serverInstantThread(indexDistribution, "job", null), 120000);
}
private static String ppRamString(int bytes) {
diff --git a/source/de/anomic/server/serverAbstractSwitch.java b/source/de/anomic/server/serverAbstractSwitch.java
index dbeae093a..f9cf1b39c 100644
--- a/source/de/anomic/server/serverAbstractSwitch.java
+++ b/source/de/anomic/server/serverAbstractSwitch.java
@@ -48,6 +48,8 @@ import java.io.PrintWriter;
import java.net.InetAddress;
import java.util.Enumeration;
import java.util.Hashtable;
+import java.util.Map;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.Properties;
import java.util.TreeMap;
@@ -56,12 +58,14 @@ public abstract class serverAbstractSwitch implements serverSwitch {
// configuration management
private final File configFile;
- private Hashtable configProps;
+ private Map configProps;
private final String configComment;
- private final Hashtable authorization;
- private String rootPath;
+ private final HashMap authorization;
+ private String rootPath;
private final TreeMap workerThreads;
- protected int serverJobs;
+ private final TreeMap switchActions;
+ protected serverLog log;
+ protected int serverJobs;
public serverAbstractSwitch(String rootPath, String initPath, String configPath) throws IOException {
// we initialize the switchboard with a property file,
@@ -77,20 +81,18 @@ public abstract class serverAbstractSwitch implements serverSwitch {
new File(configFile.getParent()).mkdir();
// predefine init's
- Hashtable initProps;
- if (initFile.exists()) initProps = loadHashtable(initFile); else initProps = new Hashtable();
+ Map initProps;
+ if (initFile.exists()) initProps = loadHashMap(initFile); else initProps = new HashMap();
// load config's from last save
- if (configFile.exists()) configProps = loadHashtable(configFile); else configProps = new Hashtable();
+ if (configFile.exists()) configProps = loadHashMap(configFile); else configProps = new HashMap();
// remove all values from config that do not appear in init (out-dated settings)
- Enumeration e = configProps.keys();
+ Iterator i = configProps.keySet().iterator();
String key;
- while (e.hasMoreElements()) {
- key = (String) e.nextElement();
- //System.out.println("TESTING " + key);
+ while (i.hasNext()) {
+ key = (String) i.next();
if (!(initProps.containsKey(key))) {
- //System.out.println("MIGRATE: removing out-dated property '" + key + "'");
configProps.remove(key);
}
}
@@ -104,16 +106,28 @@ public abstract class serverAbstractSwitch implements serverSwitch {
saveConfig();
// other settings
- authorization = new Hashtable();
+ authorization = new HashMap();
// init thread control
workerThreads = new TreeMap();
+ // init switch actions
+ switchActions = new TreeMap();
+
// init busy state control
serverJobs = 0;
}
- public static Hashtable loadHashtable(File f) {
+ // a logger for this switchboard
+ public void setLog(serverLog log) {
+ this.log = log;
+ }
+
+ public serverLog getLog() {
+ return log;
+ }
+
+ public static Map loadHashMap(File f) {
// load props
Properties prop = new Properties();
try {
@@ -125,15 +139,16 @@ public abstract class serverAbstractSwitch implements serverSwitch {
return (Hashtable) prop;
}
- public static void saveHashtable(File f, Hashtable props, String comment) throws IOException {
+ public static void saveMap(File f, Map props, String comment) throws IOException {
PrintWriter pw = new PrintWriter(new FileOutputStream(f));
pw.println("# " + comment);
- Enumeration e = props.keys();
+ Iterator i = props.entrySet().iterator();
String key, value;
- while (e.hasMoreElements()) {
- key = (String) e.nextElement();
- //value = (String) props.get(key);
- value = ((String) props.get(key)).replaceAll("\n", "\\\\n");
+ Map.Entry entry;
+ while (i.hasNext()) {
+ entry = (Map.Entry) i.next();
+ key = (String) entry.getKey();
+ value = ((String) entry.getValue()).replaceAll("\n", "\\\\n");
pw.println(key + "=" + value);
}
pw.println("# EOF");
@@ -143,37 +158,95 @@ public abstract class serverAbstractSwitch implements serverSwitch {
public void setConfig(String key, long value) {
setConfig(key, "" + value);
}
-
+
public void setConfig(String key, String value) {
- configProps.put(key, value);
+ // perform action before setting new value
+ Map.Entry entry;
+ serverSwitchAction action;
+ Iterator i = switchActions.entrySet().iterator();
+ while (i.hasNext()) {
+ entry = (Map.Entry) i.next();
+ action = (serverSwitchAction) entry.getValue();
+ try {
+ action.doBevoreSetConfig(key, value);
+ } catch (Exception e) {
+ log.logError("serverAction bevoreSetConfig '" + action.getShortDescription() + "' failed with exception: " + e.getMessage());
+ }
+ }
+
+ // set the value
+ String oldValue = (String) configProps.put(key, value);
saveConfig();
+
+ // perform actions afterwards
+ i = switchActions.entrySet().iterator();
+ while (i.hasNext()) {
+ entry = (Map.Entry) i.next();
+ action = (serverSwitchAction) entry.getValue();
+ try {
+ action.doAfterSetConfig(key, value, oldValue);
+ } catch (Exception e) {
+ log.logError("serverAction afterSetConfig '" + action.getShortDescription() + "' failed with exception: " + e.getMessage());
+ }
+ }
}
public String getConfig(String key, String dflt) {
+ // get the value
String s = (String) configProps.get(key);
+
+ // do action
+ Map.Entry entry;
+ serverSwitchAction action;
+ Iterator i = switchActions.entrySet().iterator();
+ while (i.hasNext()) {
+ entry = (Map.Entry) i.next();
+ action = (serverSwitchAction) entry.getValue();
+ try {
+ action.doWhenGetConfig(key, s, dflt);
+ } catch (Exception e) {
+ log.logError("serverAction whenGetConfig '" + action.getShortDescription() + "' failed with exception: " + e.getMessage());
+ }
+ }
+
+ // return value
if (s == null) return dflt; else return s;
}
- public Enumeration configKeys() {
- return configProps.keys();
+ public Iterator configKeys() {
+ return configProps.keySet().iterator();
}
private void saveConfig() {
try {
- saveHashtable(configFile, configProps, configComment);
+ saveMap(configFile, configProps, configComment);
} catch (IOException e) {
System.out.println("ERROR: cannot write config file " + configFile.toString() + ": " + e.getMessage());
}
}
- public void deployThread(String threadName, String threadShortDescription, String threadLongDescription, serverThread newThread, serverLog log, long startupDelay) {
+
+ // add/remove action listener
+ public void deployAction(String actionName, String actionShortDescription, String actionLongDescription,
+ serverSwitchAction newAction) {
+ newAction.setLog(log);
+ newAction.setDescription(actionShortDescription, actionLongDescription);
+ switchActions.put(actionName, newAction);
+ }
+
+ public void undeployAction(String actionName) {
+ switchActions.remove(actionName);
+ }
+
+
+ public void deployThread(String threadName, String threadShortDescription, String threadLongDescription, serverThread newThread, long startupDelay) {
deployThread(threadName, threadShortDescription, threadLongDescription,
- newThread, log, startupDelay,
+ newThread, startupDelay,
Long.parseLong(getConfig(threadName + "_idlesleep" , "novalue")),
Long.parseLong(getConfig(threadName + "_busysleep" , "novalue")));
}
- public void deployThread(String threadName, String threadShortDescription, String threadLongDescription, serverThread newThread, serverLog log, long startupDelay, long initialIdleSleep, long initialBusySleep) {
+ public void deployThread(String threadName, String threadShortDescription, String threadLongDescription, serverThread newThread, long startupDelay, long initialIdleSleep, long initialBusySleep) {
if (newThread.isAlive()) throw new RuntimeException("undeployed threads must not live; they are started as part of the deployment");
newThread.setStartupSleep(startupDelay);
long sleep;
diff --git a/source/de/anomic/server/serverSwitch.java b/source/de/anomic/server/serverSwitch.java
index 6022e72e0..2f628089d 100644
--- a/source/de/anomic/server/serverSwitch.java
+++ b/source/de/anomic/server/serverSwitch.java
@@ -53,15 +53,24 @@ import java.util.Iterator;
public interface serverSwitch {
// the root path for the application
public String getRootPath();
-
- // the switchboard can be used to set and read properties
- public void setConfig(String key, String value);
- public String getConfig(String key, String dflt);
- public Enumeration configKeys();
+
+ // a logger for this switchboard
+ public void setLog(serverLog log);
+ public serverLog getLog();
+
+ // a switchboard can have action listener
+ // these listeners are hooks for numerous methods below
+ public void deployAction(String actionName,
+ String actionShortDescription,
+ String actionLongDescription,
+ serverSwitchAction action);
+ public void undeployAction(String actionName);
// the switchboard can manage worker threads
- public void deployThread(String threadName, String threadShortDescription, String threadLongDescription,
- serverThread newThread, serverLog log,
+ public void deployThread(String threadName,
+ String threadShortDescription,
+ String threadLongDescription,
+ serverThread newThread,
long startupDelay, long initialIdleSleep, long initialBusySleep);
public serverThread getThread(String threadName);
public void setThreadSleep(String threadName, long idleMillis, long busyMillis);
@@ -69,6 +78,11 @@ public interface serverSwitch {
public void terminateAllThreads(boolean waitFor);
public Iterator /*of serverThread-Names (String)*/ threadNames();
+ // the switchboard can be used to set and read properties
+ public void setConfig(String key, String value);
+ public String getConfig(String key, String dflt);
+ public Iterator configKeys();
+
// the switchboard also shall maintain a job list
// jobs can be queued by submitting a job object
// to work off a queue job, use deQueue, which is meant to
diff --git a/source/yacy.java b/source/yacy.java
index f4881c06a..4bcddf01f 100644
--- a/source/yacy.java
+++ b/source/yacy.java
@@ -252,7 +252,7 @@ public final class yacy {
serverLog.logFailure("STARTUP", "Failed to start server. Probably port " + port + " already in use.");
} else {
// first start the server
- sb.deployThread("10_httpd", "HTTPD Server/Proxy", "the HTTPD, used as web server and proxy", server, null, 0, 0, 0);
+ sb.deployThread("10_httpd", "HTTPD Server/Proxy", "the HTTPD, used as web server and proxy", server, 0, 0, 0);
//server.start();
// open the browser window
diff --git a/yacy.parser b/yacy.parser
index 47a600f8d..1df65f6a4 100644
--- a/yacy.parser
+++ b/yacy.parser
@@ -1,2 +1,2 @@
#plasmaParser configuration file
-#Sun May 08 22:26:31 CEST 2005
+#Wed May 11 13:47:09 CEST 2005