Author: toad
Date: 2006-09-01 21:02:44 +0000 (Fri, 01 Sep 2006)
New Revision: 10332

Modified:
   trunk/freenet/src/freenet/clients/http/BookmarkManager.java
   trunk/freenet/src/freenet/clients/http/ConfigToadlet.java
   trunk/freenet/src/freenet/clients/http/PluginToadlet.java
   trunk/freenet/src/freenet/clients/http/PproxyToadlet.java
   trunk/freenet/src/freenet/clients/http/SymlinkerToadlet.java
   trunk/freenet/src/freenet/clients/http/WelcomeToadlet.java
   trunk/freenet/src/freenet/node/NodeClientCore.java
   trunk/freenet/src/freenet/node/TextModeClientInterface.java
   trunk/freenet/src/freenet/plugin/PluginManager.java
   trunk/freenet/src/freenet/pluginmanager/PluginManager.java
Log:
Store the config file when changes are made.
But don't do it on-thread, to avoid deadlocks, and don't do it during startup, 
to avoid corruption.

Modified: trunk/freenet/src/freenet/clients/http/BookmarkManager.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/BookmarkManager.java 2006-09-01 
20:41:57 UTC (rev 10331)
+++ trunk/freenet/src/freenet/clients/http/BookmarkManager.java 2006-09-01 
21:02:44 UTC (rev 10332)
@@ -73,6 +73,7 @@
                                } catch (MalformedURLException mue) {
                                }
                        }
+                       node.storeConfig();
                }
        }

@@ -85,7 +86,7 @@
                String[] initialbookmarks = sc.getStringArr("bookmarks");
                for (int i = 0; i < initialbookmarks.length; i++) {
                        try {
-                               addBookmark(new Bookmark(initialbookmarks[i]));
+                               addBookmark(new Bookmark(initialbookmarks[i]), 
false);
                        } catch (MalformedURLException mue) {
                                // just ignore that one
                        }
@@ -126,7 +127,7 @@
                this.bookmarks.clear();
        }

-       public void addBookmark(Bookmark b) {
+       public void addBookmark(Bookmark b, boolean store) {
                this.bookmarks.add(b);
                if (b.getKeyType().equals("USK")) {
                        try {
@@ -136,9 +137,10 @@

                        }
                }
+               if(store) node.storeConfig();
        }

-       public void removeBookmark(Bookmark b) {
+       public void removeBookmark(Bookmark b, boolean store) {
                if (b.getKeyType().equals("USK")) {
                        try {
                                USK u = USK.create(b.key);
@@ -148,5 +150,6 @@
                        }
                }
                this.bookmarks.remove(b);
+               if(store) node.storeConfig();
        }
 }

Modified: trunk/freenet/src/freenet/clients/http/ConfigToadlet.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/ConfigToadlet.java   2006-09-01 
20:41:57 UTC (rev 10331)
+++ trunk/freenet/src/freenet/clients/http/ConfigToadlet.java   2006-09-01 
21:02:44 UTC (rev 10332)
@@ -84,6 +84,7 @@
                                }
                        }
                }
+               core.storeConfig();

                HTMLNode pageNode = 
ctx.getPageMaker().getPageNode("Configuration Applied");
                HTMLNode contentNode = 
ctx.getPageMaker().getContentNode(pageNode);

Modified: trunk/freenet/src/freenet/clients/http/PluginToadlet.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/PluginToadlet.java   2006-09-01 
20:41:57 UTC (rev 10331)
+++ trunk/freenet/src/freenet/clients/http/PluginToadlet.java   2006-09-01 
21:02:44 UTC (rev 10332)
@@ -139,7 +139,7 @@
                        pluginName = httpRequest.getParam("pluginName");
                        boolean added = false;
                        try {
-                               pluginManager.addPlugin(pluginName);
+                               pluginManager.addPlugin(pluginName, true);
                                added = true;
                        } catch (IllegalArgumentException iae1) {
                        }
@@ -151,14 +151,14 @@
                } else if ("reload".equals(action)) {
                        pluginName = httpRequest.getParam("pluginName");
                        Plugin plugin = findPlugin(pluginName);
-                       pluginManager.removePlugin(plugin);
-                       pluginManager.addPlugin(plugin.getClass().getName());
+                       pluginManager.removePlugin(plugin, false);
+                       pluginManager.addPlugin(plugin.getClass().getName(), 
false);
                        writePermanentRedirect(ctx, "Plugin list", 
"?action=list");
                        return;
                } else if ("unload".equals(action)) {
                        pluginName = httpRequest.getParam("pluginName");
                        Plugin plugin = findPlugin(pluginName);
-                       pluginManager.removePlugin(plugin);
+                       pluginManager.removePlugin(plugin, true);
                        writePermanentRedirect(ctx, "Plugin list", 
"?action=list");
                        return;
                }

Modified: trunk/freenet/src/freenet/clients/http/PproxyToadlet.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/PproxyToadlet.java   2006-09-01 
20:41:57 UTC (rev 10331)
+++ trunk/freenet/src/freenet/clients/http/PproxyToadlet.java   2006-09-01 
21:02:44 UTC (rev 10332)
@@ -63,7 +63,7 @@
                }

                if (request.isParameterSet("load")) {
-                       pm.startPlugin(request.getParam("load"));
+                       pm.startPlugin(request.getParam("load"), true);
                        //writeReply(ctx, 200, "text/html", "OK", 
mkForwardPage("Loading plugin", "Loading plugin...", ".", 5));

                        headers.put("Location", ".");
@@ -115,7 +115,7 @@
                                //writeReply(ctx, 200, "text/html", "OK", 
mkForwardPage(ctx,"Error", "Plugin not found...", ".", 5));
                        } else {
                                pm.killPlugin(request.getParam("reload"));
-                               pm.startPlugin(fn);
+                               pm.startPlugin(fn, true);

                                headers.put("Location", ".");
                                ctx.sendReplyHeaders(302, "Found", headers, 
null, 0);

Modified: trunk/freenet/src/freenet/clients/http/SymlinkerToadlet.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/SymlinkerToadlet.java        
2006-09-01 20:41:57 UTC (rev 10331)
+++ trunk/freenet/src/freenet/clients/http/SymlinkerToadlet.java        
2006-09-01 21:02:44 UTC (rev 10332)
@@ -17,10 +17,12 @@
 public class SymlinkerToadlet extends Toadlet {

        private final HashMap linkMap = new HashMap();
+       private final Node node;
        SubConfig tslconfig;

        public SymlinkerToadlet(HighLevelSimpleClient client,final Node node) {
                super(client);
+               this.node = node;
                tslconfig = new SubConfig("toadletsymlinker", node.config);
                tslconfig.register("symlinks", null, 9, true, false, "Symlinks 
in ToadletServer", 
                                "A list of \"alias#target\"'s that forms a 
bunch of symlinks", 
@@ -48,7 +50,7 @@
                                //System.err.println("Load: " + 
StringArrOption.decode(fns[i]));
                                String tuple[] = 
StringArrOption.decode(fns[i]).split("#");
                                if (tuple.length == 2)
-                                       addLink(tuple[0], tuple[1]);
+                                       addLink(tuple[0], tuple[1], false);
                        }
                tslconfig.finishedInitialization();

@@ -59,33 +61,39 @@
                                if (tuple.length == 2)
                                        Logger.normal(this, "Added link: " + 
tuple[0] + " => " + tuple[1]);
                        }
-               addLink("/sl/search/", "/plugins/plugins.Librarian/");
-               addLink("/sl/gallery/", "/plugins/plugins.TestGallery/");
+               addLink("/sl/search/", "/plugins/plugins.Librarian/", false);
+               addLink("/sl/gallery/", "/plugins/plugins.TestGallery/", false);
        }

-       public boolean addLink(String alias, String target) {
+       public boolean addLink(String alias, String target, boolean store) {
+               boolean ret;
                synchronized (linkMap) {
                        if (linkMap.put(alias, target) == alias) {
                                Logger.normal(this, "Adding link: " + alias + " 
=> " + target);
-                               return true;
+                               ret = true;
                        } else {
                                Logger.error(this, "Adding link: " + alias + " 
=> " + target);
-                               return false;
+                               ret = false;
                        }
                }
+               if(store) node.clientCore.storeConfig();
+               return ret;
        }

-       public boolean removeLink(String alias) {
+       public boolean removeLink(String alias, boolean store) {
+               boolean ret;
                synchronized (linkMap) {
                        Object o;
                        if ((o = linkMap.remove(alias))!= null) {
                                Logger.normal(this, "Removing link: " + alias + 
" => " + o);
-                               return true;
+                               ret = true;
                        } else {
                                Logger.error(this, "Adding link: " + alias + " 
=> " + o);
-                               return false;
+                               ret = false;
                        }
                }
+               if(store) node.clientCore.storeConfig();
+               return ret;
        }

        private String getConfigLoadString() {

Modified: trunk/freenet/src/freenet/clients/http/WelcomeToadlet.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/WelcomeToadlet.java  2006-09-01 
20:41:57 UTC (rev 10331)
+++ trunk/freenet/src/freenet/clients/http/WelcomeToadlet.java  2006-09-01 
21:02:44 UTC (rev 10332)
@@ -119,7 +119,7 @@
                        return;
                } else if (request.isParameterSet("addbookmark")) {
                        try {
-                               bookmarks.addBookmark(new 
Bookmark(request.getParam("key"), request.getParam("name")));
+                               bookmarks.addBookmark(new 
Bookmark(request.getParam("key"), request.getParam("name")), true);
                        } catch (MalformedURLException mue) {
                                this.sendBookmarkEditPage(ctx, MODE_ADD, null, 
request.getParam("key"), request.getParam("name"), "Given key does not appear 
to be a valid Freenet key.");
                                return;
@@ -136,7 +136,7 @@
                                Bookmark b = (Bookmark)e.nextElement();

                                if 
(request.isParameterSet("delete_"+b.hashCode())) {
-                                       bookmarks.removeBookmark(b);
+                                       bookmarks.removeBookmark(b, true);
                                } else if 
(request.isParameterSet("edit_"+b.hashCode())) {
                                        this.sendBookmarkEditPage(ctx, b);
                                        return;
@@ -144,8 +144,8 @@
                                        // removing it and adding means that 
any USK subscriptions are updated properly
                                        try {
                                                Bookmark newbkmk = new 
Bookmark(request.getParam("key"), request.getParam("name"));
-                                               bookmarks.removeBookmark(b);
-                                               bookmarks.addBookmark(newbkmk);
+                                               bookmarks.removeBookmark(b, 
false);
+                                               bookmarks.addBookmark(newbkmk, 
true);
                                        } catch (MalformedURLException mue) {
                                                this.sendBookmarkEditPage(ctx, 
MODE_EDIT, b, request.getParam("key"), request.getParam("name"), "Given key 
does not appear to be a valid freenet key.");
                                                return;

Modified: trunk/freenet/src/freenet/node/NodeClientCore.java
===================================================================
--- trunk/freenet/src/freenet/node/NodeClientCore.java  2006-09-01 20:41:57 UTC 
(rev 10331)
+++ trunk/freenet/src/freenet/node/NodeClientCore.java  2006-09-01 21:02:44 UTC 
(rev 10332)
@@ -736,6 +736,14 @@
                        Logger.error(this, "Don't know what to do with 
"+block+" should be queued for reinsert");
        }

+       public void storeConfig() {
+               node.ps.queueTimedJob(new Runnable() {
+                       public void run() {
+                               node.config.store();
+                       }
+               }, 0);
+       }
+       
        public boolean isTestnetEnabled() {
                return node.isTestnetEnabled();
        }

Modified: trunk/freenet/src/freenet/node/TextModeClientInterface.java
===================================================================
--- trunk/freenet/src/freenet/node/TextModeClientInterface.java 2006-09-01 
20:41:57 UTC (rev 10331)
+++ trunk/freenet/src/freenet/node/TextModeClientInterface.java 2006-09-01 
21:02:44 UTC (rev 10332)
@@ -623,6 +623,7 @@
             }catch(Exception e){
                Logger.error(this, "Error setting node's name");
                }
+            core.storeConfig();
         } else if(uline.startsWith("DISABLEPEER:")) {
                String nodeIdentifier = 
(line.substring("DISABLEPEER:".length())).trim();
                if(!havePeer(nodeIdentifier)) {
@@ -753,7 +754,7 @@
                        outsb.append("");

                } else
-                       
n.pluginManager.startPlugin(line.substring("PLUGLOAD:".length()).trim());
+                       
n.pluginManager.startPlugin(line.substring("PLUGLOAD:".length()).trim(), true);
             //outsb.append("PLUGLOAD: <pkg.classname>[(@<URI to 
jarfile.jar>|<<URI to file containing real URI>|* (will load from freenets 
pluginpool))] - Load plugin.");
         } else if(uline.startsWith("PLUGLIST")) {
                outsb.append(n.pluginManager.dumpPlugins());

Modified: trunk/freenet/src/freenet/plugin/PluginManager.java
===================================================================
--- trunk/freenet/src/freenet/plugin/PluginManager.java 2006-09-01 20:41:57 UTC 
(rev 10331)
+++ trunk/freenet/src/freenet/plugin/PluginManager.java 2006-09-01 21:02:44 UTC 
(rev 10332)
@@ -88,7 +88,7 @@
                        for (int pluginIndex = 0, pluginCount = 
loadedPluginNames.length; pluginIndex < pluginCount; pluginIndex++) {
                                String pluginName = 
StringArrOption.decode(loadedPluginNames[pluginIndex]);
                                try {
-                                       addPlugin(pluginName);
+                                       addPlugin(pluginName, false);
                                } catch (IllegalArgumentException iae1) {
                                }
                        }
@@ -129,7 +129,7 @@
         * @param pluginName
         *            The name of the plugin
         */
-       public void addPlugin(String pluginName) throws 
IllegalArgumentException {
+       public void addPlugin(String pluginName, boolean store) throws 
IllegalArgumentException {
                Plugin newPlugin = createPlugin(pluginName);
                if (newPlugin == null) {
                        throw new IllegalArgumentException();
@@ -139,6 +139,8 @@
                synchronized (syncObject) {
                        plugins.add(newPlugin);
                }
+               if(store)
+                       node.clientCore.storeConfig();
        }

        /**
@@ -148,11 +150,13 @@
         * @param plugin
         *            The plugin to remove
         */
-       public void removePlugin(Plugin plugin) {
+       public void removePlugin(Plugin plugin, boolean store) {
                plugin.stopPlugin();
                synchronized (syncObject) {
                        plugins.remove(plugin);
                }
+               if(store)
+                       node.clientCore.storeConfig();
        }

        /**

Modified: trunk/freenet/src/freenet/pluginmanager/PluginManager.java
===================================================================
--- trunk/freenet/src/freenet/pluginmanager/PluginManager.java  2006-09-01 
20:41:57 UTC (rev 10331)
+++ trunk/freenet/src/freenet/pluginmanager/PluginManager.java  2006-09-01 
21:02:44 UTC (rev 10332)
@@ -71,7 +71,7 @@
                if (fns != null)
                        for (int i = 0 ; i < fns.length ; i++) {
                                //System.err.println("Load: " + 
StringArrOption.decode(fns[i]));
-                               startPlugin(StringArrOption.decode(fns[i]));
+                               startPlugin(StringArrOption.decode(fns[i]), 
false);
                        }

                        pmconfig.finishedInitialization();
@@ -100,7 +100,7 @@
                return out.toString();
        }

-       public void startPlugin(String filename) {
+       public void startPlugin(String filename, boolean store) {
                if (filename.trim().length() == 0)
                        return;
                Logger.normal(this, "Loading plugin: " + filename);
@@ -136,6 +136,7 @@
                                                UserAlert.ERROR));
                        }
                }
+               if(store) core.storeConfig();
        }

        private void registerToadlet(FredPlugin pl){
@@ -170,6 +171,8 @@
                        if (removeKey != null)
                                pluginInfo.remove(removeKey);
                }
+               if(removeKey != null)
+                       core.storeConfig();
        }

        public void addToadletSymlinks(PluginInfoWrapper pi) {


Reply via email to