jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1565277 - /jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/QueryManagerImpl.java
Date Thu, 06 Feb 2014 14:29:47 GMT
Author: mduerig
Date: Thu Feb  6 14:29:46 2014
New Revision: 1565277

URL: http://svn.apache.org/r1565277
Log:
OAK-1338: Implement QueryStat from Jackrabbit API
Implement repository statistics: query count and query duration

Modified:
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/QueryManagerImpl.java

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/QueryManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/QueryManagerImpl.java?rev=1565277&r1=1565276&r2=1565277&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/QueryManagerImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/QueryManagerImpl.java
Thu Feb  6 14:29:46 2014
@@ -18,6 +18,9 @@
  */
 package org.apache.jackrabbit.oak.jcr.query;
 
+import static org.apache.jackrabbit.api.stats.RepositoryStatistics.Type.QUERY_COUNT;
+import static org.apache.jackrabbit.api.stats.RepositoryStatistics.Type.QUERY_DURATION;
+
 import java.text.ParseException;
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -25,6 +28,7 @@ import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
+import java.util.concurrent.atomic.AtomicLong;
 
 import javax.jcr.Node;
 import javax.jcr.RepositoryException;
@@ -55,6 +59,8 @@ public class QueryManagerImpl implements
     private final QueryObjectModelFactoryImpl qomFactory;
     private final QueryEngine queryEngine;
     private final HashSet<String> supportedQueryLanguages = new HashSet<String>();
+    private final AtomicLong queryCount;
+    private final AtomicLong queryDuration;
 
     public QueryManagerImpl(SessionContext sessionContext) {
         this.sessionDelegate = sessionContext.getSessionDelegate();
@@ -62,6 +68,8 @@ public class QueryManagerImpl implements
         qomFactory = new QueryObjectModelFactoryImpl(this, sessionContext);
         queryEngine = sessionDelegate.getQueryEngine();
         supportedQueryLanguages.addAll(queryEngine.getSupportedQueryLanguages());
+        queryCount = sessionContext.getCounter(QUERY_COUNT);
+        queryDuration = sessionContext.getCounter(QUERY_DURATION);
     }
 
     @Override
@@ -120,12 +128,15 @@ public class QueryManagerImpl implements
             long limit, long offset, HashMap<String, Value> bindVariableMap) throws
RepositoryException {
         try {
             Map<String, PropertyValue> bindMap = convertMap(bindVariableMap);
-            long t = System.nanoTime();
+            long t0 = System.nanoTime();
             Result r = queryEngine.executeQuery(
                     statement, language, limit, offset, bindMap,
                     sessionContext.getSessionLocalMappings());
+            queryCount.incrementAndGet();
+            long dt = (System.nanoTime() - t0) / 1000000;
+            queryDuration.addAndGet(dt);
             sessionContext.getStatisticManager()
-                    .logQueryEvaluationTime(language, statement, (System.nanoTime() - t)
/ 1000000);
+                    .logQueryEvaluationTime(language, statement, dt);
             return new QueryResultImpl(sessionContext, r);
         } catch (IllegalArgumentException e) {
             throw new InvalidQueryException(e);



Mime
View raw message