Example #1
0
  /*
   * Read local file contents and populate the results model with the collected
   * information.
   */
  String readLocalFile(File dir, List scenarios) throws FileNotFoundException {
    //	if (!dir.exists()) return null;
    File dataFile = new File(dir, getName() + ".dat"); // $NON-NLS-1$
    if (!dataFile.exists()) throw new FileNotFoundException();
    DataInputStream stream = null;
    try {
      // Read local file info
      stream = new DataInputStream(new BufferedInputStream(new FileInputStream(dataFile)));
      print(" - read local files info"); // $NON-NLS-1$
      String lastBuildName = stream.readUTF(); // first string is the build name

      // Next field is the number of scenarios for the component
      int size = stream.readInt();

      // Then follows all the scenario information
      for (int i = 0; i < size; i++) {
        // ... which starts with the scenario id
        int scenario_id = stream.readInt();
        ScenarioResults scenarioResults =
            scenarios == null ? null : getScenarioResults(scenarios, scenario_id);
        if (scenarioResults == null) {
          // this can happen if scenario pattern does not cover all those stored in local data file
          // hence, creates a fake scenario to read the numbers and skip to the next scenario
          scenarioResults = new ScenarioResults(-1, null, null);
          //				scenarioResults.parent = this;
          //				scenarioResults.readData(stream);
          // Should no longer occur as we get all scenarios from database now
          //				throw new RuntimeException("Unexpected unfound scenario!"); //$NON-NLS-1$
        }
        scenarioResults.parent = this;
        scenarioResults.printStream = this.printStream;
        scenarioResults.readData(stream);
        addChild(scenarioResults, true);
        if (this.printStream != null) this.printStream.print('.');
      }
      println();
      println(
          "	=> "
              + size
              + " scenarios data were read from file "
              + dataFile); //$NON-NLS-1$ //$NON-NLS-2$

      // Return last build name stored in the local files
      return lastBuildName;
    } catch (IOException ioe) {
      println(
          "	!!! "
              + dataFile
              + " should be deleted as it contained invalid data !!!"); //$NON-NLS-1$ //$NON-NLS-2$
    } finally {
      try {
        stream.close();
      } catch (IOException e) {
        // nothing else to do!
      }
    }
    return null;
  }
Example #2
0
  /*
   * Read the database values for a build name and a list of scenarios.
   * The database is read only if the components does not already knows the
   * given build (i.e. if it has not been already read) or if the force arguments is set.
   */
  void updateBuild(
      String buildName,
      List scenarios,
      boolean force,
      File dataDir,
      SubMonitor subMonitor,
      PerformanceResults.RemainingTimeGuess timeGuess) {

    // Read all variations
    println("Component '" + this.name + "':"); // $NON-NLS-1$ //$NON-NLS-2$

    // manage monitor
    int size = scenarios.size();
    subMonitor.setWorkRemaining(size + 1);
    StringBuffer buffer = new StringBuffer("Component "); // $NON-NLS-1$
    buffer.append(this.name);
    buffer.append("..."); // $NON-NLS-1$
    String title = buffer.toString();
    subMonitor.subTask(title + timeGuess.display());
    timeGuess.count++;
    subMonitor.worked(1);
    if (subMonitor.isCanceled()) return;

    // Read new values for the local result
    boolean dirty = false;
    long readTime = System.currentTimeMillis();
    String log = " - read scenarios from DB:"; // $NON-NLS-1$
    if (size > 0) {
      for (int i = 0; i < size; i++) {

        // manage monitor
        subMonitor.subTask(title + timeGuess.display());
        timeGuess.count++;
        if (log != null) {
          println(log);
          log = null;
        }

        // read results
        ScenarioResults nextScenarioResults = (ScenarioResults) scenarios.get(i);
        ScenarioResults scenarioResults = (ScenarioResults) getResults(nextScenarioResults.id);
        if (scenarioResults == null) {
          // Scenario is not known yet, force an update
          scenarioResults = nextScenarioResults;
          scenarioResults.parent = this;
          scenarioResults.printStream = this.printStream;
          scenarioResults.updateBuild(buildName, true);
          dirty = true;
          addChild(scenarioResults, true);
        } else {
          if (scenarioResults.updateBuild(buildName, force)) {
            dirty = true;
          }
        }
        if (dataDir != null
            && dirty
            && (System.currentTimeMillis() - readTime) > 300000) { // save every 5mn
          writeData(buildName, dataDir, true, true);
          dirty = false;
          readTime = System.currentTimeMillis();
        }

        // manage monitor
        subMonitor.worked(1);
        if (subMonitor.isCanceled()) return;
      }
    }

    // Write local files
    if (dataDir != null) {
      writeData(buildName, dataDir, false, dirty);
    }

    // Print global time
    printGlobalTime(readTime);
  }