Author: j16sdiz
Date: 2008-08-14 13:45:17 +0000 (Thu, 14 Aug 2008)
New Revision: 21840

Added:
   trunk/freenet/src/freenet/config/NodeNeedRestartException.java
Modified:
   trunk/freenet/src/freenet/clients/http/ConfigToadlet.java
   trunk/freenet/src/freenet/clients/http/FirstTimeWizardToadlet.java
   trunk/freenet/src/freenet/config/ConfigCallback.java
   trunk/freenet/src/freenet/config/Option.java
   trunk/freenet/src/freenet/config/SubConfig.java
   trunk/freenet/src/freenet/l10n/freenet.l10n.en.properties
   trunk/freenet/src/freenet/node/LoggingConfigHandler.java
   trunk/freenet/src/freenet/node/Node.java
Log:
show restart button

Modified: trunk/freenet/src/freenet/clients/http/ConfigToadlet.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/ConfigToadlet.java   2008-08-14 
13:44:45 UTC (rev 21839)
+++ trunk/freenet/src/freenet/clients/http/ConfigToadlet.java   2008-08-14 
13:45:17 UTC (rev 21840)
@@ -13,6 +13,7 @@
 import freenet.config.ConfigCallback;
 import freenet.config.EnumerableOptionCallback;
 import freenet.config.InvalidConfigValueException;
+import freenet.config.NodeNeedRestartException;
 import freenet.config.Option;
 import freenet.config.SubConfig;
 import freenet.config.WrapperConfig;
@@ -59,6 +60,7 @@
                }

                boolean logMINOR = Logger.shouldLog(Logger.MINOR, this);
+               boolean needRestart = false;

                for(int i=0; i<sc.length ; i++){
                        Option[] o = sc[i].getOptions();
@@ -78,6 +80,8 @@
                                                        o[j].setValue(value);
                                                } catch 
(InvalidConfigValueException e) {
                                                        
errbuf.append(o[j].getName()).append(' ').append(e.getMessage()).append('\n');
+                                               } catch 
(NodeNeedRestartException e) {
+                                                       needRestart = true;
                                                } catch (Exception e){
                             errbuf.append(o[j].getName()).append(' 
').append(e).append('\n');
                                                        Logger.error(this, 
"Caught "+e, e);
@@ -103,7 +107,24 @@

                if (errbuf.length() == 0) {
                        HTMLNode infobox = 
contentNode.addChild(ctx.getPageMaker().getInfobox("infobox-success", 
l10n("appliedTitle")));
-                       
ctx.getPageMaker().getContentNode(infobox).addChild("#", 
l10n("appliedSuccess"));
+                       HTMLNode content = 
ctx.getPageMaker().getContentNode(infobox);
+                       content.addChild("#", l10n("appliedSuccess"));
+                       
+                       if (needRestart && node.isUsingWrapper()) {
+                               content.addChild("br");
+                               content.addChild("#", l10n("needRestart"));
+                               content.addChild("br");
+                               HTMLNode restartForm = 
content.addChild("form",//
+                                       new String[] { "action", "method" }, 
new String[] { "/", "get" }//
+                                       ).addChild("div");
+                               restartForm.addChild("input",//
+                                       new String[] { "type", "name" },//
+                                       new String[] { "hidden", "restart" });
+                               restartForm.addChild("input", //
+                                       new String[] { "type", "name", "value" 
},//
+                                       new String[] { "submit", "restart2",//
+                                               l10n("restartNode") });
+                       }
                } else {
                        HTMLNode infobox = 
contentNode.addChild(ctx.getPageMaker().getInfobox("infobox-error", 
l10n("appliedFailureTitle")));
                        HTMLNode content = 
ctx.getPageMaker().getContentNode(infobox).addChild("div", "class", 
"infobox-content");

Modified: trunk/freenet/src/freenet/clients/http/FirstTimeWizardToadlet.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/FirstTimeWizardToadlet.java  
2008-08-14 13:44:45 UTC (rev 21839)
+++ trunk/freenet/src/freenet/clients/http/FirstTimeWizardToadlet.java  
2008-08-14 13:45:17 UTC (rev 21840)
@@ -11,6 +11,7 @@
 import freenet.client.HighLevelSimpleClient;
 import freenet.config.Config;
 import freenet.config.InvalidConfigValueException;
+import freenet.config.NodeNeedRestartException;
 import freenet.config.WrapperConfig;
 import freenet.l10n.L10n;
 import freenet.node.Node;
@@ -292,9 +293,13 @@
                        try {
                                config.get("node.opennet").set("enabled", 
enable);
                        } catch (InvalidConfigValueException e) {
-                               Logger.error(this, "Should not happen setting 
opennet.enabled="+enable+" please repot: "+e, e);
+                               Logger.error(this, "Should not happen setting 
opennet.enabled=" + enable + " please report: " + e, e);
                                super.writeTemporaryRedirect(ctx, "step1", 
TOADLET_URL+"?step="+WIZARD_STEP.OPENNET);
                                return;
+                       } catch (NodeNeedRestartException e) {
+                               Logger.error(this, "Should not happen setting 
opennet.enabled=" + enable + " please report: " + e, e);
+                               super.writeTemporaryRedirect(ctx, "step1", 
TOADLET_URL + "?step=" + WIZARD_STEP.OPENNET);
+                               return;
                        }
                        super.writeTemporaryRedirect(ctx, "step1", 
TOADLET_URL+"?step="+WIZARD_STEP.NAME_SELECTION);
                        return;
@@ -306,6 +311,9 @@
                                Logger.normal(this, "The node name has been set 
to "+ selectedNName);
                        } catch (InvalidConfigValueException e) {
                                Logger.error(this, "Should not happen, please 
report!" + e, e);
+                       } catch (NodeNeedRestartException e) {
+                               Logger.error(this, "Should not happen, please 
report: " + e, e);
+                               return;
                        }

                        // Attempt to skip one step if possible
@@ -340,6 +348,8 @@
                                Logger.normal(this, "The storeSize has been set 
to "+ selectedStoreSize);
                        } catch (InvalidConfigValueException e) {
                                Logger.error(this, "Should not happen, please 
report!" + e, e);
+                       } catch (NodeNeedRestartException e) {
+                               Logger.error(this, "Should not happen, please 
report!" + e, e);
                        }
                        boolean canDoStepSix = 
WrapperConfig.canChangeProperties();
                        super.writeTemporaryRedirect(ctx, "step5", 
TOADLET_URL+"?step="+(canDoStepSix?WIZARD_STEP.MEMORY:WIZARD_STEP.CONGRATZ));
@@ -372,6 +382,8 @@
                        Logger.normal(this, "The outputBandwidthLimit has been 
set to " + selectedUploadSpeed);
                } catch(InvalidConfigValueException e) {
                        Logger.error(this, "Should not happen, please report!" 
+ e, e);
+               } catch (NodeNeedRestartException e) {
+                       Logger.error(this, "Should not happen, please report!" 
+ e, e);
                }
        }

@@ -381,6 +393,8 @@
                        Logger.normal(this, "The inputBandwidthLimit has been 
set to " + selectedDownloadSpeed);
                } catch(InvalidConfigValueException e) {
                        Logger.error(this, "Should not happen, please report!" 
+ e, e);
+               } catch (NodeNeedRestartException e) {
+                       Logger.error(this, "Should not happen, please report!" 
+ e, e);
                }
        }
 }

Modified: trunk/freenet/src/freenet/config/ConfigCallback.java
===================================================================
--- trunk/freenet/src/freenet/config/ConfigCallback.java        2008-08-14 
13:44:45 UTC (rev 21839)
+++ trunk/freenet/src/freenet/config/ConfigCallback.java        2008-08-14 
13:45:17 UTC (rev 21840)
@@ -17,7 +17,7 @@
         * @throws InvalidConfigOptionException
         *             If the new value is invalid for this particular option.
         */
-       public abstract void set(T val) throws InvalidConfigValueException;
+       public abstract void set(T val) throws InvalidConfigValueException, 
NodeNeedRestartException;

        public boolean isReadOnly() {
                return false;

Added: trunk/freenet/src/freenet/config/NodeNeedRestartException.java
===================================================================
--- trunk/freenet/src/freenet/config/NodeNeedRestartException.java              
                (rev 0)
+++ trunk/freenet/src/freenet/config/NodeNeedRestartException.java      
2008-08-14 13:45:17 UTC (rev 21840)
@@ -0,0 +1,20 @@
+/* This code is part of Freenet. It is distributed under the GNU General
+ * Public License, version 2 (or at your option any later version). See
+ * http://www.gnu.org/ for further details of the GPL. */
+package freenet.config;
+
+/**
+ * Thrown when the node refuses to set a config variable to a particular
+ * value because it is invalid. Just because this is not thrown does not
+ * necessarily mean that there are no problems with the value defined,
+ * it merely means that there are no immediately detectable problems with 
+ * it.
+ */
+public class NodeNeedRestartException extends Exception {
+       private static final long serialVersionUID = -1;
+
+       public NodeNeedRestartException(String msg) {
+               super(msg);
+       }
+
+}

Modified: trunk/freenet/src/freenet/config/Option.java
===================================================================
--- trunk/freenet/src/freenet/config/Option.java        2008-08-14 13:44:45 UTC 
(rev 21839)
+++ trunk/freenet/src/freenet/config/Option.java        2008-08-14 13:45:17 UTC 
(rev 21840)
@@ -51,18 +51,22 @@
         * 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 final void setValue(String val) throws 
InvalidConfigValueException {
+       public final void setValue(String val) throws 
InvalidConfigValueException, NodeNeedRestartException {
                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;
+       protected final void set(T val) throws InvalidConfigValueException, 
NodeNeedRestartException {
+               try {
+                       cb.set(val);
+                       currentValue = val;
+               } catch (NodeNeedRestartException e) {
+                       currentValue = val;
+                       throw e;
+               }
        }

        /**
@@ -84,7 +88,7 @@
        /**
         * Call the callback with the current value of the option.
         */
-       public void forceUpdate() throws InvalidConfigValueException {
+       public void forceUpdate() throws InvalidConfigValueException, 
NodeNeedRestartException {
                setValue(getValueString());
        }


Modified: trunk/freenet/src/freenet/config/SubConfig.java
===================================================================
--- trunk/freenet/src/freenet/config/SubConfig.java     2008-08-14 13:44:45 UTC 
(rev 21839)
+++ trunk/freenet/src/freenet/config/SubConfig.java     2008-08-14 13:45:17 UTC 
(rev 21840)
@@ -185,6 +185,11 @@
                                        String msg = "Invalid config value: 
"+prefix+SimpleFieldSet.MULTI_LEVEL_CHAR+key+" = "+val+" : error: "+e;
                                        Logger.error(this, msg, e);
                                        System.err.println(msg); // might be 
about logging?
+                               } catch (NodeNeedRestartException e) {
+                                       // Impossible
+                                       String msg = "Impossible: " + prefix + 
SimpleFieldSet.MULTI_LEVEL_CHAR + key + " = " + val
+                                               + " : error: " + e;
+                                       Logger.error(this, msg, e);
                                }
                        }
                }
@@ -257,19 +262,21 @@

        /**
         * Force an option to be updated even if it hasn't changed.
-        * @throws InvalidConfigValueException 
+        * 
+        * @throws InvalidConfigValueException
+        * @throws NodeNeedRestartException
         */
-       public void forceUpdate(String optionName) throws 
InvalidConfigValueException {
+       public void forceUpdate(String optionName) throws 
InvalidConfigValueException, NodeNeedRestartException {
                Option o = map.get(optionName);
                o.forceUpdate();
        }

-       public void set(String name, String value) throws 
InvalidConfigValueException {
+       public void set(String name, String value) throws 
InvalidConfigValueException, NodeNeedRestartException {
                Option o = map.get(name);
                o.setValue(value);
        }

-       public void set(String name, boolean value) throws 
InvalidConfigValueException {
+       public void set(String name, boolean value) throws 
InvalidConfigValueException, NodeNeedRestartException {
                BooleanOption o = (BooleanOption) map.get(name);
                o.set(value);
        }

Modified: trunk/freenet/src/freenet/l10n/freenet.l10n.en.properties
===================================================================
--- trunk/freenet/src/freenet/l10n/freenet.l10n.en.properties   2008-08-14 
13:44:45 UTC (rev 21839)
+++ trunk/freenet/src/freenet/l10n/freenet.l10n.en.properties   2008-08-14 
13:45:17 UTC (rev 21840)
@@ -87,6 +87,8 @@
 ConfigToadlet.fproxy=fproxy
 ConfigToadlet.fullTitle=Freenet Node Configuration of ${name}
 ConfigToadlet.logger=logger
+ConfigToadlet.needRestart=Some config need restart to activate, restart the 
node now?
+ConfigToadlet.restartNode=Restart
 PageMaker.modeSimple=Simple interface
 PageMaker.modeSimpleTooltip=A simple interface all users can use
 PageMaker.modeAdvanced=Advanced interface

Modified: trunk/freenet/src/freenet/node/LoggingConfigHandler.java
===================================================================
--- trunk/freenet/src/freenet/node/LoggingConfigHandler.java    2008-08-14 
13:44:45 UTC (rev 21839)
+++ trunk/freenet/src/freenet/node/LoggingConfigHandler.java    2008-08-14 
13:45:17 UTC (rev 21840)
@@ -8,6 +8,7 @@

 import freenet.config.EnumerableOptionCallback;
 import freenet.config.InvalidConfigValueException;
+import freenet.config.NodeNeedRestartException;
 import freenet.config.OptionFormatException;
 import freenet.config.SubConfig;
 import freenet.support.Executor;
@@ -239,6 +240,10 @@
                        } catch (InvalidConfigValueException e2) {
                                System.err.println("Invalid config value for 
logger.priority in config file: "+config.getString("priority"));
                                // Leave it at the default.
+                       } catch (NodeNeedRestartException e) {
+                               // impossible
+                               System.err.println("impossible 
NodeNeedRestartException for logger.priority in config file: "
+                                       + config.getString("priority"));
                        }
                        FileLoggerHook hook;
                        try {
@@ -346,7 +351,8 @@
                return maxZippedLogsSize;
        }

-       public void setMaxZippedLogFiles(String maxSizeAsString) throws 
InvalidConfigValueException {
+       public void setMaxZippedLogFiles(String maxSizeAsString) throws 
InvalidConfigValueException,
+               NodeNeedRestartException {
                config.set("maxZippedLogsSize", maxSizeAsString);
        }


Modified: trunk/freenet/src/freenet/node/Node.java
===================================================================
--- trunk/freenet/src/freenet/node/Node.java    2008-08-14 13:44:45 UTC (rev 
21839)
+++ trunk/freenet/src/freenet/node/Node.java    2008-08-14 13:45:17 UTC (rev 
21840)
@@ -38,6 +38,7 @@
 import freenet.config.FreenetFilePersistentConfig;
 import freenet.config.InvalidConfigValueException;
 import freenet.config.LongOption;
+import freenet.config.NodeNeedRestartException;
 import freenet.config.PersistentConfig;
 import freenet.config.SubConfig;
 import freenet.crypt.DSAPublicKey;
@@ -1093,7 +1094,9 @@
                                try {
                                        
logConfigHandler.setMaxZippedLogFiles(TESTNET_MIN_MAX_ZIPPED_LOGFILES_STRING);
                                } catch (InvalidConfigValueException e) {
-                                       throw new Error("Impossible: "+e);
+                                       throw new Error("Impossible: " + e, e);
+                               } catch (NodeNeedRestartException e) {
+                                       throw new Error("Impossible: " + e, e);
                                }
                        }
                } else {
@@ -3147,7 +3150,7 @@
                }
        }

-       public void setName(String key) throws InvalidConfigValueException {
+       public void setName(String key) throws InvalidConfigValueException, 
NodeNeedRestartException {
                 config.get("node").getOption("name").setValue(key);
        }



Reply via email to