lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From o...@apache.org
Subject svn commit: r524969 [4/5] - in /lucene/java/trunk/contrib/benchmark/src/java/org/apache/lucene/benchmark: ./ byTask/ byTask/feeds/ byTask/programmatic/ byTask/stats/ byTask/tasks/ byTask/utils/ standard/ stats/ utils/
Date Mon, 02 Apr 2007 23:37:17 GMT
Modified: lucene/java/trunk/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/SearchTravRetTask.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/SearchTravRetTask.java?view=diff&rev=524969&r1=524968&r2=524969
==============================================================================
--- lucene/java/trunk/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/SearchTravRetTask.java (original)
+++ lucene/java/trunk/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/SearchTravRetTask.java Mon Apr  2 16:37:14 2007
@@ -1,44 +1,44 @@
-package org.apache.lucene.benchmark.byTask.tasks;
-
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import org.apache.lucene.benchmark.byTask.PerfRunData;
-
-/**
- * Search and Traverse and Retrieve docs task.
- * 
- * <p>Note: This task reuses the reader if it is already open. 
- * Otherwise a reader is opened at start and closed at the end.
- * </p>
+package org.apache.lucene.benchmark.byTask.tasks;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.lucene.benchmark.byTask.PerfRunData;
+
+/**
+ * Search and Traverse and Retrieve docs task.
  * 
- * <p>Takes optional param: traversal size (otherwise all results are traversed).</p>
+ * <p>Note: This task reuses the reader if it is already open. 
+ * Otherwise a reader is opened at start and closed at the end.
+ * </p>
  * 
- * <p>Other side effects: counts additional 1 (record) for each traversed hit, 
- * and 1 more for each retrieved (non null) document.</p>
- */
+ * <p>Takes optional param: traversal size (otherwise all results are traversed).</p>
+ * 
+ * <p>Other side effects: counts additional 1 (record) for each traversed hit, 
+ * and 1 more for each retrieved (non null) document.</p>
+ */
 public class SearchTravRetTask extends SearchTravTask {
-
-  public SearchTravRetTask(PerfRunData runData) {
-    super(runData);
-  }
-
-  public boolean withRetrieve() {
-    return true;
-  }
-
-}
+
+  public SearchTravRetTask(PerfRunData runData) {
+    super(runData);
+  }
+
+  public boolean withRetrieve() {
+    return true;
+  }
+
+}

Propchange: lucene/java/trunk/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/SearchTravRetTask.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: lucene/java/trunk/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/SearchTravTask.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/SearchTravTask.java?view=diff&rev=524969&r1=524968&r2=524969
==============================================================================
--- lucene/java/trunk/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/SearchTravTask.java (original)
+++ lucene/java/trunk/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/SearchTravTask.java Mon Apr  2 16:37:14 2007
@@ -1,65 +1,65 @@
-package org.apache.lucene.benchmark.byTask.tasks;
-
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import org.apache.lucene.benchmark.byTask.PerfRunData;
-import org.apache.lucene.benchmark.byTask.feeds.QueryMaker;
-
-/**
- * Search and Traverse task.
- * 
- * <p>Note: This task reuses the reader if it is already open. 
- * Otherwise a reader is opened at start and closed at the end.
+package org.apache.lucene.benchmark.byTask.tasks;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.lucene.benchmark.byTask.PerfRunData;
+import org.apache.lucene.benchmark.byTask.feeds.QueryMaker;
+
+/**
+ * Search and Traverse task.
+ * 
+ * <p>Note: This task reuses the reader if it is already open. 
+ * Otherwise a reader is opened at start and closed at the end.
  * <p/>
  * 
- * <p>Takes optional param: traversal size (otherwise all results are traversed).</p>
- * 
- * <p>Other side effects: counts additional 1 (record) for each traversed hit.</p>
- */
-public class SearchTravTask extends ReadTask {
+ * <p>Takes optional param: traversal size (otherwise all results are traversed).</p>
+ * 
+ * <p>Other side effects: counts additional 1 (record) for each traversed hit.</p>
+ */
+public class SearchTravTask extends ReadTask {
   protected int traversalSize = Integer.MAX_VALUE;
-
-  public SearchTravTask(PerfRunData runData) {
-    super(runData);
-  }
-
-  public boolean withRetrieve() {
-    return false;
-  }
-
-  public boolean withSearch() {
-    return true;
-  }
-
-  public boolean withTraverse() {
-    return true;
-  }
-
-  public boolean withWarm() {
-    return false;
-  }
-
+
+  public SearchTravTask(PerfRunData runData) {
+    super(runData);
+  }
+
+  public boolean withRetrieve() {
+    return false;
+  }
+
+  public boolean withSearch() {
+    return true;
+  }
+
+  public boolean withTraverse() {
+    return true;
+  }
+
+  public boolean withWarm() {
+    return false;
+  }
+
   
 
-  public QueryMaker getQueryMaker() {
+  public QueryMaker getQueryMaker() {
     return getRunData().getQueryMaker(this);
-  }
-
+  }
+
   public int traversalSize() {
     return traversalSize;
   }
@@ -75,4 +75,4 @@
   public boolean supportsParams() {
     return true;
   }
-}
+}

Propchange: lucene/java/trunk/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/SearchTravTask.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: lucene/java/trunk/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/SetPropTask.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/SetPropTask.java?view=diff&rev=524969&r1=524968&r2=524969
==============================================================================
--- lucene/java/trunk/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/SetPropTask.java (original)
+++ lucene/java/trunk/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/SetPropTask.java Mon Apr  2 16:37:14 2007
@@ -1,61 +1,61 @@
-package org.apache.lucene.benchmark.byTask.tasks;
-
-import org.apache.lucene.benchmark.byTask.PerfRunData;
-
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- * Set a performance test configuration property.
- * A property may have a single value, or a sequence of values, seprated by ":". 
- * If a sequence of values is specified, each time a new round starts, 
- * the next (cyclic) value is taken.  
+package org.apache.lucene.benchmark.byTask.tasks;
+
+import org.apache.lucene.benchmark.byTask.PerfRunData;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Set a performance test configuration property.
+ * A property may have a single value, or a sequence of values, seprated by ":". 
+ * If a sequence of values is specified, each time a new round starts, 
+ * the next (cyclic) value is taken.  
  * <br>Other side effects: none.
  * <br>Takes mandatory param: "name,value" pair. 
- * @see org.apache.lucene.benchmark.byTask.tasks.NewRoundTask
- */
-public class SetPropTask extends PerfTask {
-
-  public SetPropTask(PerfRunData runData) {
-    super(runData);
-  }
-
-  private String name;
-  private String value;
-  
-  public int doLogic() throws Exception {
-    if (name==null || value==null) {
-      throw new Exception(getName()+" - undefined name or value: name="+name+" value="+value);
-    }
-    getRunData().getConfig().set(name,value);
-    return 0;
-  }
-
-  /**
-   * Set the params (property name and value).
-   * @param params property name and value separated by ','.
-   */
-  public void setParams(String params) {
-    super.setParams(params);
-    int k = params.indexOf(",");
-    name = params.substring(0,k).trim();
-    value = params.substring(k+1).trim();
-  }
-
+ * @see org.apache.lucene.benchmark.byTask.tasks.NewRoundTask
+ */
+public class SetPropTask extends PerfTask {
+
+  public SetPropTask(PerfRunData runData) {
+    super(runData);
+  }
+
+  private String name;
+  private String value;
+  
+  public int doLogic() throws Exception {
+    if (name==null || value==null) {
+      throw new Exception(getName()+" - undefined name or value: name="+name+" value="+value);
+    }
+    getRunData().getConfig().set(name,value);
+    return 0;
+  }
+
+  /**
+   * Set the params (property name and value).
+   * @param params property name and value separated by ','.
+   */
+  public void setParams(String params) {
+    super.setParams(params);
+    int k = params.indexOf(",");
+    name = params.substring(0,k).trim();
+    value = params.substring(k+1).trim();
+  }
+
   /* (non-Javadoc)
    * @see org.apache.lucene.benchmark.byTask.tasks.PerfTask#supportsParams()
    */
@@ -63,4 +63,4 @@
     return true;
   }
 
-}
+}

Propchange: lucene/java/trunk/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/SetPropTask.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: lucene/java/trunk/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/TaskSequence.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/TaskSequence.java?view=diff&rev=524969&r1=524968&r2=524969
==============================================================================
--- lucene/java/trunk/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/TaskSequence.java (original)
+++ lucene/java/trunk/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/TaskSequence.java Mon Apr  2 16:37:14 2007
@@ -1,295 +1,295 @@
-package org.apache.lucene.benchmark.byTask.tasks;
-
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import java.util.ArrayList;
-import java.util.Iterator;
-
-import org.apache.lucene.benchmark.byTask.PerfRunData;
-import org.apache.lucene.benchmark.byTask.feeds.NoMoreDataException;
-
-/**
- * Sequence of parallel or sequential tasks.
- */
-public class TaskSequence extends PerfTask {
-  public static int REPEAT_EXHAUST = -2; 
-  private ArrayList tasks;
-  private int repetitions = 1;
-  private boolean parallel;
-  private TaskSequence parent;
-  private boolean letChildReport = true;
-  private int rate = 0;
-  private boolean perMin = false; // rate, if set, is, by default, be sec.
-  private String seqName; 
-  
-  public TaskSequence (PerfRunData runData, String name, TaskSequence parent, boolean parallel) {
-    super(runData);
-    name = (name!=null ? name : (parallel ? "Par" : "Seq"));
-    setName(name);
-    setSequenceName();
-    this.parent = parent;
-    this.parallel = parallel;
-    tasks = new ArrayList();
-  }
-
-  /**
-   * @return Returns the parallel.
-   */
-  public boolean isParallel() {
-    return parallel;
-  }
-
-  /**
-   * @return Returns the repetitions.
-   */
-  public int getRepetitions() {
-    return repetitions;
-  }
-
-  /**
-   * @param repetitions The repetitions to set.
-   * @throws Exception 
-   */
-  public void setRepetitions(int repetitions) throws Exception {
-    this.repetitions = repetitions;
-    if (repetitions==REPEAT_EXHAUST && isParallel()) {
-      throw new Exception("REPEAT_EXHAUST is not allowed for parallel tasks");
-    }
-    setSequenceName();
-  }
-
-  /**
-   * @return Returns the parent.
-   */
-  public TaskSequence getParent() {
-    return parent;
-  }
-
-  /*
-   * (non-Javadoc)
-   * @see org.apache.lucene.benchmark.byTask.tasks.PerfTask#doLogic()
-   */
-  public int doLogic() throws Exception {
-    return ( parallel ? doParallelTasks() : doSerialTasks());
-  }
-
-  private int doSerialTasks() throws Exception {
-    if (rate > 0) {
-      return doSerialTasksWithRate();
-    }
-    
-    int count = 0;
-    boolean exhausted = false;
-    for (int k=0; (repetitions==REPEAT_EXHAUST && !exhausted) || k<repetitions; k++) {
-      for (Iterator it = tasks.iterator(); it.hasNext();) {
-        PerfTask task = (PerfTask) it.next();
-        try {
-          count += task.runAndMaybeStats(letChildReport);
-        } catch (NoMoreDataException e) {
-          exhausted = true;
-        }
-      }
-    }
-    return count;
-  }
-
-  private int doSerialTasksWithRate() throws Exception {
-    long delayStep = (perMin ? 60000 : 1000) /rate;
-    long nextStartTime = System.currentTimeMillis();
-    int count = 0;
-    boolean exhausted = false;
-    for (int k=0; (repetitions==REPEAT_EXHAUST && !exhausted) || k<repetitions; k++) {
-      for (Iterator it = tasks.iterator(); it.hasNext();) {
-        PerfTask task = (PerfTask) it.next();
-        long waitMore = nextStartTime - System.currentTimeMillis();
-        if (waitMore > 0) {
-          //System.out.println("wait: "+waitMore+" for rate: "+ratePerMin+" (delayStep="+delayStep+")");
-          Thread.sleep(waitMore);
-        }
-        nextStartTime += delayStep; // this aims at avarage rate. 
-        try {
-          count += task.runAndMaybeStats(letChildReport);
-        } catch (NoMoreDataException e) {
-          exhausted = true;
-        }
-      }
-    }
-    return count;
-  }
-
-  private int doParallelTasks() throws Exception {
-    final int count [] = {0};
-    Thread t[] = new Thread [repetitions * tasks.size()];
-    // prepare threads
-    int indx = 0;
-    for (int k=0; k<repetitions; k++) {
-      for (int i = 0; i < tasks.size(); i++) {
-        final PerfTask task = (PerfTask) ((PerfTask) tasks.get(i)).clone();
-        t[indx++] = new Thread() {
-          public void run() {
-            int n;
-            try {
-              n = task.runAndMaybeStats(letChildReport);
-            } catch (Exception e) {
-              throw new RuntimeException(e);
-            }
-            synchronized (count) {
-              count[0] += n;
-            }
-          }
-        };
-      }
-    }
-    // run threads
-    startThreads(t);
-    // wait for all threads to complete
-    for (int i = 0; i < t.length; i++) {
-      t[i].join();
-    }
-    // return total count
-    return count[0];
-  }
-
-  // run threads
-  private void startThreads(Thread[] t) throws InterruptedException {
-    if (rate > 0) {
-      startlThreadsWithRate(t);
-      return;
-    }
-    for (int i = 0; i < t.length; i++) {
-      t[i].start();
-    }
-  }
-
-  // run threadsm with rate
-  private void startlThreadsWithRate(Thread[] t) throws InterruptedException {
-    long delayStep = (perMin ? 60000 : 1000) /rate;
-    long nextStartTime = System.currentTimeMillis();
-    for (int i = 0; i < t.length; i++) {
-      long waitMore = nextStartTime - System.currentTimeMillis();
-      if (waitMore > 0) {
-        //System.out.println("thread wait: "+waitMore+" for rate: "+ratePerMin+" (delayStep="+delayStep+")");
-        Thread.sleep(waitMore);
-      }
-      nextStartTime += delayStep; // this aims at avarage rate of starting threads. 
-      t[i].start();
-    }
-  }
-
-  public void addTask(PerfTask task) {
-    tasks.add(task);
-    task.setDepth(getDepth()+1);
-  }
-  
-  /* (non-Javadoc)
-   * @see java.lang.Object#toString()
-   */
-  public String toString() {
-    String padd = getPadding();
-    StringBuffer sb = new StringBuffer(super.toString());
-    sb.append(parallel ? " [" : " {");
-    sb.append(NEW_LINE);
-    for (Iterator it = tasks.iterator(); it.hasNext();) {
-      PerfTask task = (PerfTask) it.next();
-      sb.append(task.toString());
-      sb.append(NEW_LINE);
-    }
-    sb.append(padd);
-    sb.append(!letChildReport ? ">" : (parallel ? "]" : "}"));
-    if (repetitions>1) {
-      sb.append(" * " + repetitions);
-    }
-    if (repetitions==REPEAT_EXHAUST) {
-      sb.append(" * EXHAUST");
-    }
-    if (rate>0) {
-      sb.append(",  rate: " + rate+"/"+(perMin?"min":"sec"));
-    }
-    return sb.toString();
-  }
-
-  /**
-   * Execute child tasks in a way that they do not report their time separately.
-   */
-  public void setNoChildReport() {
-    letChildReport  = false;
-    for (Iterator it = tasks.iterator(); it.hasNext();) {
-      PerfTask task = (PerfTask) it.next();
-      if (task instanceof TaskSequence) {
-        ((TaskSequence)task).setNoChildReport();
-  }
-    }
-  }
-
-  /**
-   * Returns the rate per minute: how many operations should be performed in a minute.
-   * If 0 this has no effect.
-   * @return the rate per min: how many operations should be performed in a minute.
-   */
-  public int getRate() {
-    return (perMin ? rate : 60*rate);
-  }
-
-  /**
-   * @param rate The rate to set.
-   */
-  public void setRate(int rate, boolean perMin) {
-    this.rate = rate;
-    this.perMin = perMin;
-    setSequenceName();
-  }
-
-  private void setSequenceName() {
-    seqName = super.getName();
-    if (repetitions==REPEAT_EXHAUST) {
-      seqName += "_Exhaust";
-    } else if (repetitions>1) {
-      seqName += "_"+repetitions;
-    }
-    if (rate>0) {
-      seqName += "_" + rate + (perMin?"/min":"/sec"); 
-    }
-    if (parallel && seqName.toLowerCase().indexOf("par")<0) {
-      seqName += "_Par";
-    }
-  }
-
-  public String getName() {
-    return seqName; // overide to include more info 
-  }
-
-  /**
-   * @return Returns the tasks.
-   */
-  public ArrayList getTasks() {
-    return tasks;
-  }
-
-  /* (non-Javadoc)
-   * @see java.lang.Object#clone()
-   */
-  protected Object clone() throws CloneNotSupportedException {
-    TaskSequence res = (TaskSequence) super.clone();
-    res.tasks = new ArrayList();
-    for (int i = 0; i < tasks.size(); i++) {
-      res.tasks.add(((PerfTask)tasks.get(i)).clone());
-    }
-    return res;
-  }
-  
-}
+package org.apache.lucene.benchmark.byTask.tasks;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import org.apache.lucene.benchmark.byTask.PerfRunData;
+import org.apache.lucene.benchmark.byTask.feeds.NoMoreDataException;
+
+/**
+ * Sequence of parallel or sequential tasks.
+ */
+public class TaskSequence extends PerfTask {
+  public static int REPEAT_EXHAUST = -2; 
+  private ArrayList tasks;
+  private int repetitions = 1;
+  private boolean parallel;
+  private TaskSequence parent;
+  private boolean letChildReport = true;
+  private int rate = 0;
+  private boolean perMin = false; // rate, if set, is, by default, be sec.
+  private String seqName; 
+  
+  public TaskSequence (PerfRunData runData, String name, TaskSequence parent, boolean parallel) {
+    super(runData);
+    name = (name!=null ? name : (parallel ? "Par" : "Seq"));
+    setName(name);
+    setSequenceName();
+    this.parent = parent;
+    this.parallel = parallel;
+    tasks = new ArrayList();
+  }
+
+  /**
+   * @return Returns the parallel.
+   */
+  public boolean isParallel() {
+    return parallel;
+  }
+
+  /**
+   * @return Returns the repetitions.
+   */
+  public int getRepetitions() {
+    return repetitions;
+  }
+
+  /**
+   * @param repetitions The repetitions to set.
+   * @throws Exception 
+   */
+  public void setRepetitions(int repetitions) throws Exception {
+    this.repetitions = repetitions;
+    if (repetitions==REPEAT_EXHAUST && isParallel()) {
+      throw new Exception("REPEAT_EXHAUST is not allowed for parallel tasks");
+    }
+    setSequenceName();
+  }
+
+  /**
+   * @return Returns the parent.
+   */
+  public TaskSequence getParent() {
+    return parent;
+  }
+
+  /*
+   * (non-Javadoc)
+   * @see org.apache.lucene.benchmark.byTask.tasks.PerfTask#doLogic()
+   */
+  public int doLogic() throws Exception {
+    return ( parallel ? doParallelTasks() : doSerialTasks());
+  }
+
+  private int doSerialTasks() throws Exception {
+    if (rate > 0) {
+      return doSerialTasksWithRate();
+    }
+    
+    int count = 0;
+    boolean exhausted = false;
+    for (int k=0; (repetitions==REPEAT_EXHAUST && !exhausted) || k<repetitions; k++) {
+      for (Iterator it = tasks.iterator(); it.hasNext();) {
+        PerfTask task = (PerfTask) it.next();
+        try {
+          count += task.runAndMaybeStats(letChildReport);
+        } catch (NoMoreDataException e) {
+          exhausted = true;
+        }
+      }
+    }
+    return count;
+  }
+
+  private int doSerialTasksWithRate() throws Exception {
+    long delayStep = (perMin ? 60000 : 1000) /rate;
+    long nextStartTime = System.currentTimeMillis();
+    int count = 0;
+    boolean exhausted = false;
+    for (int k=0; (repetitions==REPEAT_EXHAUST && !exhausted) || k<repetitions; k++) {
+      for (Iterator it = tasks.iterator(); it.hasNext();) {
+        PerfTask task = (PerfTask) it.next();
+        long waitMore = nextStartTime - System.currentTimeMillis();
+        if (waitMore > 0) {
+          //System.out.println("wait: "+waitMore+" for rate: "+ratePerMin+" (delayStep="+delayStep+")");
+          Thread.sleep(waitMore);
+        }
+        nextStartTime += delayStep; // this aims at avarage rate. 
+        try {
+          count += task.runAndMaybeStats(letChildReport);
+        } catch (NoMoreDataException e) {
+          exhausted = true;
+        }
+      }
+    }
+    return count;
+  }
+
+  private int doParallelTasks() throws Exception {
+    final int count [] = {0};
+    Thread t[] = new Thread [repetitions * tasks.size()];
+    // prepare threads
+    int indx = 0;
+    for (int k=0; k<repetitions; k++) {
+      for (int i = 0; i < tasks.size(); i++) {
+        final PerfTask task = (PerfTask) ((PerfTask) tasks.get(i)).clone();
+        t[indx++] = new Thread() {
+          public void run() {
+            int n;
+            try {
+              n = task.runAndMaybeStats(letChildReport);
+            } catch (Exception e) {
+              throw new RuntimeException(e);
+            }
+            synchronized (count) {
+              count[0] += n;
+            }
+          }
+        };
+      }
+    }
+    // run threads
+    startThreads(t);
+    // wait for all threads to complete
+    for (int i = 0; i < t.length; i++) {
+      t[i].join();
+    }
+    // return total count
+    return count[0];
+  }
+
+  // run threads
+  private void startThreads(Thread[] t) throws InterruptedException {
+    if (rate > 0) {
+      startlThreadsWithRate(t);
+      return;
+    }
+    for (int i = 0; i < t.length; i++) {
+      t[i].start();
+    }
+  }
+
+  // run threadsm with rate
+  private void startlThreadsWithRate(Thread[] t) throws InterruptedException {
+    long delayStep = (perMin ? 60000 : 1000) /rate;
+    long nextStartTime = System.currentTimeMillis();
+    for (int i = 0; i < t.length; i++) {
+      long waitMore = nextStartTime - System.currentTimeMillis();
+      if (waitMore > 0) {
+        //System.out.println("thread wait: "+waitMore+" for rate: "+ratePerMin+" (delayStep="+delayStep+")");
+        Thread.sleep(waitMore);
+      }
+      nextStartTime += delayStep; // this aims at avarage rate of starting threads. 
+      t[i].start();
+    }
+  }
+
+  public void addTask(PerfTask task) {
+    tasks.add(task);
+    task.setDepth(getDepth()+1);
+  }
+  
+  /* (non-Javadoc)
+   * @see java.lang.Object#toString()
+   */
+  public String toString() {
+    String padd = getPadding();
+    StringBuffer sb = new StringBuffer(super.toString());
+    sb.append(parallel ? " [" : " {");
+    sb.append(NEW_LINE);
+    for (Iterator it = tasks.iterator(); it.hasNext();) {
+      PerfTask task = (PerfTask) it.next();
+      sb.append(task.toString());
+      sb.append(NEW_LINE);
+    }
+    sb.append(padd);
+    sb.append(!letChildReport ? ">" : (parallel ? "]" : "}"));
+    if (repetitions>1) {
+      sb.append(" * " + repetitions);
+    }
+    if (repetitions==REPEAT_EXHAUST) {
+      sb.append(" * EXHAUST");
+    }
+    if (rate>0) {
+      sb.append(",  rate: " + rate+"/"+(perMin?"min":"sec"));
+    }
+    return sb.toString();
+  }
+
+  /**
+   * Execute child tasks in a way that they do not report their time separately.
+   */
+  public void setNoChildReport() {
+    letChildReport  = false;
+    for (Iterator it = tasks.iterator(); it.hasNext();) {
+      PerfTask task = (PerfTask) it.next();
+      if (task instanceof TaskSequence) {
+        ((TaskSequence)task).setNoChildReport();
+  }
+    }
+  }
+
+  /**
+   * Returns the rate per minute: how many operations should be performed in a minute.
+   * If 0 this has no effect.
+   * @return the rate per min: how many operations should be performed in a minute.
+   */
+  public int getRate() {
+    return (perMin ? rate : 60*rate);
+  }
+
+  /**
+   * @param rate The rate to set.
+   */
+  public void setRate(int rate, boolean perMin) {
+    this.rate = rate;
+    this.perMin = perMin;
+    setSequenceName();
+  }
+
+  private void setSequenceName() {
+    seqName = super.getName();
+    if (repetitions==REPEAT_EXHAUST) {
+      seqName += "_Exhaust";
+    } else if (repetitions>1) {
+      seqName += "_"+repetitions;
+    }
+    if (rate>0) {
+      seqName += "_" + rate + (perMin?"/min":"/sec"); 
+    }
+    if (parallel && seqName.toLowerCase().indexOf("par")<0) {
+      seqName += "_Par";
+    }
+  }
+
+  public String getName() {
+    return seqName; // overide to include more info 
+  }
+
+  /**
+   * @return Returns the tasks.
+   */
+  public ArrayList getTasks() {
+    return tasks;
+  }
+
+  /* (non-Javadoc)
+   * @see java.lang.Object#clone()
+   */
+  protected Object clone() throws CloneNotSupportedException {
+    TaskSequence res = (TaskSequence) super.clone();
+    res.tasks = new ArrayList();
+    for (int i = 0; i < tasks.size(); i++) {
+      res.tasks.add(((PerfTask)tasks.get(i)).clone());
+    }
+    return res;
+  }
+  
+}

Propchange: lucene/java/trunk/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/TaskSequence.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: lucene/java/trunk/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/WarmTask.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/WarmTask.java?view=diff&rev=524969&r1=524968&r2=524969
==============================================================================
--- lucene/java/trunk/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/WarmTask.java (original)
+++ lucene/java/trunk/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/WarmTask.java Mon Apr  2 16:37:14 2007
@@ -1,60 +1,60 @@
-package org.apache.lucene.benchmark.byTask.tasks;
-
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import org.apache.lucene.benchmark.byTask.PerfRunData;
-import org.apache.lucene.benchmark.byTask.feeds.QueryMaker;
-
-/**
- * Warm reader task: retrieve all reader documents.
- * 
- * <p>Note: This task reuses the reader if it is already open. 
- * Otherwise a reader is opened at start and closed at the end.
- * </p>
- * 
- * <p>Other side effects: counts additional 1 (record) for each 
- * retrieved (non null) document.</p>
- */
-public class WarmTask extends ReadTask {
-
-  public WarmTask(PerfRunData runData) {
-    super(runData);
-  }
-
-  public boolean withRetrieve() {
-    return false;
-  }
-
-  public boolean withSearch() {
-    return false;
-  }
-
-  public boolean withTraverse() {
-    return false;
-  }
-
-  public boolean withWarm() {
-    return true;
-  }
-
-  public QueryMaker getQueryMaker() {
-    return null; // not required for this task.
-  }
-
-
-}
+package org.apache.lucene.benchmark.byTask.tasks;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.lucene.benchmark.byTask.PerfRunData;
+import org.apache.lucene.benchmark.byTask.feeds.QueryMaker;
+
+/**
+ * Warm reader task: retrieve all reader documents.
+ * 
+ * <p>Note: This task reuses the reader if it is already open. 
+ * Otherwise a reader is opened at start and closed at the end.
+ * </p>
+ * 
+ * <p>Other side effects: counts additional 1 (record) for each 
+ * retrieved (non null) document.</p>
+ */
+public class WarmTask extends ReadTask {
+
+  public WarmTask(PerfRunData runData) {
+    super(runData);
+  }
+
+  public boolean withRetrieve() {
+    return false;
+  }
+
+  public boolean withSearch() {
+    return false;
+  }
+
+  public boolean withTraverse() {
+    return false;
+  }
+
+  public boolean withWarm() {
+    return true;
+  }
+
+  public QueryMaker getQueryMaker() {
+    return null; // not required for this task.
+  }
+
+
+}

Propchange: lucene/java/trunk/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/WarmTask.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: lucene/java/trunk/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/utils/Algorithm.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/utils/Algorithm.java?view=diff&rev=524969&r1=524968&r2=524969
==============================================================================
--- lucene/java/trunk/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/utils/Algorithm.java (original)
+++ lucene/java/trunk/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/utils/Algorithm.java Mon Apr  2 16:37:14 2007
@@ -1,258 +1,258 @@
-package org.apache.lucene.benchmark.byTask.utils;
-
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import java.io.StreamTokenizer;
-import java.io.StringReader;
-import java.lang.reflect.Constructor;
-import java.util.ArrayList;
-
-import org.apache.lucene.benchmark.byTask.PerfRunData;
-import org.apache.lucene.benchmark.byTask.tasks.PerfTask;
-import org.apache.lucene.benchmark.byTask.tasks.RepSumByPrefTask;
-import org.apache.lucene.benchmark.byTask.tasks.TaskSequence;
-
-/**
- * Test algorithm, as read from file
- */
-public class Algorithm {
-  
-  private TaskSequence sequence;
-  
-  /**
-   * Read algorithm from file
-   * @param runData perf-run-data used at running the tasks.
-   * @throws Exception if errors while parsing the algorithm 
-   */
-  public Algorithm (PerfRunData runData) throws Exception {
-    String algTxt = runData.getConfig().getAlgorithmText();
-    sequence = new TaskSequence(runData,null,null,false);
-    TaskSequence currSequence = sequence;
-    PerfTask prevTask = null;
-    StreamTokenizer stok = new StreamTokenizer(new StringReader(algTxt));
-    stok.commentChar('#');
-    stok.eolIsSignificant(false);
-    stok.ordinaryChar('"');
-    stok.ordinaryChar('/');
-    stok.ordinaryChar('(');
-    stok.ordinaryChar(')');
-    boolean colonOk = false; 
-    currSequence.setDepth(0);
-    String taskPackage = PerfTask.class.getPackage().getName() + ".";
-    
-    Class paramClass[] = {PerfRunData.class};
-    PerfRunData paramObj[] = {runData};
-    
-    while (stok.nextToken() != StreamTokenizer.TT_EOF) { 
-      switch(stok.ttype) {
-  
-        case StreamTokenizer.TT_WORD:
-          String s = stok.sval;
-          Constructor cnstr = Class.forName(taskPackage+s+"Task").getConstructor(paramClass);
-          PerfTask task = (PerfTask) cnstr.newInstance(paramObj);
-          currSequence.addTask(task);
-          if (task instanceof RepSumByPrefTask) {
-            stok.nextToken();
-            String prefix = stok.sval;
-            if (prefix==null || prefix.length()==0) { 
-              throw new Exception("named report prefix problem - "+stok.toString()); 
-            }
-            ((RepSumByPrefTask) task).setPrefix(prefix);
-          }
-          // check for task param: '(' someParam ')'
-          stok.nextToken();
-          if (stok.ttype!='(') {
-            stok.pushBack();
-          } else {
-            // get params, for tasks that supports them, - anything until next ')'
-            StringBuffer params = new StringBuffer();
-            stok.nextToken();
-            while (stok.ttype!=')') { 
-              switch (stok.ttype) {
-                case StreamTokenizer.TT_NUMBER:  
-                  params.append(stok.nval);
-                  break;
-                case StreamTokenizer.TT_WORD:    
-                  params.append(stok.sval);             
-                  break;
-                case StreamTokenizer.TT_EOF:     
-                  throw new Exception("unexpexted EOF: - "+stok.toString());
-                default:
-                  params.append((char)stok.ttype);
-              }
-              stok.nextToken();
-            }
-            String prm = params.toString().trim();
-            if (prm.length()>0) {
-              task.setParams(prm);
-            }
-          }
-
-          // ---------------------------------------
-          colonOk = false; prevTask = task;
-          break;
-  
-        default:
-          char c = (char)stok.ttype;
-          
-          switch(c) {
-          
-            case ':' :
-              if (!colonOk) throw new Exception("colon unexpexted: - "+stok.toString());
-              colonOk = false;
-              // get repetitions number
-              stok.nextToken();
-              if ((char)stok.ttype == '*') {
-                ((TaskSequence)prevTask).setRepetitions(TaskSequence.REPEAT_EXHAUST);
-              } else {
-                if (stok.ttype!=StreamTokenizer.TT_NUMBER) throw new Exception("expexted repetitions number: - "+stok.toString());
-                ((TaskSequence)prevTask).setRepetitions((int)stok.nval);
-              }
-              // check for rate specification (ops/min)
-              stok.nextToken();
-              if (stok.ttype!=':') {
-                stok.pushBack();
-              } else {
-                // get rate number
-                stok.nextToken();
-                if (stok.ttype!=StreamTokenizer.TT_NUMBER) throw new Exception("expexted rate number: - "+stok.toString());
-                // check for unit - min or sec, sec is default
-                stok.nextToken();
-                if (stok.ttype!='/') {
-                  stok.pushBack();
-                  ((TaskSequence)prevTask).setRate((int)stok.nval,false); // set rate per sec
-                } else {
-                  stok.nextToken();
-                  if (stok.ttype!=StreamTokenizer.TT_WORD) throw new Exception("expexted rate unit: 'min' or 'sec' - "+stok.toString());
-                  String unit = stok.sval.toLowerCase();
-                  if ("min".equals(unit)) {
-                    ((TaskSequence)prevTask).setRate((int)stok.nval,true); // set rate per min
-                  } else if ("sec".equals(unit)) {
-                    ((TaskSequence)prevTask).setRate((int)stok.nval,false); // set rate per sec
-                  } else {
-                    throw new Exception("expexted rate unit: 'min' or 'sec' - "+stok.toString());
-                  }
-                }
-              }
-              colonOk = false;
-              break;
-    
-            case '{' : 
-            case '[' :  
-              // a sequence
-              // check for sequence name
-              String name = null;
-              stok.nextToken();
-              if (stok.ttype!='"') {
-                stok.pushBack();
-              } else {
-                stok.nextToken();
-                name = stok.sval;
-                stok.nextToken();
-                if (stok.ttype!='"' || name==null || name.length()==0) { 
-                  throw new Exception("sequence name problem - "+stok.toString()); 
-                }
-              }
-              // start the sequence
-              TaskSequence seq2 = new TaskSequence(runData, name, currSequence, c=='[');
-              currSequence.addTask(seq2);
-              currSequence = seq2;
-              colonOk = false;
-              break;
-    
-            case '>' :
-              currSequence.setNoChildReport();
-            case '}' : 
-            case ']' : 
-              // end sequence
-              colonOk = true; prevTask = currSequence;
-              currSequence = currSequence.getParent();
-              break;
-          
-          } //switch(c)
-          break;
-          
-      } //switch(stok.ttype)
-      
-    }
-    
-    if (sequence != currSequence) {
-      throw new Exception("Unmatched sequences");
-    }
-    
-    // remove redundant top level enclosing sequences
-    while (sequence.getRepetitions()==1 && sequence.getRate()==0) {
-      ArrayList t = sequence.getTasks();
-      if (t!=null && t.size()==1) {
-        PerfTask p = (PerfTask) t.get(0);
-        if (p instanceof TaskSequence) {
-          sequence = (TaskSequence) p;
-          continue;
-        }
-      }
-      break;
-    }
-  }
-
-  /* (non-Javadoc)
-   * @see java.lang.Object#toString()
-   */
-  public String toString() {
-    String newline = System.getProperty("line.separator");
-    StringBuffer sb = new StringBuffer();
-    sb.append(sequence.toString());
-    sb.append(newline);
-    return sb.toString();
-  }
-
-  /**
-   * Execute this algorithm
-   * @throws Exception 
-   */
-  public void execute() throws Exception {
-    sequence.doLogic();
-  }
-
-  /**
-   * Expert: for test purposes, return all tasks participating in this algorithm.
-   * @return all tasks participating in this algorithm.
-   */
-  public ArrayList extractTasks() {
-    ArrayList res = new ArrayList();
-    extractTasks(res, sequence);
-    return res;
-  }
-  private void extractTasks (ArrayList extrct, TaskSequence seq) {
-    if (seq==null) 
-      return;
-    extrct.add(seq);
-    ArrayList t = sequence.getTasks();
-    if (t==null) 
-      return;
-    for (int i = 0; i < t.size(); i++) {
-      PerfTask p = (PerfTask) t.get(0);
-      if (p instanceof TaskSequence) {
-        extractTasks(extrct, (TaskSequence)p);
-      } else {
-        extrct.add(p);
-      }
-    }
-  }
-  
-}
-
+package org.apache.lucene.benchmark.byTask.utils;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.StreamTokenizer;
+import java.io.StringReader;
+import java.lang.reflect.Constructor;
+import java.util.ArrayList;
+
+import org.apache.lucene.benchmark.byTask.PerfRunData;
+import org.apache.lucene.benchmark.byTask.tasks.PerfTask;
+import org.apache.lucene.benchmark.byTask.tasks.RepSumByPrefTask;
+import org.apache.lucene.benchmark.byTask.tasks.TaskSequence;
+
+/**
+ * Test algorithm, as read from file
+ */
+public class Algorithm {
+  
+  private TaskSequence sequence;
+  
+  /**
+   * Read algorithm from file
+   * @param runData perf-run-data used at running the tasks.
+   * @throws Exception if errors while parsing the algorithm 
+   */
+  public Algorithm (PerfRunData runData) throws Exception {
+    String algTxt = runData.getConfig().getAlgorithmText();
+    sequence = new TaskSequence(runData,null,null,false);
+    TaskSequence currSequence = sequence;
+    PerfTask prevTask = null;
+    StreamTokenizer stok = new StreamTokenizer(new StringReader(algTxt));
+    stok.commentChar('#');
+    stok.eolIsSignificant(false);
+    stok.ordinaryChar('"');
+    stok.ordinaryChar('/');
+    stok.ordinaryChar('(');
+    stok.ordinaryChar(')');
+    boolean colonOk = false; 
+    currSequence.setDepth(0);
+    String taskPackage = PerfTask.class.getPackage().getName() + ".";
+    
+    Class paramClass[] = {PerfRunData.class};
+    PerfRunData paramObj[] = {runData};
+    
+    while (stok.nextToken() != StreamTokenizer.TT_EOF) { 
+      switch(stok.ttype) {
+  
+        case StreamTokenizer.TT_WORD:
+          String s = stok.sval;
+          Constructor cnstr = Class.forName(taskPackage+s+"Task").getConstructor(paramClass);
+          PerfTask task = (PerfTask) cnstr.newInstance(paramObj);
+          currSequence.addTask(task);
+          if (task instanceof RepSumByPrefTask) {
+            stok.nextToken();
+            String prefix = stok.sval;
+            if (prefix==null || prefix.length()==0) { 
+              throw new Exception("named report prefix problem - "+stok.toString()); 
+            }
+            ((RepSumByPrefTask) task).setPrefix(prefix);
+          }
+          // check for task param: '(' someParam ')'
+          stok.nextToken();
+          if (stok.ttype!='(') {
+            stok.pushBack();
+          } else {
+            // get params, for tasks that supports them, - anything until next ')'
+            StringBuffer params = new StringBuffer();
+            stok.nextToken();
+            while (stok.ttype!=')') { 
+              switch (stok.ttype) {
+                case StreamTokenizer.TT_NUMBER:  
+                  params.append(stok.nval);
+                  break;
+                case StreamTokenizer.TT_WORD:    
+                  params.append(stok.sval);             
+                  break;
+                case StreamTokenizer.TT_EOF:     
+                  throw new Exception("unexpexted EOF: - "+stok.toString());
+                default:
+                  params.append((char)stok.ttype);
+              }
+              stok.nextToken();
+            }
+            String prm = params.toString().trim();
+            if (prm.length()>0) {
+              task.setParams(prm);
+            }
+          }
+
+          // ---------------------------------------
+          colonOk = false; prevTask = task;
+          break;
+  
+        default:
+          char c = (char)stok.ttype;
+          
+          switch(c) {
+          
+            case ':' :
+              if (!colonOk) throw new Exception("colon unexpexted: - "+stok.toString());
+              colonOk = false;
+              // get repetitions number
+              stok.nextToken();
+              if ((char)stok.ttype == '*') {
+                ((TaskSequence)prevTask).setRepetitions(TaskSequence.REPEAT_EXHAUST);
+              } else {
+                if (stok.ttype!=StreamTokenizer.TT_NUMBER) throw new Exception("expexted repetitions number: - "+stok.toString());
+                ((TaskSequence)prevTask).setRepetitions((int)stok.nval);
+              }
+              // check for rate specification (ops/min)
+              stok.nextToken();
+              if (stok.ttype!=':') {
+                stok.pushBack();
+              } else {
+                // get rate number
+                stok.nextToken();
+                if (stok.ttype!=StreamTokenizer.TT_NUMBER) throw new Exception("expexted rate number: - "+stok.toString());
+                // check for unit - min or sec, sec is default
+                stok.nextToken();
+                if (stok.ttype!='/') {
+                  stok.pushBack();
+                  ((TaskSequence)prevTask).setRate((int)stok.nval,false); // set rate per sec
+                } else {
+                  stok.nextToken();
+                  if (stok.ttype!=StreamTokenizer.TT_WORD) throw new Exception("expexted rate unit: 'min' or 'sec' - "+stok.toString());
+                  String unit = stok.sval.toLowerCase();
+                  if ("min".equals(unit)) {
+                    ((TaskSequence)prevTask).setRate((int)stok.nval,true); // set rate per min
+                  } else if ("sec".equals(unit)) {
+                    ((TaskSequence)prevTask).setRate((int)stok.nval,false); // set rate per sec
+                  } else {
+                    throw new Exception("expexted rate unit: 'min' or 'sec' - "+stok.toString());
+                  }
+                }
+              }
+              colonOk = false;
+              break;
+    
+            case '{' : 
+            case '[' :  
+              // a sequence
+              // check for sequence name
+              String name = null;
+              stok.nextToken();
+              if (stok.ttype!='"') {
+                stok.pushBack();
+              } else {
+                stok.nextToken();
+                name = stok.sval;
+                stok.nextToken();
+                if (stok.ttype!='"' || name==null || name.length()==0) { 
+                  throw new Exception("sequence name problem - "+stok.toString()); 
+                }
+              }
+              // start the sequence
+              TaskSequence seq2 = new TaskSequence(runData, name, currSequence, c=='[');
+              currSequence.addTask(seq2);
+              currSequence = seq2;
+              colonOk = false;
+              break;
+    
+            case '>' :
+              currSequence.setNoChildReport();
+            case '}' : 
+            case ']' : 
+              // end sequence
+              colonOk = true; prevTask = currSequence;
+              currSequence = currSequence.getParent();
+              break;
+          
+          } //switch(c)
+          break;
+          
+      } //switch(stok.ttype)
+      
+    }
+    
+    if (sequence != currSequence) {
+      throw new Exception("Unmatched sequences");
+    }
+    
+    // remove redundant top level enclosing sequences
+    while (sequence.getRepetitions()==1 && sequence.getRate()==0) {
+      ArrayList t = sequence.getTasks();
+      if (t!=null && t.size()==1) {
+        PerfTask p = (PerfTask) t.get(0);
+        if (p instanceof TaskSequence) {
+          sequence = (TaskSequence) p;
+          continue;
+        }
+      }
+      break;
+    }
+  }
+
+  /* (non-Javadoc)
+   * @see java.lang.Object#toString()
+   */
+  public String toString() {
+    String newline = System.getProperty("line.separator");
+    StringBuffer sb = new StringBuffer();
+    sb.append(sequence.toString());
+    sb.append(newline);
+    return sb.toString();
+  }
+
+  /**
+   * Execute this algorithm
+   * @throws Exception 
+   */
+  public void execute() throws Exception {
+    sequence.doLogic();
+  }
+
+  /**
+   * Expert: for test purposes, return all tasks participating in this algorithm.
+   * @return all tasks participating in this algorithm.
+   */
+  public ArrayList extractTasks() {
+    ArrayList res = new ArrayList();
+    extractTasks(res, sequence);
+    return res;
+  }
+  private void extractTasks (ArrayList extrct, TaskSequence seq) {
+    if (seq==null) 
+      return;
+    extrct.add(seq);
+    ArrayList t = sequence.getTasks();
+    if (t==null) 
+      return;
+    for (int i = 0; i < t.size(); i++) {
+      PerfTask p = (PerfTask) t.get(0);
+      if (p instanceof TaskSequence) {
+        extractTasks(extrct, (TaskSequence)p);
+      } else {
+        extrct.add(p);
+      }
+    }
+  }
+  
+}
+

Propchange: lucene/java/trunk/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/utils/Algorithm.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: lucene/java/trunk/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/utils/Config.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/utils/Config.java?view=diff&rev=524969&r1=524968&r2=524969
==============================================================================
--- lucene/java/trunk/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/utils/Config.java (original)
+++ lucene/java/trunk/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/utils/Config.java Mon Apr  2 16:37:14 2007
@@ -1,324 +1,324 @@
-package org.apache.lucene.benchmark.byTask.utils;
-
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import java.io.BufferedReader;
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.Reader;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Properties;
-import java.util.StringTokenizer;
-
-/**
- * Perf run configuration properties.
- * Numeric peroperty containing ":", e.g. "10:100:5" is interpreted 
- * as array of numeric values. It is extracted once, on first use, and 
- * maintain an round number to return the appropriate value.   
- */
-public class Config {
-
-  private static final String NEW_LINE = System.getProperty("line.separator");
-
-  private int roundNumber = 0;
-  private Properties props;
-  private HashMap valByRound = new HashMap();
-  private HashMap colForValByRound = new HashMap();
-  private String algorithmText;
-
-  /**
-   * Read both algorithm and config properties.
-   * @param algReader from where to read algorithm and config properties.
-   * @throws IOException
-   */
-  public Config (Reader algReader) throws IOException {
-    // read alg file to array of lines
-    ArrayList lines = new ArrayList();
-    BufferedReader r = new BufferedReader(algReader);
-    int lastConfigLine=0;
-    for (String line = r.readLine(); line!=null; line=r.readLine()) {
-      lines.add(line);
-      if (line.indexOf('=')>0) {
-        lastConfigLine = lines.size();
-      }
-    }
-    r.close();
-    // copy props lines to string
-    StringBuffer sb = new StringBuffer();
-    for (int i=0; i<lastConfigLine; i++) {
-      sb.append(lines.get(i));
-      sb.append(NEW_LINE);
-    }
-    // read props from string
-    this.props = new Properties();
-    props.load(new ByteArrayInputStream(sb.toString().getBytes()));
-
-    if (Boolean.valueOf(props.getProperty("print.props","true")).booleanValue()) {
-      printProps();
-    }
-    
-    // copy algorithm lines
-    sb = new StringBuffer();
-    for (int i=lastConfigLine; i<lines.size(); i++) {
-      sb.append(lines.get(i));
-      sb.append(NEW_LINE);
-    }
-    algorithmText = sb.toString();
-  }
-
-  /**
-   * Create config without algorithm - usefull for a programmatic perf test.
-   * @param props - configuration properties.
-   * @throws IOException
-   */
-  public Config (Properties props) {
-    this.props = props;
-    if (Boolean.valueOf(props.getProperty("print.props","true")).booleanValue()) {
-      printProps();
-    }
-  }
-
-  private void printProps() {
-    System.out.println("------------> config properties:");
-    for (Iterator it = props.keySet().iterator(); it.hasNext();) {
-      String propName = (String) it.next();
-      System.out.println(propName + " = " + props.getProperty(propName));
-    }
-    System.out.println("-------------------------------");
-  }
-
-  /**
-   * Return a string property.
-   * @param name name of property.
-   * @param dflt default value.
-   * @return a string property.
-   */
-  public String get (String name, String dflt) {
-    return props.getProperty(name,dflt);
-  }
-
-  /**
-   * Set a property.
-   * Note: once a multiple values property is set, it can no longer be modified.
-   * @param name name of property.
-   * @param value either single or multiple propery value (multple values are separated by ":")
-   * @throws Exception 
-   */
-  public void set (String name, String value) throws Exception {
-    if (valByRound.get(name) != null) {
-      throw new Exception("Cannot modify a multi value property!");
-    }
-    props.setProperty(name,value);
-  }
-
-  /**
-   * Return an int property.
-   * If the property contain ":", e.g. "10:100:5", it is interpreted 
-   * as array of ints. It is extracted once, on first call
-   * to get() it, and a by-round-value is returned. 
-   * @param name name of property
-   * @param dflt default value
-   * @return a int property.
-   */
-  public int get (String name, int dflt) {
-    // use value by round if already parsed
-    int vals[] = (int[]) valByRound.get(name);
-    if (vals != null) {
-      return vals[roundNumber % vals.length];
-    }
-    // done if not by round 
-    String sval = props.getProperty(name,""+dflt);
-    if (sval.indexOf(":")<0) {
-      return Integer.parseInt(sval);
-    }
-    // first time this prop is extracted by round
-    int k = sval.indexOf(":");
-    String colName = sval.substring(0,k);
-    sval = sval.substring(k+1);
-    colForValByRound.put(name,colName);
-    vals = propToIntArray(sval);
-    valByRound.put(name,vals);
-    return vals[roundNumber % vals.length];
-  }
-  
-  /**
-   * Return a boolean property.
-   * If the property contain ":", e.g. "true.true.false", it is interpreted 
-   * as array of boleans. It is extracted once, on first call
-   * to get() it, and a by-round-value is returned. 
-   * @param name name of property
-   * @param dflt default value
-   * @return a int property.
-   */
-  public boolean get (String name, boolean dflt) {
-    // use value by round if already parsed
-    boolean vals[] = (boolean[]) valByRound.get(name);
-    if (vals != null) {
-      return vals[roundNumber % vals.length];
-    }
-    // done if not by round 
-    String sval = props.getProperty(name,""+dflt);
-    if (sval.indexOf(":")<0) {
-      return Boolean.valueOf(sval).booleanValue();
-    }
-    // first time this prop is extracted by round 
-    int k = sval.indexOf(":");
-    String colName = sval.substring(0,k);
-    sval = sval.substring(k+1);
-    colForValByRound.put(name,colName);
-    vals = propToBooleanArray(sval);
-    valByRound.put(name,vals);
-    return vals[roundNumber % vals.length];
-  }
-  
-  /**
-   * Increment the round number, for config values that are extracted by round number. 
-   * @return the new round number.
-   */
-  public int newRound () {
-    roundNumber++;
-    
-    // log changes in values
-    if (valByRound.size()>0) {
-      StringBuffer sb = new StringBuffer("--> Round ").append(roundNumber-1).append("-->").append(roundNumber).append(": ");
-      for (Iterator iter = valByRound.keySet().iterator(); iter.hasNext();) {
-        String name = (String) iter.next();
-        Object a = valByRound.get(name);
-        if (a instanceof int[]) {
-          int ai[] = (int[]) a;
-          int n1 = (roundNumber-1)%ai.length;
-          int n2 = roundNumber%ai.length;
-          sb.append("  ").append(name).append(":").append(ai[n1]).append("-->").append(ai[n2]);
-        } else {
-          boolean ab[] = (boolean[]) a;
-          int n1 = (roundNumber-1)%ab.length;
-          int n2 = roundNumber%ab.length;
-          sb.append("  ").append(name).append(":").append(ab[n1]).append("-->").append(ab[n2]);
-        }
-      }
-      System.out.println();
-      System.out.println(sb.toString());
-      System.out.println();
-    }
-    
-    return roundNumber;
-  }
-  
-  // extract properties to array, e.g. for "10.100.5" return int[]{10,100,5}. 
-  private int[] propToIntArray (String s) {
-    if (s.indexOf(":")<0) {
-      return new int [] { Integer.parseInt(s) };
-    }
-    
-    ArrayList a = new ArrayList();
-    StringTokenizer st = new StringTokenizer(s,":");
-    while (st.hasMoreTokens()) {
-      String t = st.nextToken();
-      a.add(new Integer(t));
-    }
-    int res[] = new int[a.size()]; 
-    for (int i=0; i<a.size(); i++) {
-      res[i] = ((Integer) a.get(i)).intValue();
-    }
-    return res;
-  }
-    
-  // extract properties to array, e.g. for "true.true.false" return booleab[]{true,false,false}. 
-  private boolean[] propToBooleanArray (String s) {
-    if (s.indexOf(":")<0) {
-      return new boolean [] { Boolean.valueOf(s).booleanValue() };
-    }
-    
-    ArrayList a = new ArrayList();
-    StringTokenizer st = new StringTokenizer(s,":");
-    while (st.hasMoreTokens()) {
-      String t = st.nextToken();
-      a.add(new Boolean(t));
-    }
-    boolean res[] = new boolean[a.size()]; 
-    for (int i=0; i<a.size(); i++) {
-      res[i] = ((Boolean) a.get(i)).booleanValue();
-    }
-    return res;
-  }
-
-  /**
-   * @return names of params set by round, for reports title
-   */
-  public String getColsNamesForValsByRound() {
-    if (colForValByRound.size()==0) {
-      return "";
-    }
-    StringBuffer sb = new StringBuffer(); 
-    for (Iterator it = colForValByRound.keySet().iterator(); it.hasNext();) {
-      String name = (String) it.next();
-      String colName = (String) colForValByRound.get(name);
-      sb.append(" ").append(colName);
-    }
-    return sb.toString();
-  }
-
-  /**
-   * @return values of params set by round, for reports lines.
-   */
-  public String getColsValuesForValsByRound(int roundNum) {
-    if (colForValByRound.size()==0) {
-      return "";
-    }
-    StringBuffer sb = new StringBuffer(); 
-    for (Iterator it = colForValByRound.keySet().iterator(); it.hasNext();) {
-      String name = (String) it.next();
-      String colName = (String) colForValByRound.get(name);
-      String template = " "+colName;
-      if (roundNum<0) {
-        // just append blanks
-        sb.append(Format.formatPaddLeft("-",template));
-      } else {
-        // append actual values, for that round
-        Object a = valByRound.get(name);
-        if (a instanceof int[]) {
-          int ai[] = (int[]) a;
-          int n = roundNum % ai.length;
-          sb.append(Format.format(ai[n],template));
-        } else {
-          boolean ab[] = (boolean[]) a;
-          int n = roundNum % ab.length;
-          sb.append(Format.formatPaddLeft(""+ab[n],template));
-        }
-      }
-    }
-    return sb.toString();
-  }
-
-  /**
-   * @return the round number.
-   */
-  public int getRoundNumber() {
-    return roundNumber;
-  }
-
-  /**
-   * @return Returns the algorithmText.
-   */
-  public String getAlgorithmText() {
-    return algorithmText;
-  }
-
-}
+package org.apache.lucene.benchmark.byTask.utils;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.BufferedReader;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.Reader;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Properties;
+import java.util.StringTokenizer;
+
+/**
+ * Perf run configuration properties.
+ * Numeric peroperty containing ":", e.g. "10:100:5" is interpreted 
+ * as array of numeric values. It is extracted once, on first use, and 
+ * maintain an round number to return the appropriate value.   
+ */
+public class Config {
+
+  private static final String NEW_LINE = System.getProperty("line.separator");
+
+  private int roundNumber = 0;
+  private Properties props;
+  private HashMap valByRound = new HashMap();
+  private HashMap colForValByRound = new HashMap();
+  private String algorithmText;
+
+  /**
+   * Read both algorithm and config properties.
+   * @param algReader from where to read algorithm and config properties.
+   * @throws IOException
+   */
+  public Config (Reader algReader) throws IOException {
+    // read alg file to array of lines
+    ArrayList lines = new ArrayList();
+    BufferedReader r = new BufferedReader(algReader);
+    int lastConfigLine=0;
+    for (String line = r.readLine(); line!=null; line=r.readLine()) {
+      lines.add(line);
+      if (line.indexOf('=')>0) {
+        lastConfigLine = lines.size();
+      }
+    }
+    r.close();
+    // copy props lines to string
+    StringBuffer sb = new StringBuffer();
+    for (int i=0; i<lastConfigLine; i++) {
+      sb.append(lines.get(i));
+      sb.append(NEW_LINE);
+    }
+    // read props from string
+    this.props = new Properties();
+    props.load(new ByteArrayInputStream(sb.toString().getBytes()));
+
+    if (Boolean.valueOf(props.getProperty("print.props","true")).booleanValue()) {
+      printProps();
+    }
+    
+    // copy algorithm lines
+    sb = new StringBuffer();
+    for (int i=lastConfigLine; i<lines.size(); i++) {
+      sb.append(lines.get(i));
+      sb.append(NEW_LINE);
+    }
+    algorithmText = sb.toString();
+  }
+
+  /**
+   * Create config without algorithm - usefull for a programmatic perf test.
+   * @param props - configuration properties.
+   * @throws IOException
+   */
+  public Config (Properties props) {
+    this.props = props;
+    if (Boolean.valueOf(props.getProperty("print.props","true")).booleanValue()) {
+      printProps();
+    }
+  }
+
+  private void printProps() {
+    System.out.println("------------> config properties:");
+    for (Iterator it = props.keySet().iterator(); it.hasNext();) {
+      String propName = (String) it.next();
+      System.out.println(propName + " = " + props.getProperty(propName));
+    }
+    System.out.println("-------------------------------");
+  }
+
+  /**
+   * Return a string property.
+   * @param name name of property.
+   * @param dflt default value.
+   * @return a string property.
+   */
+  public String get (String name, String dflt) {
+    return props.getProperty(name,dflt);
+  }
+
+  /**
+   * Set a property.
+   * Note: once a multiple values property is set, it can no longer be modified.
+   * @param name name of property.
+   * @param value either single or multiple propery value (multple values are separated by ":")
+   * @throws Exception 
+   */
+  public void set (String name, String value) throws Exception {
+    if (valByRound.get(name) != null) {
+      throw new Exception("Cannot modify a multi value property!");
+    }
+    props.setProperty(name,value);
+  }
+
+  /**
+   * Return an int property.
+   * If the property contain ":", e.g. "10:100:5", it is interpreted 
+   * as array of ints. It is extracted once, on first call
+   * to get() it, and a by-round-value is returned. 
+   * @param name name of property
+   * @param dflt default value
+   * @return a int property.
+   */
+  public int get (String name, int dflt) {
+    // use value by round if already parsed
+    int vals[] = (int[]) valByRound.get(name);
+    if (vals != null) {
+      return vals[roundNumber % vals.length];
+    }
+    // done if not by round 
+    String sval = props.getProperty(name,""+dflt);
+    if (sval.indexOf(":")<0) {
+      return Integer.parseInt(sval);
+    }
+    // first time this prop is extracted by round
+    int k = sval.indexOf(":");
+    String colName = sval.substring(0,k);
+    sval = sval.substring(k+1);
+    colForValByRound.put(name,colName);
+    vals = propToIntArray(sval);
+    valByRound.put(name,vals);
+    return vals[roundNumber % vals.length];
+  }
+  
+  /**
+   * Return a boolean property.
+   * If the property contain ":", e.g. "true.true.false", it is interpreted 
+   * as array of boleans. It is extracted once, on first call
+   * to get() it, and a by-round-value is returned. 
+   * @param name name of property
+   * @param dflt default value
+   * @return a int property.
+   */
+  public boolean get (String name, boolean dflt) {
+    // use value by round if already parsed
+    boolean vals[] = (boolean[]) valByRound.get(name);
+    if (vals != null) {
+      return vals[roundNumber % vals.length];
+    }
+    // done if not by round 
+    String sval = props.getProperty(name,""+dflt);
+    if (sval.indexOf(":")<0) {
+      return Boolean.valueOf(sval).booleanValue();
+    }
+    // first time this prop is extracted by round 
+    int k = sval.indexOf(":");
+    String colName = sval.substring(0,k);
+    sval = sval.substring(k+1);
+    colForValByRound.put(name,colName);
+    vals = propToBooleanArray(sval);
+    valByRound.put(name,vals);
+    return vals[roundNumber % vals.length];
+  }
+  
+  /**
+   * Increment the round number, for config values that are extracted by round number. 
+   * @return the new round number.
+   */
+  public int newRound () {
+    roundNumber++;
+    
+    // log changes in values
+    if (valByRound.size()>0) {
+      StringBuffer sb = new StringBuffer("--> Round ").append(roundNumber-1).append("-->").append(roundNumber).append(": ");
+      for (Iterator iter = valByRound.keySet().iterator(); iter.hasNext();) {
+        String name = (String) iter.next();
+        Object a = valByRound.get(name);
+        if (a instanceof int[]) {
+          int ai[] = (int[]) a;
+          int n1 = (roundNumber-1)%ai.length;
+          int n2 = roundNumber%ai.length;
+          sb.append("  ").append(name).append(":").append(ai[n1]).append("-->").append(ai[n2]);
+        } else {
+          boolean ab[] = (boolean[]) a;
+          int n1 = (roundNumber-1)%ab.length;
+          int n2 = roundNumber%ab.length;
+          sb.append("  ").append(name).append(":").append(ab[n1]).append("-->").append(ab[n2]);
+        }
+      }
+      System.out.println();
+      System.out.println(sb.toString());
+      System.out.println();
+    }
+    
+    return roundNumber;
+  }
+  
+  // extract properties to array, e.g. for "10.100.5" return int[]{10,100,5}. 
+  private int[] propToIntArray (String s) {
+    if (s.indexOf(":")<0) {
+      return new int [] { Integer.parseInt(s) };
+    }
+    
+    ArrayList a = new ArrayList();
+    StringTokenizer st = new StringTokenizer(s,":");
+    while (st.hasMoreTokens()) {
+      String t = st.nextToken();
+      a.add(new Integer(t));
+    }
+    int res[] = new int[a.size()]; 
+    for (int i=0; i<a.size(); i++) {
+      res[i] = ((Integer) a.get(i)).intValue();
+    }
+    return res;
+  }
+    
+  // extract properties to array, e.g. for "true.true.false" return booleab[]{true,false,false}. 
+  private boolean[] propToBooleanArray (String s) {
+    if (s.indexOf(":")<0) {
+      return new boolean [] { Boolean.valueOf(s).booleanValue() };
+    }
+    
+    ArrayList a = new ArrayList();
+    StringTokenizer st = new StringTokenizer(s,":");
+    while (st.hasMoreTokens()) {
+      String t = st.nextToken();
+      a.add(new Boolean(t));
+    }
+    boolean res[] = new boolean[a.size()]; 
+    for (int i=0; i<a.size(); i++) {
+      res[i] = ((Boolean) a.get(i)).booleanValue();
+    }
+    return res;
+  }
+
+  /**
+   * @return names of params set by round, for reports title
+   */
+  public String getColsNamesForValsByRound() {
+    if (colForValByRound.size()==0) {
+      return "";
+    }
+    StringBuffer sb = new StringBuffer(); 
+    for (Iterator it = colForValByRound.keySet().iterator(); it.hasNext();) {
+      String name = (String) it.next();
+      String colName = (String) colForValByRound.get(name);
+      sb.append(" ").append(colName);
+    }
+    return sb.toString();
+  }
+
+  /**
+   * @return values of params set by round, for reports lines.
+   */
+  public String getColsValuesForValsByRound(int roundNum) {
+    if (colForValByRound.size()==0) {
+      return "";
+    }
+    StringBuffer sb = new StringBuffer(); 
+    for (Iterator it = colForValByRound.keySet().iterator(); it.hasNext();) {
+      String name = (String) it.next();
+      String colName = (String) colForValByRound.get(name);
+      String template = " "+colName;
+      if (roundNum<0) {
+        // just append blanks
+        sb.append(Format.formatPaddLeft("-",template));
+      } else {
+        // append actual values, for that round
+        Object a = valByRound.get(name);
+        if (a instanceof int[]) {
+          int ai[] = (int[]) a;
+          int n = roundNum % ai.length;
+          sb.append(Format.format(ai[n],template));
+        } else {
+          boolean ab[] = (boolean[]) a;
+          int n = roundNum % ab.length;
+          sb.append(Format.formatPaddLeft(""+ab[n],template));
+        }
+      }
+    }
+    return sb.toString();
+  }
+
+  /**
+   * @return the round number.
+   */
+  public int getRoundNumber() {
+    return roundNumber;
+  }
+
+  /**
+   * @return Returns the algorithmText.
+   */
+  public String getAlgorithmText() {
+    return algorithmText;
+  }
+
+}

Propchange: lucene/java/trunk/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/utils/Config.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: lucene/java/trunk/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/utils/FileUtils.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/utils/FileUtils.java?view=diff&rev=524969&r1=524968&r2=524969
==============================================================================
--- lucene/java/trunk/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/utils/FileUtils.java (original)
+++ lucene/java/trunk/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/utils/FileUtils.java Mon Apr  2 16:37:14 2007
@@ -1,54 +1,54 @@
-package org.apache.lucene.benchmark.byTask.utils;
-
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import java.io.File;
-import java.io.IOException;
-
-/**
- * File utilities.
- */
-public class FileUtils {
-
-  /**
-   * Delete files and directories, even if non-empty.
-   *
-   * @param dir file or directory
-   * @return true on success, false if no or part of files have been deleted
-   * @throws java.io.IOException
-   */
-  public static boolean fullyDelete(File dir) throws IOException {
-    if (dir == null || !dir.exists()) return false;
-    File contents[] = dir.listFiles();
-    if (contents != null) {
-      for (int i = 0; i < contents.length; i++) {
-        if (contents[i].isFile()) {
-          if (!contents[i].delete()) {
-            return false;
-          }
-        } else {
-          if (!fullyDelete(contents[i])) {
-            return false;
-          }
-        }
-      }
-    }
-    return dir.delete();
-  }
-
-}
+package org.apache.lucene.benchmark.byTask.utils;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.File;
+import java.io.IOException;
+
+/**
+ * File utilities.
+ */
+public class FileUtils {
+
+  /**
+   * Delete files and directories, even if non-empty.
+   *
+   * @param dir file or directory
+   * @return true on success, false if no or part of files have been deleted
+   * @throws java.io.IOException
+   */
+  public static boolean fullyDelete(File dir) throws IOException {
+    if (dir == null || !dir.exists()) return false;
+    File contents[] = dir.listFiles();
+    if (contents != null) {
+      for (int i = 0; i < contents.length; i++) {
+        if (contents[i].isFile()) {
+          if (!contents[i].delete()) {
+            return false;
+          }
+        } else {
+          if (!fullyDelete(contents[i])) {
+            return false;
+          }
+        }
+      }
+    }
+    return dir.delete();
+  }
+
+}

Propchange: lucene/java/trunk/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/utils/FileUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message