jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r1299655 - in /jackrabbit/trunk: jackrabbit-api/src/main/java/org/apache/jackrabbit/api/stats/ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/ jackrabbit-core/src/test/java/org/apache/jackrabbit/core/stats/
Date Mon, 12 Mar 2012 12:54:59 GMT
Author: mreutegg
Date: Mon Mar 12 12:54:59 2012
New Revision: 1299655

URL: http://svn.apache.org/viewvc?rev=1299655&view=rev
Log:
JCR-3243: RepositoryStatistics should be more flexible

Added:
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/stats/RepositoryStatisticsImplTest.java
  (with props)
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/stats/TestAll.java
  (with props)
Modified:
    jackrabbit/trunk/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/stats/RepositoryStatistics.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/RepositoryStatisticsImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/TimeSeriesRecorder.java

Modified: jackrabbit/trunk/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/stats/RepositoryStatistics.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/stats/RepositoryStatistics.java?rev=1299655&r1=1299654&r2=1299655&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/stats/RepositoryStatistics.java
(original)
+++ jackrabbit/trunk/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/stats/RepositoryStatistics.java
Mon Mar 12 12:54:59 2012
@@ -53,10 +53,20 @@ public interface RepositoryStatistics {
             this.resetValueEachSecond = resetValueEachSecond;
         }
 
+        public static Type getType(String type) {
+            Type realType = null;
+            try {
+                realType = Type.valueOf(type);
+            } catch (IllegalArgumentException ignore) {};
+            return realType;
+        }
+
         public boolean isResetValueEachSecond() {
             return resetValueEachSecond;
         }
     }
 
     TimeSeries getTimeSeries(Type type);
+
+    TimeSeries getTimeSeries(String type, boolean resetValueEachSecond);
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/RepositoryStatisticsImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/RepositoryStatisticsImpl.java?rev=1299655&r1=1299654&r2=1299655&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/RepositoryStatisticsImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/RepositoryStatisticsImpl.java
Mon Mar 12 12:54:59 2012
@@ -26,17 +26,16 @@ import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicLong;
 
 import org.apache.jackrabbit.api.stats.RepositoryStatistics;
-import org.apache.jackrabbit.api.stats.RepositoryStatistics.Type;
 import org.apache.jackrabbit.api.stats.TimeSeries;
 
 public class RepositoryStatisticsImpl implements
-        Iterable<Map.Entry<Type, TimeSeries>>, RepositoryStatistics {
+        Iterable<Map.Entry<String, TimeSeries>>, RepositoryStatistics {
 
-    private final Map<Type, TimeSeriesRecorder> recorders =
-            new HashMap<Type, TimeSeriesRecorder>();
+    private final Map<String, TimeSeriesRecorder> recorders =
+            new HashMap<String, TimeSeriesRecorder>();
 
-    private final Map<Type, TimeSeriesAverage> avg =
-            new HashMap<Type, TimeSeriesAverage>();
+    private final Map<String, TimeSeriesAverage> avg =
+            new HashMap<String, TimeSeriesAverage>();
 
     public RepositoryStatisticsImpl() {
         getOrCreateRecorder(Type.SESSION_COUNT);
@@ -55,7 +54,7 @@ public class RepositoryStatisticsImpl im
     }
 
     private void createAvg(Type count, Type duration, Type avgTs) {
-        avg.put(avgTs, new TimeSeriesAverage(getOrCreateRecorder(duration),
+        avg.put(avgTs.name(), new TimeSeriesAverage(getOrCreateRecorder(duration),
                 getOrCreateRecorder(count)));
     }
 
@@ -68,8 +67,8 @@ public class RepositoryStatisticsImpl im
         }, 1, 1, TimeUnit.SECONDS);
     }
 
-    public synchronized Iterator<Entry<Type, TimeSeries>> iterator() {
-        Map<Type, TimeSeries> map = new TreeMap<Type, TimeSeries>();
+    public synchronized Iterator<Entry<String, TimeSeries>> iterator() {
+        Map<String, TimeSeries> map = new TreeMap<String, TimeSeries>();
         map.putAll(recorders);
         map.putAll(avg);
         return map.entrySet().iterator();
@@ -79,18 +78,29 @@ public class RepositoryStatisticsImpl im
         return getOrCreateRecorder(type).getCounter();
     }
 
+    public AtomicLong getCounter(String type, boolean resetValueEachSecond) {
+        return getOrCreateRecorder(type, resetValueEachSecond).getCounter();
+    }
+
     public TimeSeries getTimeSeries(Type type) {
+        return getTimeSeries(type.name(), type.isResetValueEachSecond());
+    }
+
+    public TimeSeries getTimeSeries(String type, boolean resetValueEachSecond) {
         if (avg.containsKey(type)) {
             return avg.get(type);
-        } else {
-            return getOrCreateRecorder(type);
         }
+        return getOrCreateRecorder(type, resetValueEachSecond);
     }
 
     private synchronized TimeSeriesRecorder getOrCreateRecorder(Type type) {
+        return getOrCreateRecorder(type.name(), type.isResetValueEachSecond());
+    }
+
+    private synchronized TimeSeriesRecorder getOrCreateRecorder(String type, boolean resetValueEachSecond)
{
         TimeSeriesRecorder recorder = recorders.get(type);
         if (recorder == null) {
-            recorder = new TimeSeriesRecorder(type);
+            recorder = new TimeSeriesRecorder(resetValueEachSecond);
             recorders.put(type, recorder);
         }
         return recorder;
@@ -101,5 +111,4 @@ public class RepositoryStatisticsImpl im
             recorder.recordOneSecond();
         }
     }
-
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/TimeSeriesRecorder.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/TimeSeriesRecorder.java?rev=1299655&r1=1299654&r2=1299655&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/TimeSeriesRecorder.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/TimeSeriesRecorder.java
Mon Mar 12 12:54:59 2012
@@ -29,12 +29,12 @@ import org.apache.jackrabbit.api.stats.R
  */
 class TimeSeriesRecorder implements TimeSeries {
 
-    /** Type */
-    private final Type type;
-    
     /** Value */
     private final AtomicLong counter = new AtomicLong();
 
+    /** Whether to reset value each second */
+    private final boolean resetValueEachSecond;
+
     /** Measured value per second over the last minute. */
     private final long[] valuePerSecond = new long[60];
 
@@ -60,7 +60,11 @@ class TimeSeriesRecorder implements Time
     private int weeks = 0;
 
     public TimeSeriesRecorder(Type type) {
-        this.type = type;
+        this(type.isResetValueEachSecond());
+    }
+
+    public TimeSeriesRecorder(boolean resetValueEachSecond) {
+        this.resetValueEachSecond = resetValueEachSecond;
     }
 
     /**
@@ -79,7 +83,7 @@ class TimeSeriesRecorder implements Time
      * second.
      */
     public synchronized void recordOneSecond() {
-        if (type.isResetValueEachSecond()) {
+        if (resetValueEachSecond) {
             valuePerSecond[seconds++] = counter.getAndSet(0);
         } else {
             valuePerSecond[seconds++] = counter.get();
@@ -133,7 +137,7 @@ class TimeSeriesRecorder implements Time
 
             sum += array[i];
         }
-        if (type.isResetValueEachSecond()) {
+        if (resetValueEachSecond) {
             return sum;
         }
         return sum / array.length;
@@ -154,5 +158,4 @@ class TimeSeriesRecorder implements Time
         }
         return reverse;
     }
-
 }

Added: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/stats/RepositoryStatisticsImplTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/stats/RepositoryStatisticsImplTest.java?rev=1299655&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/stats/RepositoryStatisticsImplTest.java
(added)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/stats/RepositoryStatisticsImplTest.java
Mon Mar 12 12:54:59 2012
@@ -0,0 +1,60 @@
+/*
+ * 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.
+ */
+package org.apache.jackrabbit.core.stats;
+
+import java.util.Iterator;
+import java.util.Map.Entry;
+
+import junit.framework.TestCase;
+
+import org.apache.jackrabbit.api.stats.TimeSeries;
+
+public class RepositoryStatisticsImplTest extends TestCase {
+
+    private static final int DEFAULT_NUMBER_OF_ELEMENTS = 17;
+
+    public void testDefaultIterator() {
+        RepositoryStatisticsImpl repositoryStatistics = new RepositoryStatisticsImpl();
+
+        Iterator<Entry<String, TimeSeries>> iterator = repositoryStatistics.iterator();
+        int count = 0;
+        while (iterator.hasNext()) {
+            count++;
+            iterator.next();
+        }
+        assertEquals(DEFAULT_NUMBER_OF_ELEMENTS, count);
+    }
+
+    public void testIteratorWithSingleCustomType() {
+        RepositoryStatisticsImpl repositoryStatistics = new RepositoryStatisticsImpl();
+        String type = "customType";
+        repositoryStatistics.getCounter(type, false);
+
+        Iterator<Entry<String, TimeSeries>> iterator = repositoryStatistics.iterator();
+        int count = 0;
+        boolean customTypeExists = false;
+        while (iterator.hasNext()) {
+            count++;
+            Entry<String, TimeSeries> entry = iterator.next();
+            if (type.equals(entry.getKey())) {
+                customTypeExists = true;
+            }
+        }
+        assertEquals(DEFAULT_NUMBER_OF_ELEMENTS + 1, count);
+        assertTrue(customTypeExists);
+    }
+}

Propchange: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/stats/RepositoryStatisticsImplTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/stats/RepositoryStatisticsImplTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/stats/TestAll.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/stats/TestAll.java?rev=1299655&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/stats/TestAll.java
(added)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/stats/TestAll.java
Mon Mar 12 12:54:59 2012
@@ -0,0 +1,43 @@
+/*
+ * 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.
+ */
+package org.apache.jackrabbit.core.stats;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * Test suite that includes all test cases for the stats module.
+ */
+public class TestAll extends TestCase {
+
+    /**
+     * Returns a <code>Test</code> suite that executes all tests inside this
+     * package.
+     *
+     * @return a <code>Test</code> suite that executes all tests inside this
+     *         package.
+     */
+    public static Test suite() {
+        TestSuite suite = new TestSuite("Stats tests");
+
+        suite.addTestSuite(RepositoryStatisticsImplTest.class);
+        suite.addTestSuite(TimeSeriesRecorderTest.class);
+
+        return suite;
+    }
+}

Propchange: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/stats/TestAll.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/stats/TestAll.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL



Mime
View raw message