コード例 #1
0
  public static void main(String[] args) {
    ExtendedProperties pp = parseArguments(args);
    Properties jadeProps = pp.extractSubset("jade.");
    System.out.println("JADE PROPERTIES: " + jadeProps);

    int contentSize = DEFAULT_CONTENT_SIZE;
    try {
      contentSize = Integer.parseInt(pp.getProperty(CONTENT_SIZE));
    } catch (Exception e) {
      // Keep default
    }
    content = new byte[contentSize];

    timeInterval = DEFAULT_TIME_INTERVAL;
    try {
      timeInterval = Long.parseLong(pp.getProperty(TIME_INTERVAL));
    } catch (Exception e) {
      // Keep default
    }

    nIterations = DEFAULT_N_ITERATIONS;
    try {
      nIterations = Integer.parseInt(pp.getProperty(N_ITERATIONS));
    } catch (Exception e) {
      // Keep default
    }

    nCouples = DEFAULT_N_COUPLES;
    try {
      nCouples = Integer.parseInt(pp.getProperty(N_COUPLES));
    } catch (Exception e) {
      // Keep default
    }

    base = DEFAULT_BASE;
    try {
      base = Integer.parseInt(pp.getProperty(BASE));
    } catch (Exception e) {
      // Keep default
    }

    mode = READY_GO_MODE;
    try {
      String modeStr = pp.getProperty(MODE);
      if (SLOW_MODE_S.equals(modeStr)) {
        mode = SLOW_MODE;
      } else if (FAST_MODE_S.equals(modeStr)) {
        mode = FAST_MODE;
      } else if (STEP_BY_STEP_MODE_S.equals(modeStr)) {
        mode = STEP_BY_STEP_MODE;
      }
    } catch (Exception e) {
      // Keep default
    }
    // Prepare the inputReader to get user inputs if necessary
    if (mode == READY_GO_MODE || mode == STEP_BY_STEP_MODE) {
      inputReader = new BufferedReader(new InputStreamReader(System.in));
    }

    randomStart = "true".equals(pp.getProperty(RANDOM_START_S, "false"));

    measure = BITRATE_MEASURE;
    try {
      String measureStr = pp.getProperty(MEASURE);
      if (RTT_MEASURE_S.equals(measureStr)) {
        measure = RTT_MEASURE;
      }
    } catch (Exception e) {
      // Keep default
    }

    String prefix = Profile.getDefaultNetworkName();
    for (int i = base; i < base + nCouples; i++) {
      initCouple(jadeProps, prefix, i);
      switch (mode) {
        case SLOW_MODE:
          waitABit();
          break;
        case STEP_BY_STEP_MODE:
          prompt("Couple #" + i + " started. Press enter to continue");
          break;
        default:
          Thread.currentThread().yield();
      }
    }

    waitUntilReady();
    if (mode == READY_GO_MODE) {
      prompt("All " + nCouples + " couples ready. Press enter to go");
    }
    start();
    if (nIterations > 0) {
      System.out.println("Measurement started....");
    }

    if (timeInterval == STEPBYSTEP_TIME_INTERVAL) {
      int i = 0;
      while (true) {
        waitUntilReady();
        prompt("Iteration # " + i + " terminated by all couples. Press enter to go");
        ++i;
        start();
      }
    }
  }