Example #1
0
 /**
  * Initializes this mix according to the annotation.
  *
  * @param driverClass The driver class annotating this mix
  * @param a The annotation
  * @throws com.sun.faban.driver.DefinitionException If there is an error in the annotation
  */
 public void init(Class<?> driverClass, Annotation a) throws DefinitionException {
   com.sun.faban.driver.MatrixMix matrixMix = (com.sun.faban.driver.MatrixMix) a;
   operations = BenchmarkDefinition.getOperations(driverClass, matrixMix.operations());
   Row[] lines = matrixMix.mix();
   mix = new double[lines.length][];
   for (int i = 0; i < lines.length; i++) {
     mix[i] = lines[i].value();
   }
   deviation = matrixMix.deviation();
   validate();
 }
Example #2
0
  /**
   * The method postDeserialize re-establishes the non-serializable fields.
   *
   * @throws ClassNotFoundException
   */
  public void postDeserialize() throws ClassNotFoundException {
    if (instance == null) {
      instance = this;
    }

    if (driverConfig.driverClass == null) {
      try {
        // first try the default class loader
        ClassLoader cl = this.getClass().getClassLoader();
        driverConfig.driverClass = cl.loadClass(driverConfig.className);

      } catch (ClassNotFoundException cnfe) {
        // do nothing, check defBytes
      }
    }
    // If we couldn't load the class, driverClass is still null
    // Try again, this time check defBytes
    if (driverConfig.driverClass == null) {

      String tempDir = System.getProperty("faban.tmpdir");

      if (tempDir == null) {
        tempDir = System.getProperty("java.io.tmpdir");
      }

      File classFileDir = new File(tempDir);

      String classFileName =
          new StringBuilder(tempDir).append(driverConfig.className).append(".class").toString();

      FileOutputStream fos = null;

      try {

        File classFile = new File(classFileName);
        fos = new FileOutputStream(classFile);
        fos.write(this.defBytes);
        fos.flush();
        fos.close();

        URL url[] = new URL[1];

        url[0] = classFileDir.toURI().toURL();

        URLClassLoader loader = new URLClassLoader(url, this.getClass().getClassLoader());

        driverConfig.driverClass = loader.loadClass(driverConfig.className);

      } catch (MalformedURLException ex) {
        throw new ClassNotFoundException(ex.getMessage());
      } catch (IOException ioex) {
        throw new ClassNotFoundException(ioex.getMessage());
      } finally {
        try {
          fos.close();
        } catch (Exception ex) {
          // if fos cannot be closed, leave it alone.
        }
      }
    }
    BenchmarkDefinition.refillMethod(driverConfig.driverClass, driverConfig.preRun);
    BenchmarkDefinition.refillMethod(driverConfig.driverClass, driverConfig.postRun);

    BenchmarkDefinition.refillOperations(driverConfig.driverClass, driverConfig.mix[0].operations);
    if (driverConfig.mix[1] != null) {
      BenchmarkDefinition.refillOperations(
          driverConfig.driverClass, driverConfig.mix[1].operations);
    }
  }