/** @deprecated Use {@link Config#createSubConfig(String)} instead */ @Deprecated public SubConfig(String prefix, Config config) { this.config = config; this.prefix = prefix; map = new LinkedHashMap<String, Option<?>>(); hasInitialized = false; config.register(this); }
public void register(Option<?> o) { synchronized (this) { if (o.name.indexOf(SimpleFieldSet.MULTI_LEVEL_CHAR) != -1) throw new IllegalArgumentException( "Option names must not contain " + SimpleFieldSet.MULTI_LEVEL_CHAR); if (map.containsKey(o.name)) throw new IllegalArgumentException("Already registered: " + o.name + " on " + this); map.put(o.name, o); } config.onRegister(this, o); }
public void handleMethodPOST(URI uri, HTTPRequest request, ToadletContext ctx) throws ToadletContextClosedException, IOException, RedirectException { if (!ctx.checkFullAccess(this)) return; // User requested reset to defaults, so present confirmation page. if (request.isPartSet("confirm-reset-to-defaults")) { PageNode page = ctx.getPageMaker().getPageNode(l10n("confirmResetTitle"), ctx); HTMLNode pageNode = page.outer; HTMLNode contentNode = page.content; HTMLNode content = ctx.getPageMaker() .getInfobox( "infobox-warning", l10n("confirmResetTitle"), contentNode, "reset-confirm", true); content.addChild("#", l10n("confirmReset")); HTMLNode formNode = ctx.addFormChild(content, path(), "yes-button"); String subconfig = request.getPartAsStringFailsafe("subconfig", MAX_PARAM_VALUE_SIZE); formNode.addChild( "input", new String[] {"type", "name", "value"}, new String[] {"hidden", "subconfig", subconfig}); // Persist visible fields so that they are reset to default or // unsaved changes are persisted. for (String part : request.getParts()) { if (part.startsWith(subconfig)) { formNode.addChild( "input", new String[] {"type", "name", "value"}, new String[] { "hidden", part, request.getPartAsStringFailsafe(part, MAX_PARAM_VALUE_SIZE) }); } } formNode.addChild( "input", new String[] {"type", "name", "value"}, new String[] { "submit", "reset-to-defaults", NodeL10n.getBase().getString("Toadlet.yes") }); formNode.addChild( "input", new String[] {"type", "name", "value"}, new String[] { "submit", "decline-default-reset", NodeL10n.getBase().getString("Toadlet.no") }); writeHTMLReply(ctx, 200, "OK", pageNode.generate()); return; } // Returning from directory selector with a selection or declining // resetting settings to defaults. // Re-render config page with any changes made in the selector and/or // persisting values changed but // not applied. if (request.isPartSet(LocalFileBrowserToadlet.selectDir) || request.isPartSet("decline-default-reset")) { handleMethodGET(uri, request, ctx); return; } // Entering directory selector from config page. // This would be two loops if it checked for a redirect // (key.startsWith("select-directory.")) before // constructing params string. It always constructs it, then redirects // if it turns out to be needed. boolean directorySelector = false; StringBuilder paramsBuilder = new StringBuilder(); paramsBuilder.append('?'); String value; for (String key : request.getParts()) { // Prepare parts for page selection redirect: // Extract option and put into "select-for"; preserve others. value = request.getPartAsStringFailsafe(key, MAX_PARAM_VALUE_SIZE); if (key.startsWith("select-directory.")) { paramsBuilder .append("select-for=") .append(URLEncoder.encode(key.substring("select-directory.".length()), true)) .append('&'); directorySelector = true; } else { paramsBuilder .append(URLEncoder.encode(key, true)) .append('=') .append(URLEncoder.encode(value, true)) .append('&'); } } String params = paramsBuilder.toString(); if (directorySelector) { MultiValueTable<String, String> headers = new MultiValueTable<String, String>(1); // params ends in &. Download directory browser starts in default // download directory. headers.put( "Location", directoryBrowserPath + params + "path=" + core.getDownloadsDir().getAbsolutePath()); ctx.sendReplyHeaders(302, "Found", headers, null, 0); return; } StringBuilder errbuf = new StringBuilder(); boolean logMINOR = Logger.shouldLog(LogLevel.MINOR, this); String prefix = request.getPartAsStringFailsafe("subconfig", MAX_PARAM_VALUE_SIZE); if (logMINOR) { Logger.minor(this, "Current config prefix is " + prefix); } boolean resetToDefault = request.isPartSet("reset-to-defaults"); if (resetToDefault && logMINOR) { Logger.minor(this, "Resetting to defaults"); } for (Option<?> o : config.get(prefix).getOptions()) { String configName = o.getName(); if (logMINOR) { Logger.minor(this, "Checking option " + prefix + '.' + configName); } // This ignores unrecognized parameters. if (request.isPartSet(prefix + '.' + configName)) { // Current subconfig is to be reset to default. if (resetToDefault) { // Disallow resetting fproxy port number to default as it // might break the link to start fproxy on the system tray, // shortcuts etc. if (prefix.equals("fproxy") && configName.equals("port")) continue; value = o.getDefault(); } else { value = request.getPartAsStringFailsafe(prefix + '.' + configName, MAX_PARAM_VALUE_SIZE); } if (!(o.getValueDisplayString().equals(value))) { if (logMINOR) { Logger.minor(this, "Changing " + prefix + '.' + configName + " to " + value); } try { o.setValue(value); } catch (InvalidConfigValueException e) { errbuf.append(o.getName()).append(' ').append(e.getMessage()).append('\n'); } catch (NodeNeedRestartException e) { needRestart = true; } catch (Exception e) { errbuf.append(o.getName()).append(' ').append(e).append('\n'); Logger.error(this, "Caught " + e, e); } } else if (logMINOR) { Logger.minor(this, prefix + '.' + configName + " not changed"); } } } // Wrapper params String wrapperConfigName = "wrapper.java.maxmemory"; if (request.isPartSet(wrapperConfigName)) { value = request.getPartAsStringFailsafe(wrapperConfigName, MAX_PARAM_VALUE_SIZE); if (!WrapperConfig.getWrapperProperty(wrapperConfigName).equals(value)) { if (logMINOR) { Logger.minor(this, "Setting " + wrapperConfigName + " to " + value); } WrapperConfig.setWrapperProperty(wrapperConfigName, value); } } config.store(); PageNode page = ctx.getPageMaker().getPageNode(l10n("appliedTitle"), ctx); HTMLNode pageNode = page.outer; HTMLNode contentNode = page.content; if (errbuf.length() == 0) { HTMLNode content = ctx.getPageMaker() .getInfobox( "infobox-success", l10n("appliedTitle"), contentNode, "configuration-applied", true); content.addChild("#", l10n("appliedSuccess")); if (needRestart) { content.addChild("br"); content.addChild("#", l10n("needRestart")); if (node.isUsingWrapper()) { content.addChild("br"); HTMLNode restartForm = ctx.addFormChild(content, "/", "restartForm"); 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") }); } if (needRestartUserAlert == null) { needRestartUserAlert = new NeedRestartUserAlert(ctx.getFormPassword()); ctx.getAlertManager().register(needRestartUserAlert); } } } else { HTMLNode content = ctx.getPageMaker() .getInfobox( "infobox-error", l10n("appliedFailureTitle"), contentNode, "configuration-error", true) .addChild("div", "class", "infobox-content"); content.addChild("#", l10n("appliedFailureExceptions")); content.addChild("br"); content.addChild("#", errbuf.toString()); } HTMLNode content = ctx.getPageMaker() .getInfobox( "infobox-normal", l10n("possibilitiesTitle"), contentNode, "configuration-possibilities", false); content.addChild( "a", new String[] {"href", "title"}, new String[] {path(), l10n("shortTitle")}, l10n("returnToNodeConfig")); content.addChild("br"); addHomepageLink(content); writeHTMLReply(ctx, 200, "OK", pageNode.generate()); }
RequestStarterGroup( Node node, NodeClientCore core, int portNumber, RandomSource random, Config config, SimpleFieldSet fs, ClientContext ctx, long dbHandle) throws InvalidConfigValueException { SubConfig schedulerConfig = config.createSubConfig("node.scheduler"); this.stats = core.nodeStats; throttleWindowBulk = new ThrottleWindowManager(2.0, fs == null ? null : fs.subset("ThrottleWindow"), node); throttleWindowRT = new ThrottleWindowManager(2.0, fs == null ? null : fs.subset("ThrottleWindowRT"), node); throttleWindowCHK = new ThrottleWindowManager(2.0, fs == null ? null : fs.subset("ThrottleWindowCHK"), node); throttleWindowSSK = new ThrottleWindowManager(2.0, fs == null ? null : fs.subset("ThrottleWindowSSK"), node); throttleWindowInsert = new ThrottleWindowManager(2.0, fs == null ? null : fs.subset("ThrottleWindowInsert"), node); throttleWindowRequest = new ThrottleWindowManager( 2.0, fs == null ? null : fs.subset("ThrottleWindowRequest"), node); chkRequestThrottleBulk = new MyRequestThrottle( 5000, "CHK Request", fs == null ? null : fs.subset("CHKRequestThrottle"), 32768, false); chkRequestThrottleRT = new MyRequestThrottle( 5000, "CHK Request (RT)", fs == null ? null : fs.subset("CHKRequestThrottleRT"), 32768, true); chkRequestStarterBulk = new RequestStarter( core, chkRequestThrottleBulk, "CHK Request starter (" + portNumber + ')', stats.requestOutputThrottle, stats.requestInputThrottle, stats.localChkFetchBytesSentAverage, stats.localChkFetchBytesReceivedAverage, false, false, false); chkRequestStarterRT = new RequestStarter( core, chkRequestThrottleRT, "CHK Request starter (" + portNumber + ')', stats.requestOutputThrottle, stats.requestInputThrottle, stats.localChkFetchBytesSentAverage, stats.localChkFetchBytesReceivedAverage, false, false, true); chkFetchSchedulerBulk = new ClientRequestScheduler( false, false, false, random, chkRequestStarterBulk, node, core, "CHKrequester", ctx); chkFetchSchedulerRT = new ClientRequestScheduler( false, false, true, random, chkRequestStarterRT, node, core, "CHKrequester", ctx); chkRequestStarterBulk.setScheduler(chkFetchSchedulerBulk); chkRequestStarterRT.setScheduler(chkFetchSchedulerRT); registerSchedulerConfig( schedulerConfig, "CHKrequester", chkFetchSchedulerBulk, chkFetchSchedulerRT, false, false); // insertThrottle = new ChainedRequestThrottle(10000, 2.0F, requestThrottle); // FIXME reenable the above chkInsertThrottleBulk = new MyRequestThrottle( 20000, "CHK Insert", fs == null ? null : fs.subset("CHKInsertThrottle"), 32768, false); chkInsertThrottleRT = new MyRequestThrottle( 20000, "CHK Insert (RT)", fs == null ? null : fs.subset("CHKInsertThrottleRT"), 32768, true); chkInsertStarterBulk = new RequestStarter( core, chkInsertThrottleBulk, "CHK Insert starter (" + portNumber + ')', stats.requestOutputThrottle, stats.requestInputThrottle, stats.localChkInsertBytesSentAverage, stats.localChkInsertBytesReceivedAverage, true, false, false); chkInsertStarterRT = new RequestStarter( core, chkInsertThrottleRT, "CHK Insert starter (" + portNumber + ')', stats.requestOutputThrottle, stats.requestInputThrottle, stats.localChkInsertBytesSentAverage, stats.localChkInsertBytesReceivedAverage, true, false, true); chkPutSchedulerBulk = new ClientRequestScheduler( true, false, false, random, chkInsertStarterBulk, node, core, "CHKinserter", ctx); chkPutSchedulerRT = new ClientRequestScheduler( true, false, true, random, chkInsertStarterRT, node, core, "CHKinserter", ctx); chkInsertStarterBulk.setScheduler(chkPutSchedulerBulk); chkInsertStarterRT.setScheduler(chkPutSchedulerRT); registerSchedulerConfig( schedulerConfig, "CHKinserter", chkPutSchedulerBulk, chkPutSchedulerRT, false, true); sskRequestThrottleBulk = new MyRequestThrottle( 5000, "SSK Request", fs == null ? null : fs.subset("SSKRequestThrottle"), 1024, false); sskRequestThrottleRT = new MyRequestThrottle( 5000, "SSK Request (RT)", fs == null ? null : fs.subset("SSKRequestThrottleRT"), 1024, true); sskRequestStarterBulk = new RequestStarter( core, sskRequestThrottleBulk, "SSK Request starter (" + portNumber + ')', stats.requestOutputThrottle, stats.requestInputThrottle, stats.localSskFetchBytesSentAverage, stats.localSskFetchBytesReceivedAverage, false, true, false); sskRequestStarterRT = new RequestStarter( core, sskRequestThrottleRT, "SSK Request starter (" + portNumber + ')', stats.requestOutputThrottle, stats.requestInputThrottle, stats.localSskFetchBytesSentAverage, stats.localSskFetchBytesReceivedAverage, false, true, true); sskFetchSchedulerBulk = new ClientRequestScheduler( false, true, false, random, sskRequestStarterBulk, node, core, "SSKrequester", ctx); sskFetchSchedulerRT = new ClientRequestScheduler( false, true, true, random, sskRequestStarterRT, node, core, "SSKrequester", ctx); sskRequestStarterBulk.setScheduler(sskFetchSchedulerBulk); sskRequestStarterRT.setScheduler(sskFetchSchedulerRT); registerSchedulerConfig( schedulerConfig, "SSKrequester", sskFetchSchedulerBulk, sskFetchSchedulerRT, true, false); // insertThrottle = new ChainedRequestThrottle(10000, 2.0F, requestThrottle); // FIXME reenable the above sskInsertThrottleBulk = new MyRequestThrottle( 20000, "SSK Insert", fs == null ? null : fs.subset("SSKInsertThrottle"), 1024, false); sskInsertThrottleRT = new MyRequestThrottle( 20000, "SSK Insert", fs == null ? null : fs.subset("SSKInsertThrottleRT"), 1024, true); sskInsertStarterBulk = new RequestStarter( core, sskInsertThrottleBulk, "SSK Insert starter (" + portNumber + ')', stats.requestOutputThrottle, stats.requestInputThrottle, stats.localSskInsertBytesSentAverage, stats.localSskFetchBytesReceivedAverage, true, true, false); sskInsertStarterRT = new RequestStarter( core, sskInsertThrottleRT, "SSK Insert starter (" + portNumber + ')', stats.requestOutputThrottle, stats.requestInputThrottle, stats.localSskInsertBytesSentAverage, stats.localSskFetchBytesReceivedAverage, true, true, true); sskPutSchedulerBulk = new ClientRequestScheduler( true, true, false, random, sskInsertStarterBulk, node, core, "SSKinserter", ctx); sskPutSchedulerRT = new ClientRequestScheduler( true, true, true, random, sskInsertStarterRT, node, core, "SSKinserter", ctx); sskInsertStarterBulk.setScheduler(sskPutSchedulerBulk); sskInsertStarterRT.setScheduler(sskPutSchedulerRT); registerSchedulerConfig( schedulerConfig, "SSKinserter", sskPutSchedulerBulk, sskPutSchedulerRT, true, true); schedulerConfig.finishedInitialization(); }