Author: toad
Date: 2008-04-23 14:40:50 +0000 (Wed, 23 Apr 2008)
New Revision: 19528
Modified:
trunk/freenet/src/freenet/clients/http/ConfigToadlet.java
trunk/freenet/src/freenet/config/WrapperConfig.java
trunk/freenet/src/freenet/l10n/freenet.l10n.en.properties
Log:
Make memory usage configurable on the config page.
Modified: trunk/freenet/src/freenet/clients/http/ConfigToadlet.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/ConfigToadlet.java 2008-04-23
13:39:06 UTC (rev 19527)
+++ trunk/freenet/src/freenet/clients/http/ConfigToadlet.java 2008-04-23
14:40:50 UTC (rev 19528)
@@ -14,6 +14,7 @@
import freenet.config.InvalidConfigValueException;
import freenet.config.Option;
import freenet.config.SubConfig;
+import freenet.config.WrapperConfig;
import freenet.l10n.L10n;
import freenet.node.Node;
import freenet.node.NodeClientCore;
@@ -83,6 +84,16 @@
}
}
}
+
+ // Wrapper params
+ String wrapperConfigName = "wrapper.java.maxmemory";
+ if(request.isPartSet(wrapperConfigName)) {
+ String value =
request.getPartAsString(wrapperConfigName, MAX_PARAM_VALUE_SIZE);
+
if(!WrapperConfig.getWrapperProperty(wrapperConfigName).equals(value)) {
+ if(logMINOR) Logger.minor(this,
"Setting "+wrapperConfigName+" to "+value);
+
WrapperConfig.setWrapperProperty(wrapperConfigName, value);
+ }
+ }
}
core.storeConfig();
@@ -149,6 +160,21 @@
HTMLNode configNode = infobox.addChild("div", "class",
"infobox-content");
HTMLNode formNode = ctx.addFormChild(configNode, ".",
"configForm");
+ if(WrapperConfig.canChangeProperties()) {
+ formNode.addChild("div", "class", "configprefix",
l10n("wrapper"));
+ HTMLNode list = formNode.addChild("ul", "class",
"config");
+ HTMLNode item = list.addChild("li");
+ String configName = "wrapper.java.maxmemory";
+ // FIXME how to get the real default???
+ String defaultValue = "128";
+ String curValue =
WrapperConfig.getWrapperProperty(configName);
+ item.addChild("span", new String[]{ "class", "title",
"style" },
+ new String[]{ "configshortdesc",
L10n.getString("ConfigToadlet.defaultIs", new String[] { "default" }, new
String[] { defaultValue }),
+ "cursor: help;"
}).addChild(L10n.getHTMLNode("WrapperConfig."+configName+".short"));
+ item.addChild("span", "class",
"config").addChild("input", new String[] { "type", "class", "name", "value" },
new String[] { "text", "config", configName, curValue });
+ item.addChild("span", "class",
"configlongdesc").addChild(L10n.getHTMLNode("WrapperConfig."+configName+".long"));
+ }
+
for(int i=0; i<sc.length;i++){
short displayedConfigElements = 0;
Modified: trunk/freenet/src/freenet/config/WrapperConfig.java
===================================================================
--- trunk/freenet/src/freenet/config/WrapperConfig.java 2008-04-23 13:39:06 UTC
(rev 19527)
+++ trunk/freenet/src/freenet/config/WrapperConfig.java 2008-04-23 14:40:50 UTC
(rev 19528)
@@ -15,24 +15,40 @@
import freenet.node.NodeInitException;
import freenet.support.Logger;
import freenet.support.io.Closer;
+import freenet.support.io.FileUtil;
/**
* Class to allow us to easily change wrapper properties.
* @author toad
*/
public class WrapperConfig {
-
- public String getWrapperProperty(String name) {
+
+ public static String getWrapperProperty(String name) {
return WrapperManager.getProperties().getProperty(name, null);
}
- public boolean canChangeProperties() {
- if(!WrapperManager.isControlledByNativeWrapper()) return false;
+ public static boolean canChangeProperties() {
+ if(!WrapperManager.isControlledByNativeWrapper()) {
+ Logger.normal(WrapperConfig.class, "Cannot alter
properties: not running under wrapper");
+ return false;
+ }
File f = new File("wrapper.conf");
- if(!f.exists()) return false;
- if(!f.canRead()) return false;
- if(!f.canWrite()) return false;
- if(!f.getParentFile().canWrite()) return false; // Can we
create a file in order to rename over wrapper.conf?
+ if(!f.exists()) {
+ Logger.normal(WrapperConfig.class, "Cannot alter
properties: wrapper.conf does not exist");
+ return false;
+ }
+ if(!f.canRead()) {
+ Logger.normal(WrapperConfig.class, "Cannot alter
properties: wrapper.conf not readable");
+ return false;
+ }
+ if(!f.canWrite()) {
+ Logger.normal(WrapperConfig.class, "Cannot alter
properties: wrapper.conf not writable");
+ return false;
+ }
+ if(!FileUtil.getCanonicalFile(f).getParentFile().canWrite()) {
+ Logger.normal(WrapperConfig.class, "Cannot alter
properties: parent dir not writable");
+ return false; // Can we create a file in order to
rename over wrapper.conf?
+ }
return true;
}
@@ -42,7 +58,7 @@
* @param value The value to set it to.
* @return True if the property was successfully updated.
*/
- public synchronized boolean setWrapperProperty(String name, String
value) {
+ public static synchronized boolean setWrapperProperty(String name,
String value) {
// Some of this copied from UpdateDeployContext, hence no GPL
header on this file as none there.
File oldConfig = new File("wrapper.conf");
@@ -93,7 +109,7 @@
fis = null;
fos = null;
if(oldConfig.exists()) newConfig.delete();
- Logger.error(this, "Cannot update wrapper property
"+"name: "+e, e);
+ Logger.error(WrapperConfig.class, "Cannot update
wrapper property "+"name: "+e, e);
System.err.println("Unable to update wrapper property
"+name+" : "+e);
return false;
} finally {
@@ -108,19 +124,19 @@
oldOldConfig =
File.createTempFile("wrapper.conf", ".old.tmp", new File("."));
} catch (IOException e) {
String error = "Unable to create
temporary file and unable to copy wrapper.conf to wrapper.conf.old. Could not
update wrapper.conf trying to set property "+name;
- Logger.error(this, error);
+ Logger.error(WrapperConfig.class,
error);
System.err.println(error);
return false;
}
if(!oldConfig.renameTo(oldOldConfig)) {
String error = "Unable to change property
"+name+": Could not move old config file "+oldConfig+", so could not rename new
config file "+newConfig+" over it (already tried without deleting.";
- Logger.error(this, error);
+ Logger.error(WrapperConfig.class, error);
System.err.println(error);
return false;
}
if(!newConfig.renameTo(oldConfig)) {
String error = "Unable to rename "+newConfig+"
to "+oldConfig+" even after moving the old config file out of the way! Trying
to restore previous config file so the node will start up...";
- Logger.error(this, error);
+ Logger.error(WrapperConfig.class, error);
System.err.println(error);
if(!oldOldConfig.renameTo(oldConfig)) {
System.err.println("CATASTROPHIC UPDATE
ERROR: Unable to rename backup copy of config file over the current config
file, after failing to update config file! The node will not boot until you get
a new wrapper.conf!\n"+
@@ -129,6 +145,7 @@
}
}
}
+ WrapperManager.getProperties().setProperty(name, value);
return true;
}
Modified: trunk/freenet/src/freenet/l10n/freenet.l10n.en.properties
===================================================================
--- trunk/freenet/src/freenet/l10n/freenet.l10n.en.properties 2008-04-23
13:39:06 UTC (rev 19527)
+++ trunk/freenet/src/freenet/l10n/freenet.l10n.en.properties 2008-04-23
14:40:50 UTC (rev 19528)
@@ -102,6 +102,8 @@
ConfigToadlet.title=Freenet Node Configuration
ConfigToadlet.toadletsymlinker=toadletsymlinker
ConfigToadlet.true=true
+ConfigToadlet.wrapperSettingsTitle=Wrapper Settings
+ConfigToadlet.wrapper=wrapper
ConfigurablePersister.doesNotExistCannotCreate=File does not exist and cannot
be created
ConfigurablePersister.existsCannotReadWrite=File exists and cannot read/write
it
ConnectivityToadlet.byIPTitle=Packets for ${ip} by IP address - ${status}
(minimum tunnel lifetime ${tunnelLength})
@@ -1245,4 +1247,6 @@
WelcomeToadlet.version=Freenet ${fullVersion} Build #${build} r${rev}
WelcomeToadlet.versionHeader=Version Information & Node Control
WelcomeToadlet.writtenDatabaseStats=Runtime database statistics have been
written to the wrapper logfile
+WrapperConfig.wrapper.java.maxmemory.short=Maximum memory (in megabytes)
+WrapperConfig.wrapper.java.maxmemory.long=Limit on memory used by Freenet.
Freenet will need more memory if you have more queued requests, and to a lesser
extent if you have a larger datastore. Changes will not take effect until
Freenet has been restarted.
End