Author: toad
Date: 2006-09-01 21:09:51 +0000 (Fri, 01 Sep 2006)
New Revision: 10334

Modified:
   trunk/freenet/src/freenet/config/FilePersistentConfig.java
Log:
Save some memory in config.
Throw an exception if we try to add a config option after finishedInit().

Modified: trunk/freenet/src/freenet/config/FilePersistentConfig.java
===================================================================
--- trunk/freenet/src/freenet/config/FilePersistentConfig.java  2006-09-01 
21:06:19 UTC (rev 10333)
+++ trunk/freenet/src/freenet/config/FilePersistentConfig.java  2006-09-01 
21:09:51 UTC (rev 10334)
@@ -29,6 +29,7 @@
        final File filename;
        final File tempFilename;
        private SimpleFieldSet origConfigFileContents;
+       private boolean finishedInit;

        public FilePersistentConfig(File f) throws IOException {
                this.filename = f;
@@ -84,7 +85,7 @@
                        LineReadingInputStream lis = new 
LineReadingInputStream(bis);
                        // Config file is UTF-8 too!
                        synchronized (this) {
-                               origConfigFileContents = new 
SimpleFieldSet(lis, 32768, 128, true, true);       
+                               origConfigFileContents = new 
SimpleFieldSet(lis, 32768, 128, true, true);
                        }
                } finally {
                        try {
@@ -104,12 +105,14 @@
         * Finished initialization. So any remaining options must be invalid.
         */
        public synchronized void finishedInit() {
+               finishedInit = true;
                if(origConfigFileContents == null) return;
                Iterator i = origConfigFileContents.keyIterator();
                while(i.hasNext()) {
                        String key = (String) i.next();
                        Logger.error(this, "Unknown option: "+key+" 
(value="+origConfigFileContents.get(key)+")");
                }
+               origConfigFileContents = null;
        }

        public void store() {
@@ -167,6 +170,8 @@
        public void onRegister(SubConfig config, Option o) {
                String val, name;
                synchronized(this) {
+                       if(finishedInit)
+                               throw new 
IllegalStateException("onRegister("+config+":"+o+") called after finishedInit() 
!!");
                        if(origConfigFileContents == null) return;
                        name = 
config.prefix+SimpleFieldSet.MULTI_LEVEL_CHAR+o.name;
                        val = origConfigFileContents.get(name);


Reply via email to