jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1180887 - in /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core: jmx/TimeSeriesMBean.java jmx/TimeSeriesRecorder.java stats/ stats/RepositoryStatistics.java stats/TimeSeries.java stats/TimeSeriesRecorder.java
Date Mon, 10 Oct 2011 11:49:34 GMT
Author: jukka
Date: Mon Oct 10 11:49:33 2011
New Revision: 1180887

URL: http://svn.apache.org/viewvc?rev=1180887&view=rev
Log:
JCR-3040: JMX Stats for the Session

Separate the time series collection from JMX support

Added:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/RepositoryStatistics.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/TimeSeries.java
      - copied, changed from r1180845, jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/TimeSeriesMBean.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/TimeSeriesRecorder.java
      - copied, changed from r1180845, jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/TimeSeriesRecorder.java
Removed:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/TimeSeriesMBean.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/TimeSeriesRecorder.java

Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/RepositoryStatistics.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/RepositoryStatistics.java?rev=1180887&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/RepositoryStatistics.java
(added)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/RepositoryStatistics.java
Mon Oct 10 11:49:33 2011
@@ -0,0 +1,61 @@
+/*
+ * 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.HashMap;
+import java.util.Map;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicLong;
+
+public class RepositoryStatistics {
+
+    private final Map<String, TimeSeriesRecorder> recorders =
+            new HashMap<String, TimeSeriesRecorder>();
+
+    public RepositoryStatistics(ScheduledExecutorService executor) {
+        executor.scheduleAtFixedRate(new Runnable() {
+            public void run() {
+                recordOneSecond();
+            }
+        }, 1, 1, TimeUnit.SECONDS);
+    }
+
+    public AtomicLong getCounter(String name) {
+        return getOrCreateRecorder(name).getCounter();
+    }
+
+    public TimeSeries getTimeSeries(String name) {
+        return getOrCreateRecorder(name);
+    }
+
+    private synchronized TimeSeriesRecorder getOrCreateRecorder(String name) {
+        TimeSeriesRecorder recorder = recorders.get(name);
+        if (recorder == null) {
+            recorder = new TimeSeriesRecorder();
+            recorders.put(name, recorder);
+        }
+        return recorder;
+    }
+
+    private synchronized void recordOneSecond() {
+        for (TimeSeriesRecorder recorder : recorders.values()) {
+            recorder.recordOneSecond();
+        }
+    }
+
+}

Copied: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/TimeSeries.java
(from r1180845, jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/TimeSeriesMBean.java)
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/TimeSeries.java?p2=jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/TimeSeries.java&p1=jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/TimeSeriesMBean.java&r1=1180845&r2=1180887&rev=1180887&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/TimeSeriesMBean.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/TimeSeries.java
Mon Oct 10 11:49:33 2011
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.jackrabbit.core.jmx;
+package org.apache.jackrabbit.core.stats;
 
 /**
  * Interface for a time series of the number of events per
@@ -24,7 +24,7 @@ package org.apache.jackrabbit.core.jmx;
  *
  * @since Apache Jackrabbit 2.3.1
  */
-public interface TimeSeriesMBean {
+public interface TimeSeries {
 
     /**
      * Returns the number of events per second over the last minute.

Copied: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/TimeSeriesRecorder.java
(from r1180845, jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/TimeSeriesRecorder.java)
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/TimeSeriesRecorder.java?p2=jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/TimeSeriesRecorder.java&p1=jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/TimeSeriesRecorder.java&r1=1180845&r2=1180887&rev=1180887&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/TimeSeriesRecorder.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/TimeSeriesRecorder.java
Mon Oct 10 11:49:33 2011
@@ -14,19 +14,20 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.jackrabbit.core.jmx;
+package org.apache.jackrabbit.core.stats;
 
-import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicLong;
 
 /**
  * Recorder of a time series. An instance of this class records (and clears)
  * the state of a given {@link AtomicLong} counter once every second and
- * exposes the collected time series through the {@link TimeSeriesMBean}
+ * exposes the collected time series through the {@link TimeSeries}
  * interface.
  */
-public class TimeSeriesRecorder implements TimeSeriesMBean {
+class TimeSeriesRecorder implements TimeSeries {
+
+    /** Event counter */
+    private final AtomicLong counter = new AtomicLong();
 
     /** Number of events per second over the last minute. */
     private final long[] eventsPerSecond = new long[60];
@@ -52,28 +53,38 @@ public class TimeSeriesRecorder implemen
     /** Current week (index in {@link #eventsPerWeek}) */
     private int weeks = 0;
 
-    public TimeSeriesRecorder(
-            final AtomicLong counter, ScheduledExecutorService executor) {
-        executor.scheduleAtFixedRate(new Runnable() {
-            public void run() {
-                eventsPerSecond[seconds++] = counter.getAndSet(0);
-                if (seconds == eventsPerSecond.length) {
-                    seconds = 0;
-                    eventsPerMinute[minutes++] = sum(eventsPerSecond);
-                }
-                if (minutes == eventsPerMinute.length) {
-                    minutes = 0;
-                    eventsPerHour[hours++] = sum(eventsPerMinute);
-                }
-                if (hours == eventsPerHour.length) {
-                    hours = 0;
-                    eventsPerWeek[weeks++] = sum(eventsPerHour);
-                }
-                if (weeks == eventsPerWeek.length) {
-                    weeks = 0;
-                }
-            }
-        }, 1, 1, TimeUnit.SECONDS);
+    /**
+     * Returns the {@link AtomicLong} instance used to count events for
+     * the time series.
+     *
+     * @return event counter
+     */
+    public AtomicLong getCounter() {
+        return counter;
+    }
+
+    /**
+     * Records the number of counted events over the past second and resets
+     * the counter. This method should be scheduled to be called once per
+     * second.
+     */
+    public synchronized void recordOneSecond() {
+        eventsPerSecond[seconds++] = counter.getAndSet(0);
+        if (seconds == eventsPerSecond.length) {
+            seconds = 0;
+            eventsPerMinute[minutes++] = sum(eventsPerSecond);
+        }
+        if (minutes == eventsPerMinute.length) {
+            minutes = 0;
+            eventsPerHour[hours++] = sum(eventsPerMinute);
+        }
+        if (hours == eventsPerHour.length) {
+            hours = 0;
+            eventsPerWeek[weeks++] = sum(eventsPerHour);
+        }
+        if (weeks == eventsPerWeek.length) {
+            weeks = 0;
+        }
     }
 
     //----------------------------------------------------------< TimeSeries >



Mime
View raw message