default-button in profile menue

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@419 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
orbiter 20 years ago
parent b6d32f7f89
commit 86d778f7bc

@ -53,7 +53,8 @@
#{/table}#
<tr class="TableCellLight">
<td class="small" align="left" colspan="18">
<input type="submit" name="delaysubmit" value="Submit New Delay Values">
<input type="submit" name="submitdelay" value="Submit New Delay Values">&nbsp;&nbsp;&nbsp;
<input type="submit" name="submitdefault" value="Submit Default Values">&nbsp;&nbsp;&nbsp;
Changes take effect immediately</td>
</tr>
</form>

@ -44,6 +44,8 @@
// if the shell's current path is HTROOT
import java.util.Iterator;
import java.util.Map;
import java.io.File;
import org.apache.commons.pool.impl.GenericObjectPool;
@ -54,6 +56,7 @@ import de.anomic.server.serverCore;
import de.anomic.server.serverObjects;
import de.anomic.server.serverSwitch;
import de.anomic.server.serverThread;
import de.anomic.server.serverFileUtils;
public class Performance_p {
@ -61,7 +64,9 @@ public class Performance_p {
// return variable that accumulates replacements
plasmaSwitchboard switchboard = (plasmaSwitchboard) sb;
serverObjects prop = new serverObjects();
File defaultSettingsFile = new File(switchboard.getRootPath(), "yacy.init");
Map defaultSettings = ((post == null) || (!(post.containsKey("submitdefault")))) ? null : serverFileUtils.loadHashMap(defaultSettingsFile);
Iterator threads = switchboard.threadNames();
String threadName;
serverThread thread;
@ -116,15 +121,31 @@ public class Performance_p {
prop.put("table_" + c + "_sleeppercycle", ((idleCycles + busyCycles) == 0) ? "-" : ("" + (sleeptime / (idleCycles + busyCycles))));
prop.put("table_" + c + "_execpercycle", (busyCycles == 0) ? "-" : ("" + (exectime / busyCycles)));
if ((post != null) && (post.containsKey("delaysubmit"))) {
if ((post != null) && (post.containsKey("submitdelay"))) {
// load with new values
idlesleep = Long.parseLong((String) post.get(threadName + "_idlesleep", "100"));
busysleep = Long.parseLong((String) post.get(threadName + "_busysleep", "1000"));
idlesleep = Long.parseLong((String) post.get(threadName + "_idlesleep", "1000"));
busysleep = Long.parseLong((String) post.get(threadName + "_busysleep", "100"));
memprereq = Long.parseLong((String) post.get(threadName + "_memprereq", "0"));
// check values to prevent short-cut loops
if (idlesleep == 0) idlesleep = 1000;
if (idlesleep < 1000) idlesleep = 1000;
if (threadName.equals("10_httpd")) { idlesleep = 0; busysleep = 0; memprereq = 0; }
// on-the-fly re-configuration
switchboard.setThreadPerformance(threadName, idlesleep, busysleep, memprereq);
switchboard.setConfig(threadName + "_idlesleep", idlesleep);
switchboard.setConfig(threadName + "_busysleep", busysleep);
switchboard.setConfig(threadName + "_memprereq", memprereq);
} if ((post != null) && (post.containsKey("submitdefault"))) {
// load with new values
idlesleep = Long.parseLong(d((String) defaultSettings.get(threadName + "_idlesleep"), "1000"));
busysleep = Long.parseLong(d((String) defaultSettings.get(threadName + "_busysleep"), "100"));
memprereq = Long.parseLong(d((String) defaultSettings.get(threadName + "_memprereq"), "0"));
// check values to prevent short-cut loops
if (idlesleep < 1000) idlesleep = 1000;
if (threadName.equals("10_httpd")) { idlesleep = 0; busysleep = 0; memprereq = 0; }
// on-the-fly re-configuration
switchboard.setThreadPerformance(threadName, idlesleep, busysleep, memprereq);
switchboard.setConfig(threadName + "_idlesleep", idlesleep);
@ -133,8 +154,8 @@ public class Performance_p {
} else {
// load with old values
idlesleep = Long.parseLong(switchboard.getConfig(threadName + "_idlesleep" , "1000"));
busysleep = Long.parseLong(switchboard.getConfig(threadName + "_busysleep", "1000"));
memprereq = Long.parseLong(switchboard.getConfig(threadName + "_memprereq", "1000"));
busysleep = Long.parseLong(switchboard.getConfig(threadName + "_busysleep", "100"));
memprereq = Long.parseLong(switchboard.getConfig(threadName + "_memprereq", "0"));
}
prop.put("table_" + c + "_idlesleep", idlesleep);
prop.put("table_" + c + "_busysleep", busysleep);
@ -219,4 +240,7 @@ public class Performance_p {
return prop;
}
private static String d(String a, String b) {
return (a == null) ? b : a;
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 824 B

After

Width:  |  Height:  |  Size: 836 B

@ -193,7 +193,7 @@ public final class httpdProxyHandler extends httpdAbstractHandler implements htt
// load the yellow-list
f = switchboard.getConfig("proxyYellowList", null);
if (f != null) {
yellowList = serverFileUtils.loadSet("yellow", f);
yellowList = serverFileUtils.loadSet(f);
this.theLogger.logSystem("loaded yellow-list from file " + f + ", " + yellowList.size() + " entries");
} else {
yellowList = new HashSet();

@ -85,10 +85,10 @@ public abstract class serverAbstractSwitch implements serverSwitch {
// predefine init's
Map initProps;
if (initFile.exists()) initProps = loadHashMap(initFile); else initProps = new HashMap();
if (initFile.exists()) initProps = serverFileUtils.loadHashMap(initFile); else initProps = new HashMap();
// load config's from last save
if (configFile.exists()) configProps = loadHashMap(configFile); else configProps = new HashMap();
if (configFile.exists()) configProps = serverFileUtils.loadHashMap(configFile); else configProps = new HashMap();
synchronized (configProps) {
@ -131,41 +131,6 @@ public abstract class serverAbstractSwitch implements serverSwitch {
return log;
}
public static Map loadHashMap(File f) {
// load props
Properties prop = new Properties();
BufferedInputStream bufferedIn = null;
try {
prop.load(bufferedIn = new BufferedInputStream(new FileInputStream(f)));
} catch (IOException e1) {
System.err.println("ERROR: " + f.toString() + " not found in settings path");
prop = null;
} finally {
if (bufferedIn != null)try{bufferedIn.close();}catch(Exception e){}
}
return (Hashtable) prop;
}
public static void saveMap(File f, Map props, String comment) throws IOException {
PrintWriter pw = null;
try {
pw = new PrintWriter(new BufferedOutputStream(new FileOutputStream(f)));
pw.println("# " + comment);
Iterator i = props.entrySet().iterator();
String key, value;
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");
} finally {
if (pw!=null)try{pw.close();}catch(Exception e){}
}
}
public void setConfig(String key, long value) {
setConfig(key, "" + value);
}
@ -230,7 +195,7 @@ public abstract class serverAbstractSwitch implements serverSwitch {
private void saveConfig() {
try {
saveMap(configFile, configProps, configComment);
serverFileUtils.saveMap(configFile, configProps, configComment);
} catch (IOException e) {
System.out.println("ERROR: cannot write config file " + configFile.toString() + ": " + e.getMessage());
}

@ -50,8 +50,16 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.PrintWriter;
import java.util.zip.GZIPOutputStream;
import java.util.HashSet;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.Hashtable;
import java.util.Iterator;
public final class serverFileUtils {
@ -145,7 +153,7 @@ public final class serverFileUtils {
copy(new ByteArrayInputStream(source), dest);
}
public static HashSet loadSet(String setname, String filename) {
public static HashSet loadSet(String filename) {
HashSet set = new HashSet();
BufferedReader br = null;
try {
@ -163,4 +171,39 @@ public final class serverFileUtils {
return set;
}
public static Map loadHashMap(File f) {
// load props
Properties prop = new Properties();
BufferedInputStream bufferedIn = null;
try {
prop.load(bufferedIn = new BufferedInputStream(new FileInputStream(f)));
} catch (IOException e1) {
System.err.println("ERROR: " + f.toString() + " not found in settings path");
prop = null;
} finally {
if (bufferedIn != null)try{bufferedIn.close();}catch(Exception e){}
}
return (Hashtable) prop;
}
public static void saveMap(File f, Map props, String comment) throws IOException {
PrintWriter pw = null;
try {
pw = new PrintWriter(new BufferedOutputStream(new FileOutputStream(f)));
pw.println("# " + comment);
Iterator i = props.entrySet().iterator();
String key, value;
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");
} finally {
if (pw!=null)try{pw.close();}catch(Exception e){}
}
}
}

Loading…
Cancel
Save