You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sirona.apache.org by rm...@apache.org on 2013/11/15 17:15:14 UTC

svn commit: r1542306 - in /incubator/sirona/trunk/core/src/main/java/org/apache/sirona/gauges/counter: ./ CounterGauge.java

Author: rmannibucau
Date: Fri Nov 15 16:15:14 2013
New Revision: 1542306

URL: http://svn.apache.org/r1542306
Log:
adding abstract CounterGauge to be able to write custom gauge on counters quickly

Added:
    incubator/sirona/trunk/core/src/main/java/org/apache/sirona/gauges/counter/
    incubator/sirona/trunk/core/src/main/java/org/apache/sirona/gauges/counter/CounterGauge.java

Added: incubator/sirona/trunk/core/src/main/java/org/apache/sirona/gauges/counter/CounterGauge.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/core/src/main/java/org/apache/sirona/gauges/counter/CounterGauge.java?rev=1542306&view=auto
==============================================================================
--- incubator/sirona/trunk/core/src/main/java/org/apache/sirona/gauges/counter/CounterGauge.java (added)
+++ incubator/sirona/trunk/core/src/main/java/org/apache/sirona/gauges/counter/CounterGauge.java Fri Nov 15 16:15:14 2013
@@ -0,0 +1,57 @@
+/*
+ * 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.sirona.gauges.counter;
+
+import org.apache.sirona.Role;
+import org.apache.sirona.configuration.Configuration;
+import org.apache.sirona.counters.Counter;
+import org.apache.sirona.gauges.Gauge;
+
+public abstract class CounterGauge implements Gauge {
+    private final Counter counter;
+    private final boolean reset;
+
+    protected CounterGauge(final Counter counter) {
+        this(counter, true);
+    }
+
+    protected CounterGauge(final Counter counter, final boolean reset) {
+        this.counter = counter;
+        this.reset = reset;
+    }
+
+    @Override
+    public Role role() {
+        return counter.getKey().getRole();
+    }
+
+    @Override
+    public double value() {
+        try {
+            return counter.getSum();
+        } finally {
+            if (reset) {
+                counter.reset();
+            }
+        }
+    }
+
+    @Override
+    public long period() {
+        return Configuration.getInteger(Configuration.CONFIG_PROPERTY_PREFIX + "gauge.counter.period", 4000);
+    }
+}