incubator-any23-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ans...@apache.org
Subject svn commit: r1371039 - in /incubator/any23/trunk/core/src/main/java/org/apache/any23/writer: BenchmarkTripleHandler.java ReportingTripleHandler.java
Date Thu, 09 Aug 2012 04:53:18 GMT
Author: ansell
Date: Thu Aug  9 04:53:17 2012
New Revision: 1371039

URL: http://svn.apache.org/viewvc?rev=1371039&view=rev
Log:
convert BenchmarkTripleHandler and ReportingTripleHandler to use AtomicInteger 

Modified:
    incubator/any23/trunk/core/src/main/java/org/apache/any23/writer/BenchmarkTripleHandler.java
    incubator/any23/trunk/core/src/main/java/org/apache/any23/writer/ReportingTripleHandler.java

Modified: incubator/any23/trunk/core/src/main/java/org/apache/any23/writer/BenchmarkTripleHandler.java
URL: http://svn.apache.org/viewvc/incubator/any23/trunk/core/src/main/java/org/apache/any23/writer/BenchmarkTripleHandler.java?rev=1371039&r1=1371038&r2=1371039&view=diff
==============================================================================
--- incubator/any23/trunk/core/src/main/java/org/apache/any23/writer/BenchmarkTripleHandler.java
(original)
+++ incubator/any23/trunk/core/src/main/java/org/apache/any23/writer/BenchmarkTripleHandler.java
Thu Aug  9 04:53:17 2012
@@ -25,6 +25,7 @@ import org.openrdf.model.Value;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Map.Entry;
+import java.util.concurrent.atomic.AtomicInteger;
 
 
 /**
@@ -69,9 +70,9 @@ public class BenchmarkTripleHandler impl
         sb.append("\n   -total triples: ").append(sum.triples);
         sb.append("\n   -total runtime: ").append(sum.runtime).append(" ms!");
         if (sum.runtime != 0)
-            sb.append("\n   -tripls/ms: ").append(sum.triples / sum.runtime);
-        if (sum.methodCalls != 0)
-            sb.append("\n   -ms/calls: ").append(sum.runtime / sum.methodCalls);
+            sb.append("\n   -tripls/ms: ").append(sum.triples.get() / sum.runtime);
+        if (sum.methodCalls.get() != 0)
+            sb.append("\n   -ms/calls: ").append(sum.runtime / sum.methodCalls.get());
 
         stats.remove("SUM");
 
@@ -81,9 +82,9 @@ public class BenchmarkTripleHandler impl
             sb.append("\n   -total triples: ").append(ent.getValue().triples);
             sb.append("\n   -total runtime: ").append(ent.getValue().runtime).append(" ms!");
             if (ent.getValue().runtime != 0)
-                sb.append("\n   -tripls/ms: "  ).append(ent.getValue().triples / ent.getValue().runtime);
-            if (ent.getValue().methodCalls != 0)
-                sb.append("\n   -ms/calls: "   ).append(ent.getValue().runtime / ent.getValue().methodCalls);
+                sb.append("\n   -tripls/ms: "  ).append(ent.getValue().triples.get() / ent.getValue().runtime);
+            if (ent.getValue().methodCalls.get() != 0)
+                sb.append("\n   -ms/calls: "   ).append(ent.getValue().runtime / ent.getValue().methodCalls.get());
 
         }
 
@@ -110,9 +111,9 @@ public class BenchmarkTripleHandler impl
         if (!stats.containsKey(context.getExtractorName())) {
             stats.put(context.getExtractorName(), new StatObject());
         }
-        stats.get(context.getExtractorName()).methodCalls++;
+        stats.get(context.getExtractorName()).methodCalls.incrementAndGet();
         stats.get(context.getExtractorName()).interimStart();
-        stats.get("SUM").methodCalls++;
+        stats.get("SUM").methodCalls.incrementAndGet();
         stats.get("SUM").interimStart();
         underlyingHandler.openContext(context);
     }
@@ -122,8 +123,8 @@ public class BenchmarkTripleHandler impl
         if (!stats.containsKey(context.getExtractorName())) {
             stats.put(context.getExtractorName(), new StatObject());
         }
-        stats.get(context.getExtractorName()).triples++;
-        stats.get("SUM").triples++;
+        stats.get(context.getExtractorName()).triples.incrementAndGet();
+        stats.get("SUM").triples.incrementAndGet();
         underlyingHandler.receiveTriple(s, p, o, g, context);
     }
 
@@ -144,8 +145,8 @@ public class BenchmarkTripleHandler impl
      */
     private class StatObject {
 
-        int methodCalls = 0;
-        int triples     = 0;
+        AtomicInteger methodCalls = new AtomicInteger(0);
+        AtomicInteger triples     = new AtomicInteger(0);
         long runtime    = 0;
         long intStart   = 0;
 

Modified: incubator/any23/trunk/core/src/main/java/org/apache/any23/writer/ReportingTripleHandler.java
URL: http://svn.apache.org/viewvc/incubator/any23/trunk/core/src/main/java/org/apache/any23/writer/ReportingTripleHandler.java?rev=1371039&r1=1371038&r2=1371039&view=diff
==============================================================================
--- incubator/any23/trunk/core/src/main/java/org/apache/any23/writer/ReportingTripleHandler.java
(original)
+++ incubator/any23/trunk/core/src/main/java/org/apache/any23/writer/ReportingTripleHandler.java
Thu Aug  9 04:53:17 2012
@@ -24,6 +24,7 @@ import org.openrdf.model.Value;
 
 import java.util.Collection;
 import java.util.HashSet;
+import java.util.concurrent.atomic.AtomicInteger;
 
 /**
  * A {@link TripleHandler} that collects
@@ -37,8 +38,8 @@ public class ReportingTripleHandler impl
     private final TripleHandler wrapped;
 
     private final Collection<String> extractorNames = new HashSet<String>();
-    private int totalTriples   = 0;
-    private int totalDocuments = 0;
+    private AtomicInteger totalTriples   = new AtomicInteger(0);
+    private AtomicInteger totalDocuments = new AtomicInteger(0);
 
     public ReportingTripleHandler(TripleHandler wrapped) {
         if(wrapped == null) {
@@ -52,11 +53,11 @@ public class ReportingTripleHandler impl
     }
 
     public int getTotalTriples() {
-        return totalTriples;
+        return totalTriples.get();
     }
 
     public int getTotalDocuments() {
-        return totalDocuments;
+        return totalDocuments.get();
     }
 
     /**
@@ -67,7 +68,7 @@ public class ReportingTripleHandler impl
     }
 
     public void startDocument(URI documentURI) throws TripleHandlerException {
-        totalDocuments++;
+        totalDocuments.incrementAndGet();
         wrapped.startDocument(documentURI);
     }
 
@@ -91,7 +92,7 @@ public class ReportingTripleHandler impl
             ExtractionContext context
     ) throws TripleHandlerException {
         extractorNames.add(context.getExtractorName());
-        totalTriples++;
+        totalTriples.incrementAndGet();
         wrapped.receiveTriple(s, p, o, g, context);
     }
 



Mime
View raw message