コード例 #1
0
 private static void notifyTerminated(long time, long time2) {
   synchronized (terminatedLock) {
     totalTime += time;
     totalTime2 += time2;
     terminatedCnt++;
     if (terminatedCnt == nCouples) {
       // All couples have terminated. Compute the average round-trip time
       long n = nCouples * ((long) nIterations);
       if (measure == BITRATE_MEASURE) {
         double totBytes = n * ((double) content.length);
         double averageBitrate = totBytes / totalTime;
         System.out.println(
             "----------------------------------\nTest completed successufully.\nAverage bitrate (Kbyte/s) = "
                 + averageBitrate
                 + "\n----------------------------------");
       } else if (measure == RTT_MEASURE) {
         long averageRoundTripTime = totalTime / n;
         double avg = (double) averageRoundTripTime;
         double x = totalTime2 + n * avg * avg - 2 * avg * totalTime;
         double standardDeviation = Math.sqrt(x / n);
         System.out.println(
             "----------------------------------\nTest completed successufully.\nAverage round trip time = "
                 + averageRoundTripTime
                 + " ms\nStandard deviation = "
                 + standardDeviation
                 + "\n----------------------------------");
       }
       System.exit(0);
     }
   }
 }
コード例 #2
0
    private void job() {
      long start = System.currentTimeMillis();
      send(msg);
      blockingReceive(myTemplate);
      long time = System.currentTimeMillis() - start;

      if (!terminated) {
        System.out.println("Agent " + getLocalName() + " " + cnt + " OK");
        totalCoupleTime += time;
        totalCoupleTime2 += (time * time);
        if (nIterations > 0 && (++cnt) >= nIterations) {
          notifyTerminated(totalCoupleTime, totalCoupleTime2);
          terminated = true;
        }
      }
      if (timeInterval == STEPBYSTEP_TIME_INTERVAL) {
        notifyReady();
      }
    }
コード例 #3
0
 private void job() {
   if (firstRound) {
     long time = System.currentTimeMillis();
     // Insert the start-time ion the protocol field
     msg.setProtocol(String.valueOf(time));
     firstRound = false;
   }
   send(msg);
   if (timeInterval == STEPBYSTEP_TIME_INTERVAL) {
     notifyReady();
   }
 }
コード例 #4
0
  public void action() {
    this.prepateTemplate();

    if (template == null) msg = myAgent.receive();
    else msg = myAgent.receive(template);

    if (msg != null) {
      finished = true;
      handle(msg);
      return;
    }
    long dt = wakeupTime - System.currentTimeMillis();

    if (dt > 0) block(dt);
    else {
      finished = true;
      if (msg != null) handle(msg);
    }
  }
コード例 #5
0
 @Override
 public void onStart() {
   wakeupTime = (timeOut < 0 ? Long.MAX_VALUE : System.currentTimeMillis() + timeOut);
 }