Author: j16sdiz
Date: 2008-08-14 13:44:45 +0000 (Thu, 14 Aug 2008)
New Revision: 21839
Modified:
trunk/freenet/src/freenet/clients/http/SimpleToadletServer.java
trunk/freenet/src/freenet/config/BooleanOption.java
trunk/freenet/src/freenet/config/ConfigCallback.java
trunk/freenet/src/freenet/config/IntOption.java
trunk/freenet/src/freenet/config/LongOption.java
trunk/freenet/src/freenet/config/Option.java
trunk/freenet/src/freenet/config/ShortOption.java
trunk/freenet/src/freenet/config/StringArrOption.java
trunk/freenet/src/freenet/config/StringOption.java
trunk/freenet/src/freenet/config/SubConfig.java
trunk/freenet/src/freenet/crypt/SSL.java
trunk/freenet/src/freenet/node/LoggingConfigHandler.java
trunk/freenet/src/freenet/node/Node.java
trunk/freenet/src/freenet/node/NodeClientCore.java
trunk/freenet/src/freenet/node/NodeCryptoConfig.java
trunk/freenet/src/freenet/node/NodeIPDetector.java
trunk/freenet/src/freenet/node/NodeStats.java
trunk/freenet/src/freenet/node/TestnetHandler.java
trunk/freenet/src/freenet/node/TextModeClientInterfaceServer.java
trunk/freenet/src/freenet/node/fcp/FCPServer.java
trunk/freenet/src/freenet/node/updater/NodeUpdateManager.java
trunk/freenet/src/freenet/support/Fields.java
trunk/freenet/src/freenet/support/api/BooleanCallback.java
trunk/freenet/src/freenet/support/api/IntCallback.java
trunk/freenet/src/freenet/support/api/LongCallback.java
trunk/freenet/src/freenet/support/api/ShortCallback.java
trunk/freenet/src/freenet/support/api/StringArrCallback.java
trunk/freenet/src/freenet/support/api/StringCallback.java
Log:
more Generic, simplify the config system
Modified: trunk/freenet/src/freenet/clients/http/SimpleToadletServer.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/SimpleToadletServer.java
2008-08-14 13:33:41 UTC (rev 21838)
+++ trunk/freenet/src/freenet/clients/http/SimpleToadletServer.java
2008-08-14 13:44:45 UTC (rev 21839)
@@ -82,10 +82,10 @@
class FProxySSLCallback extends BooleanCallback {
- public boolean get() {
+ public Boolean get() {
return ssl;
}
- public void set(boolean val) throws InvalidConfigValueException
{
+ public void set(Boolean val) throws InvalidConfigValueException
{
if(val == get()) return;
if(!SSL.available()) {
throw new InvalidConfigValueException("Enable
SSL support before use ssl with Fproxy");
@@ -100,11 +100,11 @@
class FProxyPassthruMaxSize extends IntCallback {
- public int get() {
+ public Integer get() {
return FProxyToadlet.MAX_LENGTH;
}
- public void set(int val) throws InvalidConfigValueException {
+ public void set(Integer val) throws InvalidConfigValueException
{
if(val == get()) return;
FProxyToadlet.MAX_LENGTH = val;
}
@@ -112,11 +112,11 @@
class FProxyPortCallback extends IntCallback {
- public int get() {
+ public Integer get() {
return port;
}
- public void set(int newPort) throws InvalidConfigValueException
{
+ public void set(Integer newPort) throws
InvalidConfigValueException {
if(port != newPort)
throw new
InvalidConfigValueException(L10n.getString("cannotChangePortOnTheFly"));
// FIXME
@@ -206,12 +206,12 @@
class FProxyEnabledCallback extends BooleanCallback {
- public boolean get() {
+ public Boolean get() {
synchronized(SimpleToadletServer.this) {
return myThread != null;
}
}
- public void set(boolean val) throws InvalidConfigValueException
{
+ public void set(Boolean val) throws InvalidConfigValueException
{
if(val == get()) return;
synchronized(SimpleToadletServer.this) {
if(val) {
@@ -254,11 +254,11 @@
this.ts = ts;
}
- public boolean get() {
+ public Boolean get() {
return ts.isAdvancedModeEnabled();
}
- public void set(boolean val) throws InvalidConfigValueException
{
+ public void set(Boolean val) throws InvalidConfigValueException
{
if(val == get()) return;
ts.enableAdvancedMode(val);
}
@@ -272,11 +272,11 @@
this.ts = ts;
}
- public boolean get() {
+ public Boolean get() {
return ts.isFProxyJavascriptEnabled();
}
- public void set(boolean val) throws InvalidConfigValueException
{
+ public void set(Boolean val) throws InvalidConfigValueException
{
if(val == get()) return;
ts.enableFProxyJavascript(val);
}
@@ -357,11 +357,11 @@
new FProxyJavascriptEnabledCallback(this));
fproxyConfig.register("showPanicButton", false,
configItemOrder++, true, true, "SimpleToadletServer.panicButton",
"SimpleToadletServer.panicButtonLong",
new BooleanCallback(){
- public boolean get(){
+ public Boolean get() {
return
SimpleToadletServer.isPanicButtonToBeShown;
}
- public void set(boolean value){
+ public void set(Boolean value) {
if(value ==
SimpleToadletServer.isPanicButtonToBeShown) return;
else
SimpleToadletServer.isPanicButtonToBeShown = value;
}
@@ -375,13 +375,13 @@
fproxyConfig.register("enablePersistentConnections", false,
configItemOrder++, true, false,
"SimpleToadletServer.enablePersistentConnections",
"SimpleToadletServer.enablePersistentConnectionsLong",
new BooleanCallback() {
- public boolean get() {
+ public Boolean get() {
synchronized(SimpleToadletServer.this) {
return
enablePersistentConnections;
}
}
- public void set(boolean val) throws
InvalidConfigValueException {
+ public void set(Boolean val) throws
InvalidConfigValueException {
synchronized(SimpleToadletServer.this) {
enablePersistentConnections = val;
}
@@ -398,13 +398,13 @@
fproxyConfig.register("enableInlinePrefetch", false,
configItemOrder++, true, false, "SimpleToadletServer.enableInlinePrefetch",
"SimpleToadletServer.enableInlinePrefetchLong",
new BooleanCallback() {
- public boolean get() {
+ public Boolean get() {
synchronized(SimpleToadletServer.this) {
return
enableInlinePrefetch;
}
}
- public void set(boolean val) throws
InvalidConfigValueException {
+ public void set(Boolean val) throws
InvalidConfigValueException {
synchronized(SimpleToadletServer.this) {
enableInlinePrefetch =
val;
}
@@ -433,10 +433,10 @@
allowedFullAccess = new
AllowedHosts(fproxyConfig.getString("allowedHostsFullAccess"));
fproxyConfig.register("doRobots", false, configItemOrder++,
true, false, "SimpleToadletServer.doRobots", "SimpleToadletServer.doRobotsLong",
new BooleanCallback() {
- public boolean get() {
+ public Boolean get() {
return doRobots;
}
- public void set(boolean val) throws
InvalidConfigValueException {
+ public void set(Boolean val) throws
InvalidConfigValueException {
doRobots = val;
}
});
Modified: trunk/freenet/src/freenet/config/BooleanOption.java
===================================================================
--- trunk/freenet/src/freenet/config/BooleanOption.java 2008-08-14 13:33:41 UTC
(rev 21838)
+++ trunk/freenet/src/freenet/config/BooleanOption.java 2008-08-14 13:44:45 UTC
(rev 21839)
@@ -6,65 +6,25 @@
import freenet.l10n.L10n;
import freenet.support.api.BooleanCallback;
-public class BooleanOption extends Option {
-
- final boolean defaultValue;
- final BooleanCallback cb;
- private boolean currentValue;
-
+public class BooleanOption extends Option<Boolean, BooleanCallback> {
public BooleanOption(SubConfig conf, String optionName, boolean
defaultValue, int sortOrder,
boolean expert, boolean forceWrite, String shortDesc,
String longDesc, BooleanCallback cb) {
super(conf, optionName, cb, sortOrder, expert, forceWrite,
shortDesc, longDesc, Option.DataType.BOOLEAN);
this.defaultValue = defaultValue;
- this.cb = cb;
this.currentValue = defaultValue;
}
- /** Get the current value. This is the value in use if we have finished
- * initialization, otherwise it is the value set at startup (possibly
the default). */
- public boolean getValue() {
- if(config.hasFinishedInitialization())
- return currentValue = cb.get();
- else return currentValue;
- }
-
- public void setValue(String val) throws InvalidConfigValueException {
+ public Boolean parseString(String val) throws
InvalidConfigValueException {
if(val.equalsIgnoreCase("true") || val.equalsIgnoreCase("yes"))
{
- set(true);
+ return true;
} else if(val.equalsIgnoreCase("false") ||
val.equalsIgnoreCase("no")) {
- set(false);
+ return false;
} else
throw new
OptionFormatException(L10n.getString("BooleanOption.parseError", "val", val));
}
-
- public void set(boolean b) throws InvalidConfigValueException {
- cb.set(b);
- currentValue = b;
- }
-
- public String getValueString() {
- return Boolean.toString(getValue());
- }
- public void setInitialValue(String val) throws
InvalidConfigValueException {
- if(val.equalsIgnoreCase("true") || val.equalsIgnoreCase("yes"))
{
- currentValue = true;
- } else if(val.equalsIgnoreCase("false") ||
val.equalsIgnoreCase("no")) {
- currentValue = false;
- } else
- throw new
OptionFormatException(L10n.getString("BooleanOption.parseError", "val", val));
+ @Override
+ protected String toString(Boolean val) {
+ return val.toString();
}
-
- public boolean isDefault() {
- getValue();
- return currentValue == defaultValue;
- }
-
- public String getDefault() {
- return Boolean.toString(defaultValue);
- }
-
- public void setDefault() {
- currentValue = defaultValue;
- }
}
Modified: trunk/freenet/src/freenet/config/ConfigCallback.java
===================================================================
--- trunk/freenet/src/freenet/config/ConfigCallback.java 2008-08-14
13:33:41 UTC (rev 21838)
+++ trunk/freenet/src/freenet/config/ConfigCallback.java 2008-08-14
13:44:45 UTC (rev 21839)
@@ -3,7 +3,22 @@
* http://www.gnu.org/ for further details of the GPL. */
package freenet.config;
-public abstract class ConfigCallback {
+public abstract class ConfigCallback<T> {
+ /**
+ * Get the current, used value of the config variable.
+ */
+ public abstract T get();
+
+ /**
+ * Set the config variable to a new value.
+ *
+ * @param val
+ * The new value.
+ * @throws InvalidConfigOptionException
+ * If the new value is invalid for this particular option.
+ */
+ public abstract void set(T val) throws InvalidConfigValueException;
+
public boolean isReadOnly() {
return false;
}
Modified: trunk/freenet/src/freenet/config/IntOption.java
===================================================================
--- trunk/freenet/src/freenet/config/IntOption.java 2008-08-14 13:33:41 UTC
(rev 21838)
+++ trunk/freenet/src/freenet/config/IntOption.java 2008-08-14 13:44:45 UTC
(rev 21839)
@@ -8,89 +8,37 @@
import freenet.support.api.IntCallback;
/** Integer config variable */
-public class IntOption extends Option {
-
- final int defaultValue;
- final IntCallback cb;
- private int currentValue;
- // Cache it mostly so that we can keep SI units
- private String cachedStringValue;
-
- public IntOption(SubConfig conf, String optionName, int defaultValue,
String defaultValueString,
- int sortOrder, boolean expert, boolean forceWrite,
String shortDesc, String longDesc, IntCallback cb) {
+public class IntOption extends Option<Integer, IntCallback> {
+ public IntOption(SubConfig conf, String optionName, String
defaultValueString, int sortOrder, boolean expert,
+ boolean forceWrite, String shortDesc, String longDesc,
IntCallback cb) {
+ this(conf, optionName, Fields.parseInt(defaultValueString),
sortOrder, expert, forceWrite, shortDesc, longDesc,
+ cb);
+ }
+
+ public IntOption(SubConfig conf, String optionName, Integer
defaultValue, int sortOrder, boolean expert,
+ boolean forceWrite, String shortDesc, String longDesc,
IntCallback cb) {
super(conf, optionName, cb, sortOrder, expert, forceWrite,
shortDesc, longDesc, Option.DataType.NUMBER);
this.defaultValue = defaultValue;
- this.cb = cb;
this.currentValue = defaultValue;
- this.cachedStringValue = defaultValueString;
}
- public IntOption(SubConfig conf, String optionName, String
defaultValueString,
- int sortOrder, boolean expert, boolean forceWrite,
String shortDesc, String longDesc, IntCallback cb) {
- super(conf, optionName, cb, sortOrder, expert, forceWrite,
shortDesc, longDesc, Option.DataType.NUMBER);
- this.defaultValue = Fields.parseInt(defaultValueString);
- this.cb = cb;
- this.currentValue = defaultValue;
- this.cachedStringValue = defaultValueString;
- }
-
- /** Get the current value. This is the value in use if we have finished
- * initialization, otherwise it is the value set at startup (possibly
the default). */
- public int getValue() {
- if(config.hasFinishedInitialization()) {
- int val = cb.get();
- if(currentValue != val) {
- currentValue = val;
- cachedStringValue = null;
- }
- }
- return currentValue;
- }
-
- public void setValue(String val) throws InvalidConfigValueException {
- int x;
- try{
+ @Override
+ protected Integer parseString(String val) throws
InvalidConfigValueException {
+ Integer x;
+ try {
x = Fields.parseInt(val);
} catch (NumberFormatException e) {
throw new
InvalidConfigValueException(l10n("parseError", "val", val));
}
- cb.set(x);
- cachedStringValue = val;
- currentValue = x;
+ return x;
}
-
- public void setInitialValue(String val) throws
InvalidConfigValueException {
- int x;
- try{
- x = Fields.parseInt(val);
- } catch (NumberFormatException e) {
- throw new
InvalidConfigValueException(l10n("parseError", "val", val));
- }
- cachedStringValue = val;
- currentValue = x;
- }
private String l10n(String key, String pattern, String value) {
- return L10n.getString("IntOption."+key, pattern, value);
+ return L10n.getString("IntOption." + key, pattern, value);
}
- public String getValueString() {
- int val = getValue();
- if(cachedStringValue != null) return cachedStringValue;
- return Integer.toString(val);
+ @Override
+ protected String toString(Integer val) {
+ return Fields.intToString(val);
}
-
- public String getDefault(){
- return Integer.toString(defaultValue);
- }
-
- public boolean isDefault() {
- getValue();
- return currentValue == defaultValue;
- }
-
- public void setDefault() {
- currentValue = defaultValue;
- }
-
}
Modified: trunk/freenet/src/freenet/config/LongOption.java
===================================================================
--- trunk/freenet/src/freenet/config/LongOption.java 2008-08-14 13:33:41 UTC
(rev 21838)
+++ trunk/freenet/src/freenet/config/LongOption.java 2008-08-14 13:44:45 UTC
(rev 21839)
@@ -8,91 +8,37 @@
import freenet.support.api.LongCallback;
/** Long config variable */
-public class LongOption extends Option {
-
- final long defaultValue;
- final LongCallback cb;
- private long currentValue;
- // Cache it mostly so that we can keep SI units
- private String cachedStringValue;
-
- public LongOption(SubConfig conf, String optionName, long defaultValue,
String defaultValueString,
- int sortOrder, boolean expert, boolean forceWrite,
String shortDesc, String longDesc, LongCallback cb) {
- super(conf, optionName, cb, sortOrder, expert, forceWrite,
shortDesc, longDesc, Option.DataType.NUMBER);
- this.defaultValue = defaultValue;
- this.cb = cb;
- this.currentValue = defaultValue;
- this.cachedStringValue = defaultValueString;
+public class LongOption extends Option<Long, LongCallback> {
+ public LongOption(SubConfig conf, String optionName, String
defaultValueString, int sortOrder, boolean expert,
+ boolean forceWrite, String shortDesc, String longDesc,
LongCallback cb) {
+ this(conf, optionName, Fields.parseLong(defaultValueString),
sortOrder, expert, forceWrite, shortDesc,
+ longDesc, cb);
}
- public LongOption(SubConfig conf, String optionName, String
defaultValueString,
- int sortOrder, boolean expert, boolean forceWrite,
String shortDesc, String longDesc, LongCallback cb) {
+ public LongOption(SubConfig conf, String optionName, Long defaultValue,
int sortOrder, boolean expert,
+ boolean forceWrite, String shortDesc, String longDesc,
LongCallback cb) {
super(conf, optionName, cb, sortOrder, expert, forceWrite,
shortDesc, longDesc, Option.DataType.NUMBER);
- this.defaultValue = Fields.parseLong(defaultValueString);
- this.cb = cb;
+ this.defaultValue = defaultValue;
this.currentValue = defaultValue;
- this.cachedStringValue = defaultValueString;
}
-
- /** Get the current value. This is the value in use if we have finished
- * initialization, otherwise it is the value set at startup (possibly
the default). */
- public long getValue() {
- if(config.hasFinishedInitialization()) {
- long val = cb.get();
- if(currentValue != val) {
- currentValue = val;
- cachedStringValue = null;
- }
- }
- return currentValue;
- }
-
- public void setValue(String val) throws InvalidConfigValueException {
- long x;
- try{
- x = Fields.parseLong(val);
- }catch (NumberFormatException e) {
- throw new
InvalidConfigValueException(l10n("parseError", "val", val));
- }
- cb.set(x);
- cachedStringValue = val;
- currentValue = x;
- }
-
- public String getValueString() {
- long l = getValue();
- if(cachedStringValue != null)
- return cachedStringValue;
- else
- return Long.toString(l);
- }
- public void setInitialValue(String val) throws
InvalidConfigValueException {
- long x;
- try{
+ @Override
+ protected Long parseString(String val) throws
InvalidConfigValueException {
+ Long x;
+ try {
x = Fields.parseLong(val);
- }catch (NumberFormatException e) {
+ } catch (NumberFormatException e) {
throw new
InvalidConfigValueException(l10n("parseError", "val", val));
}
- cachedStringValue = val;
- currentValue = x;
+ return x;
}
-
+
private String l10n(String key, String pattern, String value) {
- return L10n.getString("LongOption."+key, pattern, value);
+ return L10n.getString("LongOption." + key, pattern, value);
}
-
- public boolean isDefault() {
- getValue();
- return currentValue == defaultValue;
- }
- public String getDefault() {
- return Long.toString(defaultValue);
+ @Override
+ protected String toString(Long val) {
+ return Fields.longToString(val);
}
-
- public void setDefault() {
- currentValue = defaultValue;
- }
-
}
Modified: trunk/freenet/src/freenet/config/Option.java
===================================================================
--- trunk/freenet/src/freenet/config/Option.java 2008-08-14 13:33:41 UTC
(rev 21838)
+++ trunk/freenet/src/freenet/config/Option.java 2008-08-14 13:44:45 UTC
(rev 21839)
@@ -6,8 +6,7 @@
/**
* A config option.
*/
-public abstract class Option {
-
+public abstract class Option<T, C extends ConfigCallback<T>> {
/** The parent SubConfig object */
protected final SubConfig config;
/** The option name */
@@ -23,8 +22,11 @@
/** Long description of value e.g. "The TCP port to listen for FCP
connections on" */
protected final String longDesc;
/** The configCallback associated to the Option */
- protected final ConfigCallback cb;
+ protected final C cb;
+ protected T defaultValue;
+ protected T currentValue;
+
public static enum DataType {
STRING, NUMBER, BOOLEAN, STRING_ARRAY
};
@@ -32,7 +34,7 @@
/** Data type : used to make it possible to make user inputs more
friendly in FCP apps */
final DataType dataType;
- Option(SubConfig config, String name, ConfigCallback cb, int sortOrder,
boolean expert, boolean forceWrite,
+ Option(SubConfig config, String name, C cb, int sortOrder, boolean
expert, boolean forceWrite,
String shortDesc, String longDesc, DataType dataType) {
this.config = config;
this.name = name;
@@ -46,22 +48,38 @@
}
/**
- * Set this option's current value to a string. Will call the callback.
Does not care
- * whether the value of the option has changed.
+ * Set this option's current value to a string. Will call the callback.
Does not care whether
+ * the value of the option has changed.
*/
- public abstract void setValue(String val) throws
InvalidConfigValueException;
+ public final void setValue(String val) throws
InvalidConfigValueException {
+ T x = parseString(val);
+ set(x);
+ currentValue = x;
+ }
+ protected abstract T parseString(String val) throws
InvalidConfigValueException;
+ protected abstract String toString(T val);
+
+ protected final void set(T val) throws InvalidConfigValueException {
+ cb.set(val);
+ currentValue = val;
+ }
+
/**
* Get the current value of the option as a string.
*/
- public abstract String getValueString();
+ public final String getValueString() {
+ return toString(currentValue);
+ }
/** Set to a value from the config file; this is not passed on to the
callback, as we
* expect the client-side initialization to check the value. The
callback is not valid
* until the client calls finishedInitialization().
* @throws InvalidConfigValueException
*/
- public abstract void setInitialValue(String val) throws
InvalidConfigValueException;
+ public final void setInitialValue(String val) throws
InvalidConfigValueException {
+ currentValue = parseString(val);
+ }
/**
* Call the callback with the current value of the option.
@@ -113,16 +131,37 @@
}
/**
+ * Get the current value. This is the value in use if we have finished
initialization, otherwise
+ * it is the value set at startup (possibly the default).
+ */
+ public final T getValue() {
+ if (config.hasFinishedInitialization())
+ return currentValue = cb.get();
+ else
+ return currentValue;
+ }
+
+ /**
* Is this option set to the default?
*/
- public abstract boolean isDefault();
+ public boolean isDefault() {
+ getValue();
+ return (currentValue == null ? false :
currentValue.equals(defaultValue));
+ }
+
+ /**
+ * Set to the default. Don't use after completed initialization, as
this does not call the
+ * callback.
+ */
+ public final void setDefault() {
+ currentValue = defaultValue;
+ }
- /** Set to the default. Don't use after completed initialization, as
this does not call the callback. FIXME fix this? */
- public abstract void setDefault();
-
- public abstract String getDefault();
+ public final String getDefault() {
+ return toString(defaultValue);
+ }
- public ConfigCallback getCallback() {
+ public final C getCallback() {
return cb;
}
}
Modified: trunk/freenet/src/freenet/config/ShortOption.java
===================================================================
--- trunk/freenet/src/freenet/config/ShortOption.java 2008-08-14 13:33:41 UTC
(rev 21838)
+++ trunk/freenet/src/freenet/config/ShortOption.java 2008-08-14 13:44:45 UTC
(rev 21839)
@@ -4,68 +4,31 @@
import freenet.support.Fields;
import freenet.support.api.ShortCallback;
-public class ShortOption extends Option {
-
- final short defaultValue;
- final ShortCallback cb;
- private short currentValue;
-
+public class ShortOption extends Option<Short, ShortCallback> {
public ShortOption(SubConfig conf, String optionName, short
defaultValue, int sortOrder,
boolean expert, boolean forceWrite, String shortDesc,
String longDesc, ShortCallback cb) {
super(conf, optionName, cb, sortOrder, expert, forceWrite,
shortDesc, longDesc, Option.DataType.NUMBER);
this.defaultValue = defaultValue;
- this.cb = cb;
this.currentValue = defaultValue;
}
-
- /** Get the current value. This is the value in use if we have finished
- * initialization, otherwise it is the value set at startup (possibly
the default). */
- public short getValue() {
- if(config.hasFinishedInitialization())
- return currentValue = cb.get();
- else return currentValue;
+
+ private String l10n(String key, String pattern, String value) {
+ return L10n.getString("ShortOption."+key, pattern, value);
}
- public void setValue(String val) throws InvalidConfigValueException {
+ @Override
+ protected Short parseString(String val) throws
InvalidConfigValueException {
short x;
- try{
- x= Fields.parseShort(val);
- } catch (NumberFormatException e) {
- throw new
InvalidConfigValueException(l10n("unrecognisedShort", "val", val));
- }
- cb.set(x);
- currentValue = x;
- }
-
- public String getValueString() {
- return Short.toString(getValue());
- }
-
- public void setInitialValue(String val) throws
InvalidConfigValueException {
- short x;
- try{
+ try {
x = Fields.parseShort(val);
} catch (NumberFormatException e) {
throw new
InvalidConfigValueException(l10n("unrecognisedShort", "val", val));
}
- currentValue = x;
+ return x;
}
- private String l10n(String key, String pattern, String value) {
- return L10n.getString("ShortOption."+key, pattern, value);
- }
-
- public boolean isDefault() {
- getValue();
- return currentValue == defaultValue;
- }
-
- public String getDefault() {
- return Short.toString(defaultValue);
- }
-
- public void setDefault() {
- currentValue = defaultValue;
- }
-
+ @Override
+ protected String toString(Short val) {
+ return Fields.shortToString(val);
+ }
}
Modified: trunk/freenet/src/freenet/config/StringArrOption.java
===================================================================
--- trunk/freenet/src/freenet/config/StringArrOption.java 2008-08-14
13:33:41 UTC (rev 21838)
+++ trunk/freenet/src/freenet/config/StringArrOption.java 2008-08-14
13:44:45 UTC (rev 21839)
@@ -8,80 +8,45 @@
import freenet.support.URLEncoder;
import freenet.support.api.StringArrCallback;
-public class StringArrOption extends Option {
-
- private final String[] defaultValue;
- private final StringArrCallback cb;
- private String[] currentValue;
-
+public class StringArrOption extends Option<String[], StringArrCallback> {
public static final String delimiter = ";";
public StringArrOption(SubConfig conf, String optionName, String[]
defaultValue, int sortOrder,
boolean expert, boolean forceWrite, String shortDesc,
String longDesc, StringArrCallback cb) {
super(conf, optionName, cb, sortOrder, expert, forceWrite,
shortDesc, longDesc, Option.DataType.STRING_ARRAY);
this.defaultValue = (defaultValue==null)?new
String[0]:defaultValue;
- this.cb = cb;
this.currentValue = (defaultValue==null)?new
String[0]:defaultValue;
}
-
- /** Get the current value. This is the value in use if we have finished
- * initialization, otherwise it is the value set at startup (possibly
the default). */
- public String[] getValue() {
- if(config.hasFinishedInitialization())
- currentValue = cb.get();
- return currentValue;
- }
+ public String[] parseString(String val) throws
InvalidConfigValueException {
+ if(val.length() == 0) return new String[0];
+ String[] out = val.split(delimiter);
- public void setValue(String[] val) throws InvalidConfigValueException {
- setInitialValue(val);
- cb.set(this.currentValue);
- }
-
- public void setValue(String val) throws InvalidConfigValueException {
try {
- setValue(stringToArray(val));
+ for (int i = 0; i < out.length; i++) {
+ if (out[i].equals(":"))
+ out[i] = "";
+ else
+ out[i] = URLDecoder.decode(out[i], true
/* FIXME false */);
+ }
} catch (URLEncodedFormatException e) {
throw new
InvalidConfigValueException(l10n("parseError", "error",
e.getLocalizedMessage()));
}
- }
-
- public static String[] stringToArray(String val) throws
URLEncodedFormatException {
- if(val.length() == 0) return new String[0];
- String[] out = val.split(delimiter);
- for(int i=0;i<out.length;i++) {
- if(out[i].equals(":"))
- out[i] = "";
- else
- out[i] = URLDecoder.decode(out[i], true /*
FIXME false */);
- }
return out;
}
-
- public String getValueString() {
- return arrayToString(getValue());
- }
public void setInitialValue(String[] val) throws
InvalidConfigValueException {
this.currentValue = val;
}
- public void setInitialValue(String val) throws
InvalidConfigValueException {
- try {
- this.currentValue = stringToArray(val);
- } catch (URLEncodedFormatException e) {
- throw new
InvalidConfigValueException(l10n("parseError", "error",
e.getLocalizedMessage()));
- }
- }
-
private String l10n(String key, String pattern, String value) {
return L10n.getString("StringArrOption."+key, pattern, value);
}
- public static String arrayToString(String[] arr) {
+ public String toString(String[] arr) {
if (arr == null)
return null;
- StringBuffer sb = new StringBuffer();
+ StringBuilder sb = new StringBuilder();
for (int i = 0 ; i < arr.length ; i++) {
String val = arr[i];
if(val.length() == 0)
@@ -101,17 +66,8 @@
}
}
- public String getDefault() {
- return arrayToString(defaultValue);
- }
-
public boolean isDefault() {
getValueString();
return currentValue == null ? false :
Arrays.equals(currentValue, defaultValue);
}
-
- public void setDefault() {
- currentValue = defaultValue;
- }
-
}
Modified: trunk/freenet/src/freenet/config/StringOption.java
===================================================================
--- trunk/freenet/src/freenet/config/StringOption.java 2008-08-14 13:33:41 UTC
(rev 21838)
+++ trunk/freenet/src/freenet/config/StringOption.java 2008-08-14 13:44:45 UTC
(rev 21839)
@@ -5,51 +5,21 @@
import freenet.support.api.StringCallback;
-public class StringOption extends Option {
-
- final String defaultValue;
- final StringCallback cb;
- private String currentValue;
-
+public class StringOption extends Option<String, StringCallback> {
public StringOption(SubConfig conf, String optionName, String
defaultValue, int sortOrder,
boolean expert, boolean forceWrite, String shortDesc,
String longDesc, StringCallback cb) {
super(conf, optionName, cb, sortOrder, expert, forceWrite,
shortDesc, longDesc, Option.DataType.STRING);
this.defaultValue = defaultValue;
- this.cb = cb;
this.currentValue = defaultValue;
}
-
- /** Get the current value. This is the value in use if we have finished
- * initialization, otherwise it is the value set at startup (possibly
the default). */
- public String getValue() {
- if(config.hasFinishedInitialization())
- return currentValue = cb.get();
- else return currentValue;
- }
- public void setValue(String val) throws InvalidConfigValueException {
- cb.set(val);
- this.currentValue = val; // Callbacks are in charge of ensuring
it matches with possibleValues
+ @Override
+ protected String parseString(String val) throws
InvalidConfigValueException {
+ return val;
}
-
- public String getValueString() {
- return getValue();
- }
- public void setInitialValue(String val) throws
InvalidConfigValueException {
- this.currentValue = val;
+ @Override
+ protected String toString(String val) {
+ return val;
}
-
- public boolean isDefault() {
- getValue();
- return (currentValue == null ? false :
currentValue.equals(defaultValue));
- }
-
- public void setDefault() {
- currentValue = defaultValue;
- }
-
- public String getDefault(){
- return defaultValue;
- }
}
Modified: trunk/freenet/src/freenet/config/SubConfig.java
===================================================================
--- trunk/freenet/src/freenet/config/SubConfig.java 2008-08-14 13:33:41 UTC
(rev 21838)
+++ trunk/freenet/src/freenet/config/SubConfig.java 2008-08-14 13:44:45 UTC
(rev 21839)
@@ -62,12 +62,12 @@
public void register(String optionName, int defaultValue, int sortOrder,
boolean expert, boolean forceWrite, String shortDesc,
String longDesc, IntCallback cb) {
- register(new IntOption(this, optionName, defaultValue, null,
sortOrder, expert, forceWrite, shortDesc, longDesc, cb));
+ register(new IntOption(this, optionName, defaultValue,
sortOrder, expert, forceWrite, shortDesc, longDesc, cb));
}
public void register(String optionName, long defaultValue, int
sortOrder,
boolean expert, boolean forceWrite, String shortDesc,
String longDesc, LongCallback cb) {
- register(new LongOption(this, optionName, defaultValue, null,
sortOrder, expert, forceWrite, shortDesc, longDesc, cb));
+ register(new LongOption(this, optionName, defaultValue,
sortOrder, expert, forceWrite, shortDesc, longDesc, cb));
}
public void register(String optionName, String defaultValueString, int
sortOrder,
Modified: trunk/freenet/src/freenet/crypt/SSL.java
===================================================================
--- trunk/freenet/src/freenet/crypt/SSL.java 2008-08-14 13:33:41 UTC (rev
21838)
+++ trunk/freenet/src/freenet/crypt/SSL.java 2008-08-14 13:44:45 UTC (rev
21839)
@@ -66,11 +66,11 @@
sslConfig.register("sslEnable", false, configItemOrder++, true,
true, "SSL.enable", "SSL.enableLong",
new BooleanCallback() {
- public boolean get() {
+ public Boolean get() {
return enable;
}
- public void set(boolean newValue) throws
InvalidConfigValueException {
+ public void set(Boolean newValue) throws
InvalidConfigValueException {
if(newValue != get()) {
enable = newValue;
if(enable)
Modified: trunk/freenet/src/freenet/node/LoggingConfigHandler.java
===================================================================
--- trunk/freenet/src/freenet/node/LoggingConfigHandler.java 2008-08-14
13:33:41 UTC (rev 21838)
+++ trunk/freenet/src/freenet/node/LoggingConfigHandler.java 2008-08-14
13:44:45 UTC (rev 21839)
@@ -64,10 +64,10 @@
loggingConfig.register("enabled", true, 1, true, false,
"LogConfigHandler.enabled", "LogConfigHandler.enabledLong",
new BooleanCallback() {
- public boolean get() {
+ public Boolean get() {
return fileLoggerHook != null;
}
- public void set(boolean val) throws
InvalidConfigValueException {
+ public void set(Boolean val) throws
InvalidConfigValueException {
if(val == (fileLoggerHook !=
null)) return;
if(!val) {
disableLogger();
@@ -110,11 +110,12 @@
config.register("maxZippedLogsSize", "128M", 3, true, true,
"LogConfigHandler.maxZippedLogsSize", "LogConfigHandler.maxZippedLogsSizeLong",
new LongCallback() {
- public long get() {
+ public Long get() {
return maxZippedLogsSize;
}
- public void set(long val) throws
InvalidConfigValueException {
- if(val < 0) val = 0;
+ public void set(Long val) throws
InvalidConfigValueException {
+ if (val < 0)
+ val = 0L;
maxZippedLogsSize = val;
if(fileLoggerHook != null) {
fileLoggerHook.setMaxOldLogsSize(val);
@@ -179,11 +180,12 @@
// max cached bytes in RAM
config.register("maxCachedBytes", "10M", 6, true, false,
"LogConfigHandler.maxCachedBytes", "LogConfigHandler.maxCachedBytesLong",
new LongCallback() {
- public long get() {
+ public Long get() {
return maxCachedLogBytes;
}
- public void set(long val) throws
InvalidConfigValueException {
- if(val < 0) val = 0;
+ public void set(Long val) throws
InvalidConfigValueException {
+ if (val < 0)
+ val = 0L;
if(val == maxCachedLogBytes)
return;
maxCachedLogBytes = val;
if(fileLoggerHook != null)
@@ -196,10 +198,10 @@
// max cached lines in RAM
config.register("maxCachedLines", "100k", 7, true, false,
"LogConfigHandler.maxCachedLines", "LogConfigHandler.maxCachedLinesLong",
new IntCallback() {
- public int get() {
+ public Integer get() {
return maxCachedLogLines;
}
- public void set(int val) throws
InvalidConfigValueException {
+ public void set(Integer val) throws
InvalidConfigValueException {
if(val < 0) val = 0;
if(val == maxCachedLogLines)
return;
maxCachedLogLines = val;
Modified: trunk/freenet/src/freenet/node/Node.java
===================================================================
--- trunk/freenet/src/freenet/node/Node.java 2008-08-14 13:33:41 UTC (rev
21838)
+++ trunk/freenet/src/freenet/node/Node.java 2008-08-14 13:44:45 UTC (rev
21839)
@@ -815,11 +815,11 @@
nodeConfig.register("disableProbabilisticHTLs", false,
sortOrder++, true, false, "Node.disablePHTLS", "Node.disablePHTLSLong",
new BooleanCallback() {
- public boolean get() {
+ public Boolean get() {
return disableProbabilisticHTLs;
}
- public void set(boolean val) throws
InvalidConfigValueException {
+ public void set(Boolean val) throws
InvalidConfigValueException {
disableProbabilisticHTLs = val;
}
@@ -829,11 +829,11 @@
nodeConfig.register("maxHTL", DEFAULT_MAX_HTL, sortOrder++,
true, false, "Node.maxHTL", "Node.maxHTLLong", new ShortCallback() {
- public short get() {
+ public Short get() {
return maxHTL;
}
- public void set(short val) throws
InvalidConfigValueException {
+ public void set(Short val) throws
InvalidConfigValueException {
if(maxHTL < 0) throw new
InvalidConfigValueException("Impossible max HTL");
maxHTL = val;
}
@@ -857,11 +857,11 @@
nodeConfig.register("enableARKs", true, sortOrder++, true,
false, "Node.enableARKs", "Node.enableARKsLong", new BooleanCallback() {
- public boolean get() {
+ public Boolean get() {
return enableARKs;
}
- public void set(boolean val) throws
InvalidConfigValueException {
+ public void set(Boolean val) throws
InvalidConfigValueException {
throw new InvalidConfigValueException("Cannot
change on the fly");
}
@@ -873,11 +873,11 @@
nodeConfig.register("enablePerNodeFailureTables", true,
sortOrder++, true, false, "Node.enablePerNodeFailureTables",
"Node.enablePerNodeFailureTablesLong", new BooleanCallback() {
- public boolean get() {
+ public Boolean get() {
return enablePerNodeFailureTables;
}
- public void set(boolean val) throws
InvalidConfigValueException {
+ public void set(Boolean val) throws
InvalidConfigValueException {
throw new InvalidConfigValueException("Cannot
change on the fly");
}
@@ -889,11 +889,11 @@
nodeConfig.register("enableULPRDataPropagation", true,
sortOrder++, true, false, "Node.enableULPRDataPropagation",
"Node.enableULPRDataPropagationLong", new BooleanCallback() {
- public boolean get() {
+ public Boolean get() {
return enableULPRDataPropagation;
}
- public void set(boolean val) throws
InvalidConfigValueException {
+ public void set(Boolean val) throws
InvalidConfigValueException {
throw new InvalidConfigValueException("Cannot
change on the fly");
}
@@ -905,11 +905,11 @@
nodeConfig.register("enableSwapping", true, sortOrder++, true,
false, "Node.enableSwapping", "Node.enableSwappingLong", new BooleanCallback() {
- public boolean get() {
+ public Boolean get() {
return enableSwapping;
}
- public void set(boolean val) throws
InvalidConfigValueException {
+ public void set(Boolean val) throws
InvalidConfigValueException {
throw new InvalidConfigValueException("Cannot
change on the fly");
}
@@ -921,11 +921,11 @@
nodeConfig.register("publishOurPeersLocation", false,
sortOrder++, true, false, "Node.publishOurPeersLocation",
"Node.publishOurPeersLocationLong", new BooleanCallback() {
- public boolean get() {
+ public Boolean get() {
return publishOurPeersLocation;
}
- public void set(boolean val) throws
InvalidConfigValueException {
+ public void set(Boolean val) throws
InvalidConfigValueException {
publishOurPeersLocation = val;
}
});
@@ -933,22 +933,22 @@
nodeConfig.register("routeAccordingToOurPeersLocation", false,
sortOrder++, true, false, "Node.routeAccordingToOurPeersLocation",
"Node.routeAccordingToOurPeersLocationLong", new BooleanCallback() {
- public boolean get() {
+ public Boolean get() {
return routeAccordingToOurPeersLocation;
}
- public void set(boolean val) throws
InvalidConfigValueException {
+ public void set(Boolean val) throws
InvalidConfigValueException {
routeAccordingToOurPeersLocation = val;
}
});
routeAccordingToOurPeersLocation =
nodeConfig.getBoolean("routeAccordingToOurPeersLocation");
nodeConfig.register("enableSwapQueueing", true, sortOrder++,
true, false, "Node.enableSwapQueueing", "Node.enableSwapQueueingLong", new
BooleanCallback() {
- public boolean get() {
+ public Boolean get() {
return enableSwapQueueing;
}
- public void set(boolean val) throws
InvalidConfigValueException {
+ public void set(Boolean val) throws
InvalidConfigValueException {
enableSwapQueueing = val;
}
@@ -956,11 +956,11 @@
enableSwapQueueing =
nodeConfig.getBoolean("enableSwapQueueing");
nodeConfig.register("enablePacketCoalescing", true,
sortOrder++, true, false, "Node.enablePacketCoalescing",
"Node.enablePacketCoalescingLong", new BooleanCallback() {
- public boolean get() {
+ public Boolean get() {
return enablePacketCoalescing;
}
- public void set(boolean val) throws
InvalidConfigValueException {
+ public void set(Boolean val) throws
InvalidConfigValueException {
enablePacketCoalescing = val;
}
@@ -1004,11 +1004,11 @@
// Bandwidth limit
nodeConfig.register("outputBandwidthLimit", "15K", sortOrder++,
false, true, "Node.outBWLimit", "Node.outBWLimitLong", new IntCallback() {
- public int get() {
+ public Integer get() {
//return
BlockTransmitter.getHardBandwidthLimit();
return outputBandwidthLimit;
}
- public void set(int obwLimit) throws
InvalidConfigValueException {
+ public void set(Integer obwLimit)
throws InvalidConfigValueException {
if(obwLimit <= 0) throw new
InvalidConfigValueException(l10n("bwlimitMustBePositive"));
synchronized(Node.this) {
outputBandwidthLimit =
obwLimit;
@@ -1029,11 +1029,11 @@
outputThrottle = new DoubleTokenBucket(obwLimit/2,
(1000L*1000L*1000L) / obwLimit, obwLimit/2, 0.8);
nodeConfig.register("inputBandwidthLimit", "-1", sortOrder++,
false, true, "Node.inBWLimit", "Node.inBWLimitLong", new IntCallback() {
- public int get() {
+ public Integer get() {
if(inputLimitDefault) return -1;
return inputBandwidthLimit;
}
- public void set(int ibwLimit) throws
InvalidConfigValueException {
+ public void set(Integer ibwLimit)
throws InvalidConfigValueException {
synchronized(Node.this) {
if(ibwLimit == -1) {
inputLimitDefault = true;
@@ -1058,11 +1058,11 @@
nodeConfig.register("throttleLocalTraffic", false, sortOrder++,
true, false, "Node.throttleLocalTraffic", "Node.throttleLocalTrafficLong", new
BooleanCallback() {
- public boolean get() {
+ public Boolean get() {
return throttleLocalData;
}
- public void set(boolean val) throws
InvalidConfigValueException {
+ public void set(Boolean val) throws
InvalidConfigValueException {
throttleLocalData = val;
}
@@ -1158,10 +1158,10 @@
final SubConfig opennetConfig = new SubConfig("node.opennet",
config);
opennetConfig.register("connectToSeednodes", true, 0, true,
false, "Node.withAnnouncement", "Node.withAnnouncementLong", new
BooleanCallback() {
- public boolean get() {
+ public Boolean get() {
return isAllowedToConnectToSeednodes;
}
- public void set(boolean val) throws
InvalidConfigValueException {
+ public void set(Boolean val) throws
InvalidConfigValueException {
if(val == get()) return;
synchronized(Node.this) {
if(opennet != null)
@@ -1179,12 +1179,12 @@
// Can be enabled on the fly
opennetConfig.register("enabled", false, 0, false, true,
"Node.opennetEnabled", "Node.opennetEnabledLong", new BooleanCallback() {
- public boolean get() {
+ public Boolean get() {
synchronized(Node.this) {
return opennet != null;
}
}
- public void set(boolean val) throws
InvalidConfigValueException {
+ public void set(Boolean val) throws
InvalidConfigValueException {
OpennetManager o;
synchronized(Node.this) {
if(val == (opennet != null)) return;
@@ -1209,10 +1209,10 @@
opennetConfig.register("maxOpennetPeers", "20", 1, true, false,
"Node.maxOpennetPeers",
"Node.maxOpennetPeersLong", new IntCallback() {
- public int get() {
+ public Integer get() {
return maxOpennetPeers;
}
- public void set(int
inputMaxOpennetPeers) throws InvalidConfigValueException {
+ public void set(Integer
inputMaxOpennetPeers) throws InvalidConfigValueException {
if(inputMaxOpennetPeers < 0)
throw new InvalidConfigValueException(l10n("mustBePositive"));
if(inputMaxOpennetPeers > 20)
throw new
InvalidConfigValueException(l10n("maxOpennetPeersMustBeTwentyOrLess"));
maxOpennetPeers =
inputMaxOpennetPeers;
@@ -1237,11 +1237,11 @@
opennetConfig.register("acceptSeedConnections", true, 2, true,
true, "Node.acceptSeedConnectionsShort", "Node.acceptSeedConnections", new
BooleanCallback() {
- public boolean get() {
+ public Boolean get() {
return acceptSeedConnections;
}
- public void set(boolean val) throws
InvalidConfigValueException {
+ public void set(Boolean val) throws
InvalidConfigValueException {
acceptSeedConnections = val;
}
@@ -1254,13 +1254,13 @@
nodeConfig.register("passOpennetPeersThroughDarknet", true,
sortOrder++, true, false, "Node.passOpennetPeersThroughDarknet",
"Node.passOpennetPeersThroughDarknetLong",
new BooleanCallback() {
- public boolean get() {
+ public Boolean get() {
synchronized(Node.this) {
return
passOpennetRefsThroughDarknet;
}
}
- public void set(boolean val) throws
InvalidConfigValueException {
+ public void set(Boolean val) throws
InvalidConfigValueException {
synchronized(Node.this) {
passOpennetRefsThroughDarknet = val;
}
@@ -1301,13 +1301,13 @@
nodeConfig.register("storeForceBigShrinks", false, sortOrder++,
true, false, "Node.forceBigShrink", "Node.forceBigShrinkLong",
new BooleanCallback() {
- public boolean get() {
+ public Boolean get() {
synchronized(Node.this) {
return
storeForceBigShrinks;
}
}
- public void set(boolean val) throws
InvalidConfigValueException {
+ public void set(Boolean val) throws
InvalidConfigValueException {
synchronized(Node.this) {
storeForceBigShrinks =
val;
}
@@ -1322,11 +1322,11 @@
nodeConfig.register("storeSize", "1G", sortOrder++, false,
true, "Node.storeSize", "Node.storeSizeLong",
new LongCallback() {
- public long get() {
+ public Long get() {
return maxTotalDatastoreSize;
}
- public void set(long storeSize) throws
InvalidConfigValueException {
+ public void set(Long storeSize) throws
InvalidConfigValueException {
if((storeSize < 0) ||
(storeSize < (32 * 1024 * 1024)))
throw new
InvalidConfigValueException(l10n("invalidStoreSize"));
long newMaxStoreKeys =
storeSize / sizePerKey;
@@ -1533,11 +1533,11 @@
nodeConfig.register("databaseMaxMemory", "20M", sortOrder++,
true, false, "Node.databaseMemory", "Node.databaseMemoryLong",
new LongCallback() {
- public long get() {
+ public Long get() {
return databaseMaxMemory;
}
- public void set(long val) throws
InvalidConfigValueException {
+ public void set(Long val) throws
InvalidConfigValueException {
if(val < 0)
throw new
InvalidConfigValueException(l10n("mustBePositive"));
else {
@@ -1660,11 +1660,11 @@
nodeConfig.register("disableHangCheckers", false, sortOrder++,
true, false, "Node.disableHangCheckers", "Node.disableHangCheckersLong", new
BooleanCallback() {
- public boolean get() {
+ public Boolean get() {
return disableHangCheckers;
}
- public void set(boolean val) throws
InvalidConfigValueException {
+ public void set(Boolean val) throws
InvalidConfigValueException {
disableHangCheckers = val;
}
});
Modified: trunk/freenet/src/freenet/node/NodeClientCore.java
===================================================================
--- trunk/freenet/src/freenet/node/NodeClientCore.java 2008-08-14 13:33:41 UTC
(rev 21838)
+++ trunk/freenet/src/freenet/node/NodeClientCore.java 2008-08-14 13:44:45 UTC
(rev 21839)
@@ -175,11 +175,11 @@
// Persistent temp files
nodeConfig.register("encryptPersistentTempBuckets", true,
sortOrder++, true, false, "NodeClientCore.encryptPersistentTempBuckets",
"NodeClientCore.encryptPersistentTempBucketsLong", new BooleanCallback() {
- public boolean get() {
+ public Boolean get() {
return (persistentTempBucketFactory == null ?
true : persistentTempBucketFactory.isEncrypting());
}
- public void set(boolean val) throws
InvalidConfigValueException {
+ public void set(Boolean val) throws
InvalidConfigValueException {
if((val == get()) ||
(persistentTempBucketFactory == null)) return;
persistentTempBucketFactory.setEncryption(val);
}
@@ -211,22 +211,22 @@
nodeConfig.register("maxRAMBucketSize", "32KiB", sortOrder++,
true, false, "NodeClientCore.maxRAMBucketSize",
"NodeClientCore.maxRAMBucketSizeLong", new LongCallback() {
- public long get() {
+ public Long get() {
return (tempBucketFactory == null ? 0 :
tempBucketFactory.getMaxRAMBucketSize());
}
- public void set(long val) throws
InvalidConfigValueException {
+ public void set(Long val) throws
InvalidConfigValueException {
if((val == get()) || (tempBucketFactory ==
null)) return;
tempBucketFactory.setMaxRAMBucketSize(val);
}
});
nodeConfig.register("RAMBucketPoolSize", "10MiB", sortOrder++,
true, false, "NodeClientCore.ramBucketPoolSize",
"NodeClientCore.ramBucketPoolSizeLong", new LongCallback() {
- public long get() {
+ public Long get() {
return (tempBucketFactory == null ? 0 :
tempBucketFactory.getMaxRamUsed());
}
- public void set(long val) throws
InvalidConfigValueException {
+ public void set(Long val) throws
InvalidConfigValueException {
if((val == get()) || (tempBucketFactory ==
null)) return;
tempBucketFactory.setMaxRamUsed(val);
}
@@ -234,11 +234,11 @@
nodeConfig.register("encryptTempBuckets", true, sortOrder++,
true, false, "NodeClientCore.encryptTempBuckets",
"NodeClientCore.encryptTempBucketsLong", new BooleanCallback() {
- public boolean get() {
+ public Boolean get() {
return (tempBucketFactory == null ? true :
tempBucketFactory.isEncrypting());
}
- public void set(boolean val) throws
InvalidConfigValueException {
+ public void set(Boolean val) throws
InvalidConfigValueException {
if((val == get()) || (tempBucketFactory ==
null)) return;
tempBucketFactory.setEncryption(val);
}
@@ -328,11 +328,11 @@
nodeConfig.register("lazyResume", false, sortOrder++, true,
false, "NodeClientCore.lazyResume",
"NodeClientCore.lazyResumeLong", new BooleanCallback() {
- public boolean get() {
+ public Boolean get() {
return lazyResume;
}
- public void set(boolean val) throws
InvalidConfigValueException {
+ public void set(Boolean val) throws
InvalidConfigValueException {
synchronized(NodeClientCore.this) {
lazyResume = val;
}
@@ -344,11 +344,11 @@
nodeConfig.register("maxBackgroundUSKFetchers", "64",
sortOrder++, true, false, "NodeClientCore.maxUSKFetchers",
"NodeClientCore.maxUSKFetchersLong", new IntCallback() {
- public int get() {
+ public Integer get() {
return maxBackgroundUSKFetchers;
}
- public void set(int uskFetch) throws
InvalidConfigValueException {
+ public void set(Integer uskFetch) throws
InvalidConfigValueException {
if(uskFetch <= 0)
throw new
InvalidConfigValueException(l10n("maxUSKFetchersMustBeGreaterThanZero"));
maxBackgroundUSKFetchers = uskFetch;
Modified: trunk/freenet/src/freenet/node/NodeCryptoConfig.java
===================================================================
--- trunk/freenet/src/freenet/node/NodeCryptoConfig.java 2008-08-14
13:33:41 UTC (rev 21838)
+++ trunk/freenet/src/freenet/node/NodeCryptoConfig.java 2008-08-14
13:44:45 UTC (rev 21839)
@@ -50,14 +50,14 @@
NodeCryptoConfig(SubConfig config, int sortOrder, boolean onePerIP)
throws NodeInitException {
config.register("listenPort", -1 /* means random */,
sortOrder++, true, true, "Node.port", "Node.portLong", new IntCallback() {
- public int get() {
+ public Integer get() {
synchronized(NodeCryptoConfig.class) {
if(crypto != null)
portNumber = crypto.portNumber;
return portNumber;
}
}
- public void set(int val) throws
InvalidConfigValueException {
+ public void set(Integer val) throws
InvalidConfigValueException {
if(portNumber < -1 || portNumber == 0 ||
portNumber > 65535) {
throw new
InvalidConfigValueException("Invalid port number");
@@ -100,13 +100,13 @@
config.register("testingDropPacketsEvery", 0, sortOrder++,
true, false, "Node.dropPacketEvery", "Node.dropPacketEveryLong",
new IntCallback() {
- public int get() {
+ public Integer get() {
synchronized(NodeCryptoConfig.this) {
return dropProbability;
}
}
- public void set(int val) throws
InvalidConfigValueException {
+ public void set(Integer val) throws
InvalidConfigValueException {
if(val < 0) throw new
InvalidConfigValueException("testingDropPacketsEvery must not be negative");
synchronized(NodeCryptoConfig.this) {
if(val ==
dropProbability) return;
@@ -122,13 +122,13 @@
config.register("oneConnectionPerIP", onePerIP, sortOrder++,
true, false, "Node.oneConnectionPerIP", "Node.oneConnectionPerIPLong",
new BooleanCallback() {
- public boolean get() {
+ public Boolean get() {
synchronized(NodeCryptoConfig.this) {
return
oneConnectionPerAddress;
}
}
- public void set(boolean val) throws
InvalidConfigValueException {
+ public void set(Boolean val) throws
InvalidConfigValueException {
synchronized(NodeCryptoConfig.this) {
oneConnectionPerAddress
= val;
}
@@ -140,13 +140,13 @@
config.register("alwaysAllowLocalAddresses", false,
sortOrder++, true, false, "Node.alwaysAllowLocalAddresses",
"Node.alwaysAllowLocalAddressesLong",
new BooleanCallback() {
- public boolean get() {
+ public Boolean get() {
synchronized(NodeCryptoConfig.this) {
return
alwaysAllowLocalAddresses;
}
}
- public void set(boolean val) throws
InvalidConfigValueException {
+ public void set(Boolean val) throws
InvalidConfigValueException {
synchronized(NodeCryptoConfig.this) {
alwaysAllowLocalAddresses = val;
}
@@ -156,11 +156,11 @@
config.register("assumeNATed", true, sortOrder++, true, true,
"Node.assumeNATed", "Node.assumeNATedLong", new BooleanCallback() {
- public boolean get() {
+ public Boolean get() {
return assumeNATed;
}
- public void set(boolean val) throws
InvalidConfigValueException {
+ public void set(Boolean val) throws
InvalidConfigValueException {
assumeNATed = val;
}
});
Modified: trunk/freenet/src/freenet/node/NodeIPDetector.java
===================================================================
--- trunk/freenet/src/freenet/node/NodeIPDetector.java 2008-08-14 13:33:41 UTC
(rev 21838)
+++ trunk/freenet/src/freenet/node/NodeIPDetector.java 2008-08-14 13:44:45 UTC
(rev 21839)
@@ -437,11 +437,11 @@
nodeConfig.register("includeLocalAddressesInNoderefs", false,
sortOrder++, true, false, "NodeIPDectector.inclLocalAddress",
"NodeIPDectector.inclLocalAddressLong", new BooleanCallback() {
- public boolean get() {
+ public Boolean get() {
return includeLocalAddressesInNoderefs;
}
- public void set(boolean val) throws
InvalidConfigValueException {
+ public void set(Boolean val) throws
InvalidConfigValueException {
includeLocalAddressesInNoderefs = val;
lastIPAddress = null;
ipDetector.clearCached();
Modified: trunk/freenet/src/freenet/node/NodeStats.java
===================================================================
--- trunk/freenet/src/freenet/node/NodeStats.java 2008-08-14 13:33:41 UTC
(rev 21838)
+++ trunk/freenet/src/freenet/node/NodeStats.java 2008-08-14 13:44:45 UTC
(rev 21839)
@@ -212,10 +212,10 @@
statsConfig.register("threadLimit", 500, sortOrder++, true,
true, "NodeStat.threadLimit", "NodeStat.threadLimitLong",
new IntCallback() {
- public int get() {
+ public Integer get() {
return threadLimit;
}
- public void set(int val) throws
InvalidConfigValueException {
+ public void set(Integer val) throws
InvalidConfigValueException {
if(val == get()) return;
if(val < 100)
throw new
InvalidConfigValueException(l10n("valueTooLow"));
@@ -227,10 +227,10 @@
// Yes it could be in seconds insteed of multiples of 0.12, but
we don't want people to play with it :)
statsConfig.register("aggressiveGC", aggressiveGCModificator,
sortOrder++, true, false, "NodeStat.aggressiveGC", "NodeStat.aggressiveGCLong",
new IntCallback() {
- public int get() {
+ public Integer get() {
return aggressiveGCModificator;
}
- public void set(int val) throws
InvalidConfigValueException {
+ public void set(Integer val) throws
InvalidConfigValueException {
if(val == get()) return;
Logger.normal(this, "Changing
aggressiveGCModificator to "+val);
aggressiveGCModificator = val;
@@ -241,11 +241,11 @@
myMemoryChecker = new MemoryChecker(node.ps,
aggressiveGCModificator);
statsConfig.register("memoryChecker", true, sortOrder++, true,
false, "NodeStat.memCheck", "NodeStat.memCheckLong",
new BooleanCallback(){
- public boolean get() {
+ public Boolean get() {
return
myMemoryChecker.isRunning();
}
- public void set(boolean val) throws
InvalidConfigValueException {
+ public void set(Boolean val) throws
InvalidConfigValueException {
if(val == get()) return;
if(val)
@@ -259,13 +259,13 @@
statsConfig.register("ignoreLocalVsRemoteBandwidthLiability",
false, sortOrder++, true, false,
"NodeStat.ignoreLocalVsRemoteBandwidthLiability",
"NodeStat.ignoreLocalVsRemoteBandwidthLiabilityLong", new BooleanCallback() {
- public boolean get() {
+ public Boolean get() {
synchronized(NodeStats.this) {
return
ignoreLocalVsRemoteBandwidthLiability;
}
}
- public void set(boolean val) throws
InvalidConfigValueException {
+ public void set(Boolean val) throws
InvalidConfigValueException {
synchronized(NodeStats.this) {
ignoreLocalVsRemoteBandwidthLiability =
val;
}
Modified: trunk/freenet/src/freenet/node/TestnetHandler.java
===================================================================
--- trunk/freenet/src/freenet/node/TestnetHandler.java 2008-08-14 13:33:41 UTC
(rev 21838)
+++ trunk/freenet/src/freenet/node/TestnetHandler.java 2008-08-14 13:44:45 UTC
(rev 21839)
@@ -216,11 +216,11 @@
this.node = node;
}
- public boolean get() {
+ public Boolean get() {
return node.testnetEnabled;
}
- public void set(boolean val) throws InvalidConfigValueException
{
+ public void set(Boolean val) throws InvalidConfigValueException
{
if(node.testnetEnabled == val) return;
throw new
InvalidConfigValueException(L10n.getString("TestnetHandler.cannotEnableDisableOnTheFly"));
}
@@ -238,11 +238,11 @@
this.node = n;
}
- public int get() {
+ public Integer get() {
return node.testnetHandler.getPort();
}
- public void set(int val) throws InvalidConfigValueException {
+ public void set(Integer val) throws InvalidConfigValueException
{
if(val == get()) return;
node.testnetHandler.rebind(val);
}
Modified: trunk/freenet/src/freenet/node/TextModeClientInterfaceServer.java
===================================================================
--- trunk/freenet/src/freenet/node/TextModeClientInterfaceServer.java
2008-08-14 13:33:41 UTC (rev 21838)
+++ trunk/freenet/src/freenet/node/TextModeClientInterfaceServer.java
2008-08-14 13:44:45 UTC (rev 21839)
@@ -111,11 +111,11 @@
this.core = core;
}
- public boolean get() {
+ public Boolean get() {
return core.getTextModeClientInterface() != null;
}
- public void set(boolean val) throws InvalidConfigValueException {
+ public void set(Boolean val) throws InvalidConfigValueException {
if(val == get()) return;
// FIXME implement - see bug #122
throw new InvalidConfigValueException("Cannot be updated on the
fly");
@@ -127,11 +127,11 @@
static class TMCISSLCallback extends BooleanCallback {
- public boolean get() {
+ public Boolean get() {
return ssl;
}
- public void set(boolean val) throws InvalidConfigValueException {
+ public void set(Boolean val) throws InvalidConfigValueException {
if(val == get()) return;
if(!SSL.available()) {
throw new InvalidConfigValueException("Enable
SSL support before use ssl with TMCI");
@@ -152,11 +152,11 @@
this.core = core;
}
- public boolean get() {
+ public Boolean get() {
return core.getDirectTMCI() != null;
}
- public void set(boolean val) throws InvalidConfigValueException {
+ public void set(Boolean val) throws InvalidConfigValueException {
if(val == get()) return;
// FIXME implement - see bug #122
throw new InvalidConfigValueException("Cannot be updated on the
fly");
@@ -227,7 +227,7 @@
this.core = core;
}
- public int get() {
+ public Integer get() {
if(core.getTextModeClientInterface()!=null)
return core.getTextModeClientInterface().port;
else
@@ -235,7 +235,7 @@
}
// TODO: implement it
- public void set(int val) throws InvalidConfigValueException {
+ public void set(Integer val) throws InvalidConfigValueException {
if(val == get()) return;
core.getTextModeClientInterface().setPort(val);
}
Modified: trunk/freenet/src/freenet/node/fcp/FCPServer.java
===================================================================
--- trunk/freenet/src/freenet/node/fcp/FCPServer.java 2008-08-14 13:33:41 UTC
(rev 21838)
+++ trunk/freenet/src/freenet/node/fcp/FCPServer.java 2008-08-14 13:44:45 UTC
(rev 21839)
@@ -201,11 +201,11 @@
this.node = node;
}
- public int get() {
+ public Integer get() {
return node.getFCPServer().port;
}
- public void set(int val) throws InvalidConfigValueException {
+ public void set(Integer val) throws InvalidConfigValueException
{
if(val != get()) {
throw new InvalidConfigValueException("Cannot
change FCP port number on the fly");
}
@@ -224,11 +224,11 @@
this.node = node;
}
- public boolean get() {
+ public Boolean get() {
return node.getFCPServer().enabled;
}
//TODO: Allow it
- public void set(boolean val) throws InvalidConfigValueException
{
+ public void set(Boolean val) throws InvalidConfigValueException
{
if(val != get()) {
throw new
InvalidConfigValueException(l10n("cannotStartOrStopOnTheFly"));
}
@@ -241,11 +241,11 @@
static class FCPSSLCallback extends BooleanCallback {
- public boolean get() {
+ public Boolean get() {
return ssl;
}
- public void set(boolean val) throws InvalidConfigValueException
{
+ public void set(Boolean val) throws InvalidConfigValueException
{
if(val == get()) return;
if(!SSL.available()) {
throw new InvalidConfigValueException("Enable
SSL support before use ssl with FCP");
@@ -334,11 +334,11 @@
FCPServer server;
- public boolean get() {
+ public Boolean get() {
return server.persistentDownloadsEnabled();
}
- public void set(boolean set) {
+ public void set(Boolean set) {
if(server.persistentDownloadsEnabled() != set)
server.setPersistentDownloadsEnabled(set);
}
@@ -364,11 +364,11 @@
FCPServer server;
- public long get() {
+ public Long get() {
return server.persistenceInterval;
}
- public void set(long value) {
+ public void set(Long value) {
server.persistenceInterval = value;
FCPServerPersister p = server.persister;
if(p != null) {
@@ -382,11 +382,11 @@
static class AssumeDDADownloadIsAllowedCallback extends BooleanCallback
{
FCPServer server;
- public boolean get() {
+ public Boolean get() {
return server.assumeDownloadDDAIsAllowed;
}
- public void set(boolean val) throws InvalidConfigValueException
{
+ public void set(Boolean val) throws InvalidConfigValueException
{
if(val == get()) return;
server.assumeDownloadDDAIsAllowed = val;
}
@@ -395,11 +395,11 @@
static class AssumeDDAUploadIsAllowedCallback extends BooleanCallback {
FCPServer server;
- public boolean get() {
+ public Boolean get() {
return server.assumeUploadDDAIsAllowed;
}
- public void set(boolean val) throws InvalidConfigValueException
{
+ public void set(Boolean val) throws InvalidConfigValueException
{
if(val == get()) return;
server.assumeUploadDDAIsAllowed = val;
}
Modified: trunk/freenet/src/freenet/node/updater/NodeUpdateManager.java
===================================================================
--- trunk/freenet/src/freenet/node/updater/NodeUpdateManager.java
2008-08-14 13:33:41 UTC (rev 21838)
+++ trunk/freenet/src/freenet/node/updater/NodeUpdateManager.java
2008-08-14 13:44:45 UTC (rev 21839)
@@ -806,22 +806,22 @@
class UpdaterEnabledCallback extends BooleanCallback {
- public boolean get() {
+ public Boolean get() {
return isEnabled();
}
- public void set(boolean val) throws InvalidConfigValueException
{
+ public void set(Boolean val) throws InvalidConfigValueException
{
enable(val);
}
}
class AutoUpdateAllowedCallback extends BooleanCallback {
- public boolean get() {
+ public Boolean get() {
return isAutoUpdateAllowed();
}
- public void set(boolean val) throws InvalidConfigValueException
{
+ public void set(Boolean val) throws InvalidConfigValueException
{
setAutoUpdateAllowed(val);
}
}
Modified: trunk/freenet/src/freenet/support/Fields.java
===================================================================
--- trunk/freenet/src/freenet/support/Fields.java 2008-08-14 13:33:41 UTC
(rev 21838)
+++ trunk/freenet/src/freenet/support/Fields.java 2008-08-14 13:44:45 UTC
(rev 21839)
@@ -684,6 +684,60 @@
return res;
}
+ public static String longToString(long val) {
+ String[] u = { "k", "K", "m", "M", "g", "G", "t", "T", "p",
"P", "e", "E" };
+ String ret = Long.toString(val);
+
+ if (val <= 0)
+ return ret;
+
+ for (int i = MULTIPLES.length - 1; i >= 0; i--) {
+ if (val > MULTIPLES[i] && val % MULTIPLES[i] == 0) {
+ ret = (val / MULTIPLES[i]) + u[i];
+ if (!u[i].toLowerCase().equals(u[i]))
+ ret += "iB";
+ break;
+ }
+ }
+ return ret;
+ }
+
+ public static String intToString(int val) {
+ String[] u = { "k", "K", "m", "M", "g", "G", "t", "T", "p",
"P", "e", "E" };
+ String ret = Integer.toString(val);
+
+ if (val <= 0)
+ return ret;
+
+ for (int i = MULTIPLES.length - 1; i >= 0; i--) {
+ if (val > MULTIPLES[i] && val % MULTIPLES[i] == 0) {
+ ret = (val / MULTIPLES[i]) + u[i];
+ if (!u[i].toLowerCase().equals(u[i]))
+ ret += "iB";
+ break;
+ }
+ }
+ return ret;
+ }
+
+ public static String shortToString(short val) {
+ String[] u = { "k", "K", "m", "M", "g", "G", "t", "T", "p",
"P", "e", "E" };
+ String ret = Short.toString(val);
+
+ if (val <= 0)
+ return ret;
+
+ for (int i = MULTIPLES.length - 1; i >= 0; i--) {
+ if (val > MULTIPLES[i] && val % MULTIPLES[i] == 0) {
+ ret = (val / MULTIPLES[i]) + u[i];
+ if (!u[i].toLowerCase().equals(u[i]))
+ ret += "iB";
+ break;
+ }
+ }
+ return ret;
+ }
+
public static double[] bytesToDoubles(byte[] data, int offset, int
length) {
long[] longs = bytesToLongs(data, offset, length);
double[] doubles = new double[longs.length];
Modified: trunk/freenet/src/freenet/support/api/BooleanCallback.java
===================================================================
--- trunk/freenet/src/freenet/support/api/BooleanCallback.java 2008-08-14
13:33:41 UTC (rev 21838)
+++ trunk/freenet/src/freenet/support/api/BooleanCallback.java 2008-08-14
13:44:45 UTC (rev 21839)
@@ -4,25 +4,10 @@
package freenet.support.api;
import freenet.config.ConfigCallback;
-import freenet.config.InvalidConfigValueException;
/**
* A callback to be called when a config value of integer type changes.
* Also reports the current value.
*/
-public abstract class BooleanCallback extends ConfigCallback {
-
- /**
- * Get the current, used value of the config variable.
- */
- public abstract boolean get();
-
- /**
- * Set the config variable to a new value.
- * @param val The new value.
- * @throws InvalidConfigOptionException If the new value is invalid for
- * this particular option.
- */
- public abstract void set(boolean val) throws
InvalidConfigValueException;
-
+public abstract class BooleanCallback extends ConfigCallback<Boolean> {
}
Modified: trunk/freenet/src/freenet/support/api/IntCallback.java
===================================================================
--- trunk/freenet/src/freenet/support/api/IntCallback.java 2008-08-14
13:33:41 UTC (rev 21838)
+++ trunk/freenet/src/freenet/support/api/IntCallback.java 2008-08-14
13:44:45 UTC (rev 21839)
@@ -4,25 +4,10 @@
package freenet.support.api;
import freenet.config.ConfigCallback;
-import freenet.config.InvalidConfigValueException;
/**
* A callback to be called when a config value of integer type changes.
* Also reports the current value.
*/
-public abstract class IntCallback extends ConfigCallback {
-
- /**
- * Get the current, used value of the config variable.
- */
- public abstract int get();
-
- /**
- * Set the config variable to a new value.
- * @param val The new value.
- * @throws InvalidConfigOptionException If the new value is invalid for
- * this particular option.
- */
- public abstract void set(int val) throws InvalidConfigValueException;
-
+public abstract class IntCallback extends ConfigCallback<Integer> {
}
Modified: trunk/freenet/src/freenet/support/api/LongCallback.java
===================================================================
--- trunk/freenet/src/freenet/support/api/LongCallback.java 2008-08-14
13:33:41 UTC (rev 21838)
+++ trunk/freenet/src/freenet/support/api/LongCallback.java 2008-08-14
13:44:45 UTC (rev 21839)
@@ -4,25 +4,10 @@
package freenet.support.api;
import freenet.config.ConfigCallback;
-import freenet.config.InvalidConfigValueException;
/**
* A callback to be called when a config value of long type changes.
* Also reports the current value.
*/
-public abstract class LongCallback extends ConfigCallback {
-
- /**
- * Get the current, used value of the config variable.
- */
- public abstract long get();
-
- /**
- * Set the config variable to a new value.
- * @param val The new value.
- * @throws InvalidConfigOptionException If the new value is invalid for
- * this particular option.
- */
- public abstract void set(long val) throws InvalidConfigValueException;
-
+public abstract class LongCallback extends ConfigCallback<Long> {
}
Modified: trunk/freenet/src/freenet/support/api/ShortCallback.java
===================================================================
--- trunk/freenet/src/freenet/support/api/ShortCallback.java 2008-08-14
13:33:41 UTC (rev 21838)
+++ trunk/freenet/src/freenet/support/api/ShortCallback.java 2008-08-14
13:44:45 UTC (rev 21839)
@@ -1,25 +1,10 @@
package freenet.support.api;
import freenet.config.ConfigCallback;
-import freenet.config.InvalidConfigValueException;
/**
* A callback to be called when a config value of short type changes.
* Also reports the current value.
*/
-public abstract class ShortCallback extends ConfigCallback {
-
- /**
- * Get the current, used value of the config variable.
- */
- public abstract short get();
-
- /**
- * Set the config variable to a new value.
- * @param val The new value.
- * @throws InvalidConfigOptionException If the new value is invalid for
- * this particular option.
- */
- public abstract void set(short val) throws InvalidConfigValueException;
-
+public abstract class ShortCallback extends ConfigCallback<Short> {
}
Modified: trunk/freenet/src/freenet/support/api/StringArrCallback.java
===================================================================
--- trunk/freenet/src/freenet/support/api/StringArrCallback.java
2008-08-14 13:33:41 UTC (rev 21838)
+++ trunk/freenet/src/freenet/support/api/StringArrCallback.java
2008-08-14 13:44:45 UTC (rev 21839)
@@ -4,22 +4,7 @@
package freenet.support.api;
import freenet.config.ConfigCallback;
-import freenet.config.InvalidConfigValueException;
/** Callback (getter/setter) for a string config variable */
-public abstract class StringArrCallback extends ConfigCallback {
-
- /**
- * Get the current, used value of the config variable.
- */
- public abstract String[] get();
-
- /**
- * Set the config variable to a new value.
- * @param val The new value.
- * @throws InvalidConfigOptionException If the new value is invalid for
- * this particular option.
- */
- public abstract void set(String[] val) throws
InvalidConfigValueException;
-
+public abstract class StringArrCallback extends ConfigCallback<String[]> {
}
Modified: trunk/freenet/src/freenet/support/api/StringCallback.java
===================================================================
--- trunk/freenet/src/freenet/support/api/StringCallback.java 2008-08-14
13:33:41 UTC (rev 21838)
+++ trunk/freenet/src/freenet/support/api/StringCallback.java 2008-08-14
13:44:45 UTC (rev 21839)
@@ -4,22 +4,8 @@
package freenet.support.api;
import freenet.config.ConfigCallback;
-import freenet.config.InvalidConfigValueException;
/** Callback (getter/setter) for a string config variable */
-public abstract class StringCallback extends ConfigCallback {
-
- /**
- * Get the current, used value of the config variable.
- */
- public abstract String get();
+public abstract class StringCallback extends ConfigCallback<String> {
- /**
- * Set the config variable to a new value.
- * @param val The new value.
- * @throws InvalidConfigOptionException If the new value is invalid for
- * this particular option.
- */
- public abstract void set(String val) throws InvalidConfigValueException;
-
}