You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by sh...@apache.org on 2011/12/19 16:30:58 UTC

svn commit: r1220799 - in /lucene/dev/branches/branch_3x: ./ lucene/ lucene/contrib/benchmark/ lucene/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/ lucene/src/java/org/apache/lucene/analysis/ lucene/src/test/org/apache/lucene/analysis/...

Author: shaie
Date: Mon Dec 19 15:30:58 2011
New Revision: 1220799

URL: http://svn.apache.org/viewvc?rev=1220799&view=rev
Log:
LUCENE-3635: Allow setting arbitrary objects on PerfRunData

Modified:
    lucene/dev/branches/branch_3x/   (props changed)
    lucene/dev/branches/branch_3x/lucene/   (props changed)
    lucene/dev/branches/branch_3x/lucene/contrib/benchmark/   (props changed)
    lucene/dev/branches/branch_3x/lucene/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/PerfRunData.java
    lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/analysis/CharTokenizer.java   (props changed)
    lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/analysis/TestCharTokenizers.java   (props changed)
    lucene/dev/branches/branch_3x/solr/   (props changed)

Modified: lucene/dev/branches/branch_3x/lucene/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/PerfRunData.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/PerfRunData.java?rev=1220799&r1=1220798&r2=1220799&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/PerfRunData.java (original)
+++ lucene/dev/branches/branch_3x/lucene/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/PerfRunData.java Mon Dec 19 15:30:58 2011
@@ -20,6 +20,7 @@ package org.apache.lucene.benchmark.byTa
 import java.io.Closeable;
 import java.io.File;
 import java.io.IOException;
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Locale;
 
@@ -28,6 +29,7 @@ import org.apache.lucene.benchmark.byTas
 import org.apache.lucene.benchmark.byTask.feeds.FacetSource;
 import org.apache.lucene.benchmark.byTask.feeds.QueryMaker;
 import org.apache.lucene.benchmark.byTask.stats.Points;
+import org.apache.lucene.benchmark.byTask.tasks.PerfTask;
 import org.apache.lucene.benchmark.byTask.tasks.ReadTask;
 import org.apache.lucene.benchmark.byTask.tasks.SearchTask;
 import org.apache.lucene.benchmark.byTask.utils.Config;
@@ -94,6 +96,7 @@ public class PerfRunData implements Clos
   private Config config;
   private long startTimeMillis;
 
+  private final HashMap<String, Object> perfObjects = new HashMap<String, Object>();
   
   // constructor
   public PerfRunData (Config config) throws Exception {
@@ -129,6 +132,15 @@ public class PerfRunData implements Clos
     IOUtils.close(indexWriter, indexReader, indexSearcher, directory, 
                   taxonomyWriter, taxonomyReader, taxonomyDir, 
                   docMaker, facetSource);
+    
+    // close all perf objects that are closeable.
+    ArrayList<Closeable> perfObjectsToClose = new ArrayList<Closeable>();
+    for (Object obj : perfObjects.values()) {
+      if (obj instanceof Closeable) {
+        perfObjectsToClose.add((Closeable) obj);
+      }
+    }
+    IOUtils.close(perfObjectsToClose);
   }
 
   // clean old stuff, reopen 
@@ -173,6 +185,20 @@ public class PerfRunData implements Clos
     return new RAMDirectory();
   }
   
+  /** Returns an object that was previously set by {@link #setPerfObject(String, Object)}. */
+  public synchronized Object getPerfObject(String key) {
+    return perfObjects.get(key);
+  }
+  
+  /**
+   * Sets an object that is required by {@link PerfTask}s, keyed by the given
+   * {@code key}. If the object implements {@link Closeable}, it will be closed
+   * by {@link #close()}.
+   */
+  public synchronized void setPerfObject(String key, Object obj) {
+    perfObjects.put(key, obj);
+  }
+  
   public long setStartTimeMillis() {
     startTimeMillis = System.currentTimeMillis();
     return startTimeMillis;