lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dor...@apache.org
Subject svn commit: r1083731 - in /lucene/dev/trunk: ./ lucene/ modules/benchmark/ modules/benchmark/src/java/org/apache/lucene/benchmark/byTask/ modules/benchmark/src/java/org/apache/lucene/benchmark/byTask/utils/ modules/benchmark/src/test/org/apache/lucene/...
Date Mon, 21 Mar 2011 11:23:38 GMT
Author: doronc
Date: Mon Mar 21 11:23:37 2011
New Revision: 1083731

URL: http://svn.apache.org/viewvc?rev=1083731&view=rev
Log:
LUCENE-2964: Allow benchmark tasks from alternative packages - merge/port from 3x.

Added:
    lucene/dev/trunk/modules/benchmark/src/test/org/apache/lucene/benchmark/byTask/tasks/alt/
      - copied from r1083726, lucene/dev/branches/branch_3x/lucene/contrib/benchmark/src/test/org/apache/lucene/benchmark/byTask/tasks/alt/
    lucene/dev/trunk/modules/benchmark/src/test/org/apache/lucene/benchmark/byTask/tasks/alt/AltPackageTaskTest.java
      - copied unchanged from r1083726, lucene/dev/branches/branch_3x/lucene/contrib/benchmark/src/test/org/apache/lucene/benchmark/byTask/tasks/alt/AltPackageTaskTest.java
    lucene/dev/trunk/modules/benchmark/src/test/org/apache/lucene/benchmark/byTask/tasks/alt/AltTestTask.java
      - copied unchanged from r1083726, lucene/dev/branches/branch_3x/lucene/contrib/benchmark/src/test/org/apache/lucene/benchmark/byTask/tasks/alt/AltTestTask.java
Modified:
    lucene/dev/trunk/   (props changed)
    lucene/dev/trunk/lucene/   (props changed)
    lucene/dev/trunk/modules/benchmark/CHANGES.txt
    lucene/dev/trunk/modules/benchmark/src/java/org/apache/lucene/benchmark/byTask/package.html
    lucene/dev/trunk/modules/benchmark/src/java/org/apache/lucene/benchmark/byTask/utils/Algorithm.java

Modified: lucene/dev/trunk/modules/benchmark/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/modules/benchmark/CHANGES.txt?rev=1083731&r1=1083730&r2=1083731&view=diff
==============================================================================
--- lucene/dev/trunk/modules/benchmark/CHANGES.txt (original)
+++ lucene/dev/trunk/modules/benchmark/CHANGES.txt Mon Mar 21 11:23:37 2011
@@ -2,6 +2,11 @@ Lucene Benchmark Contrib Change Log
 
 The Benchmark contrib package contains code for benchmarking Lucene in a variety of ways.
 
+03/21/2011
+  LUCENE-2964: Allow benchmark tasks from alternative packages,
+  specified through a new property "alt.tasks.packages".
+  (Doron Cohen, Shai Erera)
+  
 03/20/2011
   LUCENE-2963: Easier way to run benchmark, by calling Benmchmark.exec(alg-file).
   (Doron Cohen)

Modified: lucene/dev/trunk/modules/benchmark/src/java/org/apache/lucene/benchmark/byTask/package.html
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/modules/benchmark/src/java/org/apache/lucene/benchmark/byTask/package.html?rev=1083731&r1=1083730&r2=1083731&view=diff
==============================================================================
--- lucene/dev/trunk/modules/benchmark/src/java/org/apache/lucene/benchmark/byTask/package.html
(original)
+++ lucene/dev/trunk/modules/benchmark/src/java/org/apache/lucene/benchmark/byTask/package.html
Mon Mar 21 11:23:37 2011
@@ -170,6 +170,9 @@ with the benchmark.ext.classpath propert
       <font color="#FF0000">-Dbenchmark.ext.classpath=/mydir/classes
       </font> -Dtask.mem=512M</li>
 </ul>
+<u>External tasks</u>: When writing your own tasks under a package other than

+<b>org.apache.lucene.benchmark.byTask.tasks</b> specify that package thru the
+<font color="#FF0000">alt.tasks.packages</font> property.
 </p>
 
 <a name="algorithm"></a>
@@ -590,6 +593,14 @@ Here is a list of currently defined prop
     <ul><li>doc.delete.step
     </li></ul>
   </li>
+  
+  <li><b>Task alternative packages</b>:
+    <ul><li>alt.tasks.packages
+      - comma separated list of additional packages where tasks classes will be looked for
+      when not found in the default package (that of PerfTask).  If the same task class 
+      appears in more than one package, the package indicated first in this list will be
used.
+    </li></ul> 
+  </li>
 
 </ol>
 

Modified: lucene/dev/trunk/modules/benchmark/src/java/org/apache/lucene/benchmark/byTask/utils/Algorithm.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/modules/benchmark/src/java/org/apache/lucene/benchmark/byTask/utils/Algorithm.java?rev=1083731&r1=1083730&r2=1083731&view=diff
==============================================================================
--- lucene/dev/trunk/modules/benchmark/src/java/org/apache/lucene/benchmark/byTask/utils/Algorithm.java
(original)
+++ lucene/dev/trunk/modules/benchmark/src/java/org/apache/lucene/benchmark/byTask/utils/Algorithm.java
Mon Mar 21 11:23:37 2011
@@ -21,6 +21,7 @@ import java.io.StreamTokenizer;
 import java.io.StringReader;
 import java.lang.reflect.Constructor;
 import java.util.ArrayList;
+import java.util.Arrays;
 
 import org.apache.lucene.benchmark.byTask.PerfRunData;
 import org.apache.lucene.benchmark.byTask.tasks.PerfTask;
@@ -33,15 +34,23 @@ import org.apache.lucene.benchmark.byTas
 public class Algorithm {
   
   private TaskSequence sequence;
+  private final String[] taskPackages;
   
   /**
    * Read algorithm from file
+   * Property examined: alt.tasks.packages == comma separated list of 
+   * alternate package names where tasks would be searched for, when not found 
+   * in the default package (that of {@link PerfTask}{@link #getClass()}).
+   * If the same task class appears in more than one package, the package 
+   * indicated first in this list will be used.
    * @param runData perf-run-data used at running the tasks.
    * @throws Exception if errors while parsing the algorithm 
    */
   @SuppressWarnings("fallthrough")
   public Algorithm (PerfRunData runData) throws Exception {
-    String algTxt = runData.getConfig().getAlgorithmText();
+    Config config = runData.getConfig();
+    taskPackages = initTasksPackages(config);
+    String algTxt = config.getAlgorithmText();
     sequence = new TaskSequence(runData,null,null,false);
     TaskSequence currSequence = sequence;
     PerfTask prevTask = null;
@@ -55,14 +64,13 @@ public class Algorithm {
     boolean colonOk = false; 
     boolean isDisableCountNextTask = false; // only for primitive tasks
     currSequence.setDepth(0);
-    String taskPackage = PerfTask.class.getPackage().getName() + ".";
     
     while (stok.nextToken() != StreamTokenizer.TT_EOF) { 
       switch(stok.ttype) {
   
         case StreamTokenizer.TT_WORD:
           String s = stok.sval;
-          Constructor<? extends PerfTask> cnstr = Class.forName(taskPackage+s+"Task")
+          Constructor<? extends PerfTask> cnstr = taskClass(config,s)
             .asSubclass(PerfTask.class).getConstructor(PerfRunData.class);
           PerfTask task = cnstr.newInstance(runData);
           task.setDisableCounting(isDisableCountNextTask);
@@ -248,9 +256,33 @@ public class Algorithm {
     }
   }
 
-  /* (non-Javadoc)
-   * @see java.lang.Object#toString()
-   */
+  private String[] initTasksPackages(Config config) {
+    String alts = config.get("alt.tasks.packages", null);
+    String dfltPkg = PerfTask.class.getPackage().getName();
+    if (alts==null) {
+      return new String[]{ dfltPkg };
+    }
+    ArrayList<String> pkgs = new ArrayList<String>();
+    pkgs.add(dfltPkg);
+    for (String alt : alts.split(",")) {
+      pkgs.add(alt);
+    }
+    return pkgs.toArray(new String[0]);
+  }
+
+  private Class<?> taskClass(Config config, String taskName)
+      throws ClassNotFoundException {
+    for (String pkg : taskPackages) {
+      try {
+        return Class.forName(pkg+'.'+taskName+"Task");
+      } catch (ClassNotFoundException e) {
+        // failed in this package, might succeed in the next one... 
+      }
+    }
+    // can only get here if failed to instantiate
+    throw new ClassNotFoundException(taskName+" not found in packages "+Arrays.toString(taskPackages));
+  }
+
   @Override
   public String toString() {
     String newline = System.getProperty("line.separator");



Mime
View raw message