Exemple #1
0
  private List<String> select(RadiusModuleType type) throws InterruptedException {
    // get instance names
    List<String> names = new ArrayList<String>();
    RadiusModule module = server.getModule(type);
    for (RadiusInstance instance : module.getInstances()) {
      names.add(instance.getName());
    }

    // print instance list
    List<String> selected = new ArrayList<String>();

    int i = 1;
    for (String name : names) {
      context.println("[" + (i++) + "] " + name);
    }
    context.println("---------------------------");

    while (true) {
      try {
        context.print("select index (0 for end): ");
        int index = Integer.valueOf(context.readLine());
        if (index == 0) break;

        if (index < 0 || index > names.size()) {
          context.println("no item corresponds to selected index");
          continue;
        }

        // add to select bucket
        String name = names.get(index - 1);
        if (!selected.contains(name)) {
          selected.add(name);
          context.println(name + " added");
        }

      } catch (NumberFormatException e) {
        context.println("");
        throw new RuntimeException("invalid number format");
      }
    }

    return selected;
  }
Exemple #2
0
  @ScriptUsage(
      description = "list all module instances",
      arguments = {
        @ScriptArgument(name = "module type", type = "string", description = "module type ")
      })
  public void instances(String[] args) {
    context.println("Instances");
    context.println("------------");

    RadiusModuleType type = RadiusModuleType.parse(args[0]);
    if (type == null) {
      context.println("unknown module type");
      return;
    }

    RadiusModule module = server.getModule(type);

    for (RadiusInstance instance : module.getInstances()) {
      context.println("[" + instance.getName() + "] " + instance);
    }
  }