r26754 - in trunk/freenet/src/freenet: config node support

[email protected]
Newsgroups gmane.network.freenet.cvs,gmane.spam.detected
Message-ID <[email protected]>
Author: j16sdiz
Date: 2009-04-13 15:15:51 +0000 (Mon, 13 Apr 2009)
New Revision: 26754

Modified:
   trunk/freenet/src/freenet/config/IntOption.java
   trunk/freenet/src/freenet/config/LongOption.java
   trunk/freenet/src/freenet/config/ShortOption.java
   trunk/freenet/src/freenet/config/SubConfig.java
   trunk/freenet/src/freenet/node/LoggingConfigHandler.java
   trunk/freenet/src/freenet/node/Node.java
   trunk/freenet/src/freenet/support/Fields.java
Log:
Option.isSize to flag "size" option (fix bug 2614)

Modified: trunk/freenet/src/freenet/config/IntOption.java
===================================================================
--- trunk/freenet/src/freenet/config/IntOption.java	2009-04-12 21:27:13 UTC (rev 26753)
+++ trunk/freenet/src/freenet/config/IntOption.java	2009-04-13 15:15:51 UTC (rev 26754)
@@ -9,17 +9,20 @@
 
 /** Integer config variable */
 public class IntOption extends Option<Integer> {
+	protected final boolean isSize;
+
 	public IntOption(SubConfig conf, String optionName, String defaultValueString, int sortOrder, boolean expert,
-	        boolean forceWrite, String shortDesc, String longDesc, IntCallback cb) {
+	        boolean forceWrite, String shortDesc, String longDesc, IntCallback cb, boolean isSize) {
 		this(conf, optionName, Fields.parseInt(defaultValueString), sortOrder, expert, forceWrite, shortDesc, longDesc,
-		        cb);
+		        cb, isSize);
 	}
 	
 	public IntOption(SubConfig conf, String optionName, Integer defaultValue, int sortOrder, boolean expert,
-	        boolean forceWrite, String shortDesc, String longDesc, IntCallback cb) {
+	        boolean forceWrite, String shortDesc, String longDesc, IntCallback cb, boolean isSize) {
 		super(conf, optionName, cb, sortOrder, expert, forceWrite, shortDesc, longDesc, Option.DataType.NUMBER);
 		this.defaultValue = defaultValue;
 		this.currentValue = defaultValue;
+		this.isSize = isSize;
 	}
 
 	@Override
@@ -39,6 +42,6 @@
 
 	@Override
 	protected String toString(Integer val) {
-		return Fields.intToString(val);
+		return Fields.intToString(val, isSize);
 	}
 }

Modified: trunk/freenet/src/freenet/config/LongOption.java
===================================================================
--- trunk/freenet/src/freenet/config/LongOption.java	2009-04-12 21:27:13 UTC (rev 26753)
+++ trunk/freenet/src/freenet/config/LongOption.java	2009-04-13 15:15:51 UTC (rev 26754)
@@ -9,17 +9,20 @@
 
 /** Long config variable */
 public class LongOption extends Option<Long> {
+	protected final boolean isSize;
+
 	public LongOption(SubConfig conf, String optionName, String defaultValueString, int sortOrder, boolean expert,
-	        boolean forceWrite, String shortDesc, String longDesc, LongCallback cb) {
+	        boolean forceWrite, String shortDesc, String longDesc, LongCallback cb, boolean isSize) {
 		this(conf, optionName, Fields.parseLong(defaultValueString), sortOrder, expert, forceWrite, shortDesc,
-		        longDesc, cb);
+		        longDesc, cb, isSize);
 	}
 	
 	public LongOption(SubConfig conf, String optionName, Long defaultValue, int sortOrder, boolean expert,
-	        boolean forceWrite, String shortDesc, String longDesc, LongCallback cb) {
+	        boolean forceWrite, String shortDesc, String longDesc, LongCallback cb, boolean isSize) {
 		super(conf, optionName, cb, sortOrder, expert, forceWrite, shortDesc, longDesc, Option.DataType.NUMBER);
 		this.defaultValue = defaultValue;
 		this.currentValue = defaultValue;
+		this.isSize = isSize;
 	}
 
 	@Override
@@ -39,6 +42,6 @@
 	
 	@Override
 	protected String toString(Long val) {
-		return Fields.longToString(val);
+		return Fields.longToString(val, isSize);
 	}
 }

Modified: trunk/freenet/src/freenet/config/ShortOption.java
===================================================================
--- trunk/freenet/src/freenet/config/ShortOption.java	2009-04-12 21:27:13 UTC (rev 26753)
+++ trunk/freenet/src/freenet/config/ShortOption.java	2009-04-13 15:15:51 UTC (rev 26754)
@@ -5,11 +5,14 @@
 import freenet.support.api.ShortCallback;
 
 public class ShortOption extends Option<Short> {
+	protected final boolean isSize;
+	
 	public ShortOption(SubConfig conf, String optionName, short defaultValue, int sortOrder, 
-			boolean expert, boolean forceWrite, String shortDesc, String longDesc, ShortCallback cb) {
+			boolean expert, boolean forceWrite, String shortDesc, String longDesc, ShortCallback cb, boolean isSize) {
 		super(conf, optionName, cb, sortOrder, expert, forceWrite, shortDesc, longDesc, Option.DataType.NUMBER);
 		this.defaultValue = defaultValue;
 		this.currentValue = defaultValue;
+		this.isSize = isSize;
 	}
 
 	private String l10n(String key, String pattern, String value) {
@@ -29,6 +32,6 @@
 
 	@Override
 	protected String toString(Short val) {
-		return Fields.shortToString(val);
+		return Fields.shortToString(val, isSize);
 	}	
 }

Modified: trunk/freenet/src/freenet/config/SubConfig.java
===================================================================
--- trunk/freenet/src/freenet/config/SubConfig.java	2009-04-12 21:27:13 UTC (rev 26753)
+++ trunk/freenet/src/freenet/config/SubConfig.java	2009-04-13 15:15:51 UTC (rev 26754)
@@ -61,27 +61,27 @@
 	}
 	
 	public void register(String optionName, int defaultValue, int sortOrder,
-			boolean expert, boolean forceWrite, String shortDesc, String longDesc, IntCallback cb) {
+			boolean expert, boolean forceWrite, String shortDesc, String longDesc, IntCallback cb, boolean isSize) {
 		if(cb == null) cb = new NullIntCallback();
-		register(new IntOption(this, optionName, defaultValue, sortOrder, expert, forceWrite, shortDesc, longDesc, cb));
+		register(new IntOption(this, optionName, defaultValue, sortOrder, expert, forceWrite, shortDesc, longDesc, cb, isSize));
 	}
 	
 	public void register(String optionName, long defaultValue, int sortOrder,
-			boolean expert, boolean forceWrite, String shortDesc, String longDesc, LongCallback cb) {
+			boolean expert, boolean forceWrite, String shortDesc, String longDesc, LongCallback cb, boolean isSize) {
 		if(cb == null) cb = new NullLongCallback();
-		register(new LongOption(this, optionName, defaultValue, sortOrder, expert, forceWrite, shortDesc, longDesc, cb));
+		register(new LongOption(this, optionName, defaultValue, sortOrder, expert, forceWrite, shortDesc, longDesc, cb, isSize));
 	}
 	
 	public void register(String optionName, String defaultValueString, int sortOrder,
-			boolean expert, boolean forceWrite, String shortDesc, String longDesc, IntCallback cb) {
+			boolean expert, boolean forceWrite, String shortDesc, String longDesc, IntCallback cb, boolean isSize) {
 		if(cb == null) cb = new NullIntCallback();
-		register(new IntOption(this, optionName, defaultValueString, sortOrder, expert, forceWrite, shortDesc, longDesc, cb));
+		register(new IntOption(this, optionName, defaultValueString, sortOrder, expert, forceWrite, shortDesc, longDesc, cb, isSize));
 	}
 	
 	public void register(String optionName, String defaultValueString, int sortOrder,
-			boolean expert, boolean forceWrite, String shortDesc, String longDesc, LongCallback cb) {
+			boolean expert, boolean forceWrite, String shortDesc, String longDesc, LongCallback cb, boolean isSize) {
 		if(cb == null) cb = new NullLongCallback();
-		register(new LongOption(this, optionName, defaultValueString, sortOrder, expert, forceWrite, shortDesc, longDesc, cb));
+		register(new LongOption(this, optionName, defaultValueString, sortOrder, expert, forceWrite, shortDesc, longDesc, cb, isSize));
 	}
 	
 	public void register(String optionName, boolean defaultValue, int sortOrder,
@@ -97,9 +97,9 @@
 	}
 	
 	public void register(String optionName, short defaultValue, int sortOrder,
-			boolean expert, boolean forceWrite, String shortDesc, String longDesc, ShortCallback cb) {
+			boolean expert, boolean forceWrite, String shortDesc, String longDesc, ShortCallback cb, boolean isSize) {
 		if(cb == null) cb = new NullShortCallback();
-		register(new ShortOption(this, optionName, defaultValue, sortOrder, expert, forceWrite, shortDesc, longDesc, cb));
+		register(new ShortOption(this, optionName, defaultValue, sortOrder, expert, forceWrite, shortDesc, longDesc, cb, isSize));
 	}
 	
 	public void register(String optionName, String[] defaultValue, int sortOrder,

Modified: trunk/freenet/src/freenet/node/LoggingConfigHandler.java
===================================================================
--- trunk/freenet/src/freenet/node/LoggingConfigHandler.java	2009-04-12 21:27:13 UTC (rev 26753)
+++ trunk/freenet/src/freenet/node/LoggingConfigHandler.java	2009-04-13 15:15:51 UTC (rev 26754)
@@ -126,7 +126,7 @@
 							fileLoggerHook.setMaxOldLogsSize(val);
 						}
 					}
-    	});
+    	}, true);
     	
     	maxZippedLogsSize = config.getLong("maxZippedLogsSize");
     	
@@ -202,7 +202,7 @@
 						if(fileLoggerHook != null)
 							fileLoggerHook.setMaxListBytes(val);
 					}
-    	});
+    	}, true);
     	
     	maxCachedLogBytes = config.getLong("maxCachedBytes");
     	
@@ -221,7 +221,7 @@
 						if(fileLoggerHook != null)
 							fileLoggerHook.setMaxListLength(val);
 					}
-    	});
+    	}, false);
     	
     	maxCachedLogLines = config.getInt("maxCachedLines");
     	

Modified: trunk/freenet/src/freenet/node/Node.java
===================================================================
--- trunk/freenet/src/freenet/node/Node.java	2009-04-12 21:27:13 UTC (rev 26753)
+++ trunk/freenet/src/freenet/node/Node.java	2009-04-13 15:15:51 UTC (rev 26754)
@@ -1010,7 +1010,7 @@
 						if(maxHTL < 0) throw new InvalidConfigValueException("Impossible max HTL");
 						maxHTL = val;
 					}
-		});
+		}, false);
 		
 		maxHTL = nodeConfig.getShort("maxHTL");
 		
@@ -1257,7 +1257,7 @@
 						outputThrottle.changeNanosAndBucketSize((1000L * 1000L * 1000L) / obwLimit, obwLimit/2);
 						nodeStats.setOutputLimit(obwLimit);
 					}
-		});
+		}, false);
 		
 		int obwLimit = nodeConfig.getInt("outputBandwidthLimit");
 		if(obwLimit <= 0)
@@ -1293,7 +1293,7 @@
 						}
 						nodeStats.setInputLimit(ibwLimit);
 					}
-		});
+		}, true);
 		
 		int ibwLimit = nodeConfig.getInt("inputBandwidthLimit");
 		if(ibwLimit == -1) {
@@ -1471,7 +1471,7 @@
 						maxOpennetPeers = inputMaxOpennetPeers;
 						}
 					}
-		);
+		, false);
 		
 		maxOpennetPeers = opennetConfig.getInt("maxOpennetPeers");
 		if(maxOpennetPeers > 20) {
@@ -1665,7 +1665,7 @@
 						nodeStats.avgStoreLocation.changeMaxReports((int)maxStoreKeys);
 						nodeStats.avgCacheLocation.changeMaxReports((int)maxCacheKeys);
 					}
-		});
+		}, true);
 		
 		maxTotalDatastoreSize = nodeConfig.getLong("storeSize");
 		
@@ -1696,7 +1696,7 @@
 					public boolean isReadOnly() {
 				        return !("salt-hash".equals(storeType));
 			        }
-		        });
+		        }, true);
 
 		storeBloomFilterSize = nodeConfig.getInt("storeBloomFilterSize");
 
@@ -1850,7 +1850,7 @@
 					databaseMaxMemory = val;
 				}
 				
-			});
+			}, true);
 
 			/* There are some JVMs (for example libgcj 4.1.1) whose Runtime.maxMemory() does not work. */
 			long maxHeapMemory = Runtime.getRuntime().maxMemory();

Modified: trunk/freenet/src/freenet/support/Fields.java
===================================================================
--- trunk/freenet/src/freenet/support/Fields.java	2009-04-12 21:27:13 UTC (rev 26753)
+++ trunk/freenet/src/freenet/support/Fields.java	2009-04-13 15:15:51 UTC (rev 26754)
@@ -687,16 +687,16 @@
 		return res;
 	}
 
-	public static String longToString(long val) {
+	public static String longToString(long val, boolean isSize) {
 		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) {
+			if(val > MULTIPLES[i] && val % MULTIPLES[i] == 0 && (isSize || MULTIPLES[i] % 1000 == 0)) {
 				ret = (val / MULTIPLES[i]) + MULTIPLES_2[i];
-				if(!MULTIPLES_2[i].toLowerCase().equals(MULTIPLES_2[i]))
+				if(!MULTIPLES_2[i].toLowerCase().equals(MULTIPLES_2[i])) 
 					ret += "iB";
 				break;
 			}
@@ -704,14 +704,14 @@
 		return ret;
 	}
 
-	public static String intToString(int val) {
+	public static String intToString(int val, boolean isSize) {
 		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) {
+			if(val > MULTIPLES[i] && val % MULTIPLES[i] == 0 && (isSize || MULTIPLES[i] % 1000 == 0)) {
 				ret = (val / MULTIPLES[i]) + MULTIPLES_2[i];
 				if(!MULTIPLES_2[i].toLowerCase().equals(MULTIPLES_2[i]))
 					ret += "iB";
@@ -721,14 +721,14 @@
 		return ret;
 	}
 
-	public static String shortToString(short val) {
+	public static String shortToString(short val, boolean isSize) {
 		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) {
+			if(val > MULTIPLES[i] && val % MULTIPLES[i] == 0 && (isSize || MULTIPLES[i] % 1000 == 0)) {
 				ret = (val / MULTIPLES[i]) + MULTIPLES_2[i];
 				if(!MULTIPLES_2[i].toLowerCase().equals(MULTIPLES_2[i]))
 					ret += "iB";
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.