Index: jackrabbit-api/src/main/java/org/apache/jackrabbit/api/stats/RepositoryStatistics.java =================================================================== --- jackrabbit-api/src/main/java/org/apache/jackrabbit/api/stats/RepositoryStatistics.java (revision 1291877) +++ jackrabbit-api/src/main/java/org/apache/jackrabbit/api/stats/RepositoryStatistics.java (working copy) @@ -59,4 +59,6 @@ } TimeSeries getTimeSeries(Type type); + + TimeSeries getTimeSeries(String type, boolean resetValueEachSecond); } Index: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/RepositoryStatisticsImpl.java =================================================================== --- jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/RepositoryStatisticsImpl.java (revision 1291877) +++ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/RepositoryStatisticsImpl.java (working copy) @@ -32,11 +32,11 @@ public class RepositoryStatisticsImpl implements Iterable>, RepositoryStatistics { - private final Map recorders = - new HashMap(); + private final Map recorders = + new HashMap(); - private final Map avg = - new HashMap(); + private final Map avg = + new HashMap(); public RepositoryStatisticsImpl() { getOrCreateRecorder(Type.SESSION_COUNT); @@ -55,7 +55,7 @@ } 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))); } @@ -70,27 +70,55 @@ public synchronized Iterator> iterator() { Map map = new TreeMap(); - map.putAll(recorders); - map.putAll(avg); + addTypes(map, recorders); + addTypes(map, avg); return map.entrySet().iterator(); } + private void addTypes(Map mapToAdd, Map map) { + for (Entry entry : map.entrySet()) { + Type type = getType(entry.getKey()); + if (type != null) { + mapToAdd.put(type, entry.getValue()); + } + } + } + + private Type getType(String type) { + Type realType = null; + try { + realType = Type.valueOf(type); + } catch (IllegalArgumentException ignore) {}; + return realType; + } + public AtomicLong getCounter(Type type) { 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 +129,4 @@ recorder.recordOneSecond(); } } - } Index: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/TimeSeriesRecorder.java =================================================================== --- jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/TimeSeriesRecorder.java (revision 1291877) +++ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/TimeSeriesRecorder.java (working copy) @@ -29,12 +29,12 @@ */ 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 @@ 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 @@ * second. */ public synchronized void recordOneSecond() { - if (type.isResetValueEachSecond()) { + if (resetValueEachSecond) { valuePerSecond[seconds++] = counter.getAndSet(0); } else { valuePerSecond[seconds++] = counter.get(); @@ -133,7 +137,7 @@ sum += array[i]; } - if (type.isResetValueEachSecond()) { + if (resetValueEachSecond) { return sum; } return sum / array.length; @@ -154,5 +158,4 @@ } return reverse; } - }