Пример #1
0
  /**
   * Loads configuration. It verifies the constraints defined in {@link WireByMethod}.
   *
   * @param prefix the configuration prefix for this class
   */
  public WireByMethod(String prefix) {
    super(prefix);

    // get the method
    try {
      final Class wire =
          Configuration.getClass(
              prefix + "." + PAR_CLASS, Class.forName("peersim.graph.GraphFactory"));
      method =
          WireByMethod.getMethod(wire, Configuration.getString(prefix + "." + PAR_METHOD, "wire"));
    } catch (Exception e) {
      throw new RuntimeException(e);
    }

    // set the constant args (those other than 0th)
    Class[] argt = method.getParameterTypes();
    args = new Object[argt.length];
    for (int i = 1; i < args.length; ++i) {

      if (argt[i] == int.class) args[i] = Configuration.getInt(prefix + "." + PAR_ARG + i);
      else if (argt[i] == long.class) args[i] = Configuration.getLong(prefix + "." + PAR_ARG + i);
      else if (argt[i] == double.class)
        args[i] = Configuration.getDouble(prefix + "." + PAR_ARG + i);
      else if (i == args.length - 1 && argt[i].isInstance(CommonState.r)) args[i] = CommonState.r;
      else {
        // we should neve get here
        throw new RuntimeException(
            "Unexpected error, please " + "report this problem to the peersim team");
      }
    }
  }
Пример #2
0
  /** Initialization based on configuration parameters. */
  public OrangeSched(String n) {

    String[] prots = Configuration.getString(n + "." + PAR_PROTOCOL).split("\\s");
    pid = new int[prots.length];
    nce = new NextCycleEvent[prots.length];
    for (int i = 0; i < prots.length; ++i) {
      pid[i] = Configuration.lookupPid(prots[i]);
      if (!(Network.prototype.getProtocol(pid[i]) instanceof CDProtocol)) {
        throw new IllegalParameterException(
            n + "." + PAR_PROTOCOL, "Only CDProtocols are accepted here");
      }

      nce[i] =
          (NextCycleEvent) Configuration.getInstance(n + "." + PAR_NEXTC, new NextCycleEvent(null));
    }

    randstart = Configuration.contains(n + "." + PAR_RNDSTART);
  }