@Override
 public boolean isEnabled(ToadletContext ctx) {
   Option<?>[] o = subConfig.getOptions();
   if (ctx.isAdvancedModeEnabled()) return true;
   for (Option<?> option : o) if (!option.isExpert()) return true;
   return false;
 }
 private void registerSchedulerConfig(
     SubConfig schedulerConfig,
     String name,
     ClientRequestScheduler csBulk,
     ClientRequestScheduler csRT,
     boolean forSSKs,
     boolean forInserts)
     throws InvalidConfigValueException {
   PrioritySchedulerCallback callback = new PrioritySchedulerCallback();
   schedulerConfig.register(
       name + "_priority_policy",
       ClientRequestScheduler.PRIORITY_SOFT,
       name.hashCode(),
       true,
       false,
       "RequestStarterGroup.scheduler"
           + (forSSKs ? "SSK" : "CHK")
           + (forInserts ? "Inserts" : "Requests"),
       "RequestStarterGroup.schedulerLong",
       callback);
   callback.init(csRT, csBulk, schedulerConfig.getString(name + "_priority_policy"));
 }
 @Override
 public String path() {
   return "/config/" + subConfig.getPrefix();
 }
  public void handleMethodGET(URI uri, HTTPRequest req, ToadletContext ctx)
      throws ToadletContextClosedException, IOException {

    if (!ctx.checkFullAccess(this)) return;

    boolean advancedModeEnabled = ctx.isAdvancedModeEnabled();

    PageNode page =
        ctx.getPageMaker()
            .getPageNode(NodeL10n.getBase().getString("ConfigToadlet.fullTitle"), ctx);
    HTMLNode pageNode = page.outer;
    HTMLNode contentNode = page.content;

    contentNode.addChild(ctx.getAlertManager().createSummary());

    HTMLNode infobox = contentNode.addChild("div", "class", "infobox infobox-normal");
    infobox.addChild("div", "class", "infobox-header", l10n("title"));
    HTMLNode configNode = infobox.addChild("div", "class", "infobox-content");
    HTMLNode formNode = ctx.addFormChild(configNode, path(), "configForm");

    // Invisible apply button at the top so that an enter keypress will
    // apply settings instead of
    // going to a directory browser if present.
    formNode.addChild(
        "input",
        new String[] {"type", "value", "class"},
        new String[] {"submit", l10n("apply"), "invisible"});

    /*
     * Special case: present an option for the wrapper's maximum memory
     * under Core configuration, provided the maximum memory property is
     * defined. (the wrapper is being used)
     */
    if (subConfig.getPrefix().equals("node") && WrapperConfig.canChangeProperties()) {
      String configName = "wrapper.java.maxmemory";
      String curValue = WrapperConfig.getWrapperProperty(configName);
      // If persisted from directory browser, override. This is a POST
      // HTTPRequest.
      if (req.isPartSet(configName)) {
        curValue = req.getPartAsStringFailsafe(configName, MAX_PARAM_VALUE_SIZE);
      }
      if (curValue != null) {
        formNode.addChild("div", "class", "configprefix", l10n("wrapper"));
        HTMLNode list = formNode.addChild("ul", "class", "config");
        HTMLNode item = list.addChild("li", "class", OptionType.TEXT.cssClass);
        // FIXME how to get the real default???
        String defaultValue = "256";
        item.addChild(
                "span",
                new String[] {"class", "title", "style"},
                new String[] {
                  "configshortdesc",
                  NodeL10n.getBase()
                      .getString(
                          "ConfigToadlet.defaultIs",
                          new String[] {"default"},
                          new String[] {defaultValue}),
                  "cursor: help;"
                })
            .addChild(NodeL10n.getBase().getHTMLNode("WrapperConfig." + configName + ".short"));
        item.addChild("span", "class", "config")
            .addChild(
                "input",
                new String[] {"type", "class", "name", "value"},
                new String[] {"text", "config", configName, curValue});
        item.addChild("span", "class", "configlongdesc")
            .addChild(NodeL10n.getBase().getHTMLNode("WrapperConfig." + configName + ".long"));
      }
    }

    short displayedConfigElements = 0;
    HTMLNode configGroupUlNode = new HTMLNode("ul", "class", "config");

    String overriddenOption = null;
    String overriddenValue = null;

    // A value changed by the directory selector takes precedence.
    if (req.isPartSet("select-for") && req.isPartSet(LocalFileBrowserToadlet.selectDir)) {
      overriddenOption = req.getPartAsStringFailsafe("select-for", MAX_PARAM_VALUE_SIZE);
      overriddenValue = req.getPartAsStringFailsafe("filename", MAX_PARAM_VALUE_SIZE);
    }

    /*
     * Present all other options for this subconfig.
     */
    for (Option<?> o : subConfig.getOptions()) {
      if (!((!advancedModeEnabled) && o.isExpert())) {
        displayedConfigElements++;
        String configName = o.getName();
        String fullName = subConfig.getPrefix() + '.' + configName;
        String value = o.getValueDisplayString();

        if (value == null) {
          Logger.error(this, fullName + "has returned null from config!);");
          continue;
        }

        ConfigCallback<?> callback = o.getCallback();

        final OptionType optionType;
        if (callback instanceof EnumerableOptionCallback) {
          optionType = OptionType.DROP_DOWN;
        } else if (callback instanceof BooleanCallback) {
          optionType = OptionType.BOOLEAN;
        } else if (callback instanceof ProgramDirectory.DirectoryCallback
            && !callback.isReadOnly()) {
          optionType = OptionType.DIRECTORY;
        } else if (!callback.isReadOnly()) {
          optionType = OptionType.TEXT;
        } else /* if (callback.isReadOnly()) */ {
          optionType = OptionType.TEXT_READ_ONLY;
        }

        // If ConfigToadlet is serving a plugin, ask the plugin to
        // translate the
        // config descriptions, otherwise use the node's BaseL10n
        // instance like
        // normal.
        HTMLNode shortDesc = o.getShortDescNode(plugin);
        HTMLNode longDesc = o.getLongDescNode(plugin);

        HTMLNode configItemNode = configGroupUlNode.addChild("li");
        String defaultValue;
        if (callback instanceof BooleanCallback) {
          // Only case where values are localised.
          defaultValue = l10n(Boolean.toString(Boolean.valueOf(value)));
        } else {
          defaultValue = o.getDefault();
        }

        configItemNode.addAttribute("class", optionType.cssClass);
        configItemNode
            .addChild("a", new String[] {"name", "id"}, new String[] {configName, configName})
            .addChild(
                "span",
                new String[] {"class", "title", "style"},
                new String[] {
                  "configshortdesc",
                  NodeL10n.getBase()
                          .getString(
                              "ConfigToadlet.defaultIs",
                              new String[] {"default"},
                              new String[] {defaultValue})
                      + (advancedModeEnabled ? " [" + fullName + ']' : ""),
                  "cursor: help;"
                })
            .addChild(shortDesc);
        HTMLNode configItemValueNode = configItemNode.addChild("span", "class", "config");

        // Values persisted through browser or backing down from
        // resetting to defaults
        // override the currently applied ones.
        if (req.isPartSet(fullName)) {
          value = req.getPartAsStringFailsafe(fullName, MAX_PARAM_VALUE_SIZE);
        }
        if (overriddenOption != null && overriddenOption.equals(fullName)) value = overriddenValue;
        switch (optionType) {
          case DROP_DOWN:
            configItemValueNode.addChild(
                addComboBox(
                    value, (EnumerableOptionCallback) callback, fullName, callback.isReadOnly()));
            break;
          case BOOLEAN:
            configItemValueNode.addChild(
                addBooleanComboBox(Boolean.valueOf(value), fullName, callback.isReadOnly()));
            break;
          case DIRECTORY:
            configItemValueNode.addChild(addTextBox(value, fullName, o, false));
            configItemValueNode.addChild(
                "input",
                new String[] {"type", "name", "value"},
                new String[] {
                  "submit",
                  "select-directory." + fullName,
                  NodeL10n.getBase().getString("QueueToadlet.browseToChange")
                });
            break;
          case TEXT_READ_ONLY:
            configItemValueNode.addChild(addTextBox(value, fullName, o, true));
            break;
          case TEXT:
            configItemValueNode.addChild(addTextBox(value, fullName, o, false));
            break;
        }

        configItemNode.addChild("span", "class", "configlongdesc").addChild(longDesc);
      }
    }

    if (displayedConfigElements > 0) {
      formNode.addChild(
          "div",
          "class",
          "configprefix",
          (plugin == null) ? l10n(subConfig.getPrefix()) : plugin.getString(subConfig.getPrefix()));
      formNode.addChild("a", "id", subConfig.getPrefix());
      formNode.addChild(configGroupUlNode);
    }

    formNode.addChild(
        "input", new String[] {"type", "value"}, new String[] {"submit", l10n("apply")});
    formNode.addChild(
        "input", new String[] {"type", "value"}, new String[] {"reset", l10n("undo")});
    formNode.addChild(
        "input",
        new String[] {"type", "name", "value"},
        new String[] {"hidden", "subconfig", subConfig.getPrefix()});
    // 'Node' prefix options should not be reset to defaults as it is a,
    // quoting Toad, "very bad idea".
    // Options whose defaults are not wise to apply include the location of
    // the master keys file,
    // the Darknet port number, and the datastore size.
    if (!subConfig.getPrefix().equals("node")) {
      formNode.addChild(
          "input",
          new String[] {"type", "name", "value"},
          new String[] {"submit", "confirm-reset-to-defaults", l10n("resetToDefaults")});
    }

    this.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();
  }
Beispiel #6
0
 @Override
 public int compareTo(SubConfig second) {
   if (this.getPrefix().compareTo(second.getPrefix()) > 0) return 1;
   else return -1;
 }