Exemple #1
0
  /**
   * Update positionReport based on the new player performance
   *
   * @param pp
   */
  private void updatePositionDetails(PlayerPerformance pp) {
    PositionReport report = (PositionReport) positionReports.get("" + pp.getPositionCode());

    if (report == null) {
      report = new PositionReport(pp);
      positionReports.put("" + pp.getPositionCode(), report);
    }

    report.addPerformance(pp);
  }
  /** Execute these events by this run. */
  public void run() {

    double segWithAccAhead;
    double start = System.currentTimeMillis() - startOfSimulation;

    for (PositionReport event : events) {

      if (event == null) System.out.println("NULL EVENT!!!");
      if (run == null) System.out.println("NULL RUN!!!" + event.toString());

      // READ: If a new vehicle on a travel lane arrives, lookup accidents ahead
      if (run.vehicles.get(event.id) == null && event.lane < 4) {

        if (event.min > run.time.minOfLastUpdateOfAccidentAhead) {

          segWithAccAhead = run.getSegWithAccidentAhead(runs, event);
          if (segWithAccAhead != -1) run.accidentsAhead.put(event.min, segWithAccAhead);
          run.time.minOfLastUpdateOfAccidentAhead = event.min;
        } else {
          segWithAccAhead =
              (run.accidentsAhead.containsKey(event.min)) ? run.accidentsAhead.get(event.min) : -1;
        }
      } else {
        segWithAccAhead = -1;
      }
      // System.out.println("Execute event " + event.toString() + " " + query_number + " times.");

      // Query replication
      for (int i = 1; i < query_number; i++) {
        run.fake_trafficManagement(
            event,
            segWithAccAhead,
            startOfSimulation,
            distrFinishTimes,
            schedStartTimes,
            accidentWarningsFailed,
            tollNotificationsFailed);
        run.fake_collectGarbage(event.min);
      }
      // Avoid multiple storage of complex events due to replicated queries
      // System.out.println("Size: " + (run.fake_output.tollNotifications.size() +
      // run.fake_output.accidentWarnings.size()));
      run.fake_output.tollNotifications.clear();
      run.fake_output.accidentWarnings.clear();

      // WRITE: Update this run and remove old data
      run.trafficManagement(
          event,
          segWithAccAhead,
          startOfSimulation,
          distrFinishTimes,
          schedStartTimes,
          accidentWarningsFailed,
          tollNotificationsFailed);
      run.collectGarbage(event.min);
    }

    double end = System.currentTimeMillis() - startOfSimulation;
    Double duration =
        end - start; // + (events.size()*query_number); // simulate replicated query execution

    total_exe_time.addAndGet(duration.intValue());

    // System.out.println("Run id: " + run.runID + " Duration: " + duration + " Total execution
    // time: " + total_exe_time.toString());

    // Count down the number of transactions
    transaction_number.countDown();
  }