commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nico...@apache.org
Subject svn commit: r740659 - in /commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring: ./ metrics/
Date Wed, 04 Feb 2009 09:04:43 GMT
Author: nicolas
Date: Wed Feb  4 09:04:42 2009
New Revision: 740659

URL: http://svn.apache.org/viewvc?rev=740659&view=rev
Log:
add(..) methods added to Metrics API
add( double ) created to avoid Unit conversion when not required

Modified:
    commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/Counter.java
    commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/Metric.java
    commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/metrics/AbstractMetric.java
    commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/metrics/NoOpCounter.java
    commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/metrics/NoOpGauge.java
    commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/metrics/ObserverCounter.java
    commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/metrics/ObserverGauge.java
    commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/metrics/ThreadSafeCounter.java
    commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/metrics/ThreadSafeGauge.java

Modified: commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/Counter.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/Counter.java?rev=740659&r1=740658&r2=740659&view=diff
==============================================================================
--- commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/Counter.java
(original)
+++ commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/Counter.java
Wed Feb  4 09:04:42 2009
@@ -27,13 +27,6 @@
     extends Metric
 {
 
-    /**
-     * Add value to the counter. Delta should not be negative (in such case a Gauge should
be used).
-     * 
-     * @param delta
-     */
-    void add( double delta, Unit unit );
-
     public interface Observable
         extends Metric.Observable, Counter
     {

Modified: commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/Metric.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/Metric.java?rev=740659&r1=740658&r2=740659&view=diff
==============================================================================
--- commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/Metric.java
(original)
+++ commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/Metric.java
Wed Feb  4 09:04:42 2009
@@ -19,11 +19,10 @@
 
 import java.util.EventListener;
 
-
 /**
- * A <code>Metric</code> is a numerical indicator of some monitored
- * application state with support for simple statistics.
- *
+ * A <code>Metric</code> is a numerical indicator of some monitored application
state with support for simple
+ * statistics.
+ * 
  * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
  */
 public interface Metric
@@ -41,12 +40,30 @@
     void reset();
 
     /**
+     * Add value to the metric. For Counters, the value is expected to be always positive.
+     * <p>
+     * The delta MUST use the metric unit ({@link #getUnit()})
+     * 
+     * @param delta value to be added
+     */
+    void add( double delta );
+
+    /**
+     * Add value to the metric with the specified Unit. For Counters, the value is expected
to be always positive.
+     * 
+     * @param delta value to be added
+     * @param unit the unit used for delta, MUST be compatible with the metric unit ({@link
#getUnit()})
+     */
+    void add( double delta, Unit unit );
+
+    /**
      * Set the monitor this Metric is attached to
-     *
+     * 
      * @param monitor
      * @throws IllegalStateException if the Metric is allready attached to a monitor
      */
-    void setMonitor( Monitor monitor ) throws IllegalStateException;
+    void setMonitor( Monitor monitor )
+        throws IllegalStateException;
 
     /**
      * @return the monitor this Metric is attached to
@@ -72,9 +89,9 @@
         /**
          * Value has changed on Metric.
          * <p>
-         * Note that the value parameter has not the same content depending
-         * on Metric variant: for a {@ Counter} it is the delta added to the counter
-         * for a {@ Gauge} it is the new value of the gauge after beeing updated.
+         * Note that the value parameter has not the same content depending on Metric variant:
for a @ Counter} it is
+         * the delta added to the counter for a @ Gauge} it is the new value of the gauge
after beeing updated.
+         * 
          * @param metric
          * @param value
          */

Modified: commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/metrics/AbstractMetric.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/metrics/AbstractMetric.java?rev=740659&r1=740658&r2=740659&view=diff
==============================================================================
--- commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/metrics/AbstractMetric.java
(original)
+++ commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/metrics/AbstractMetric.java
Wed Feb  4 09:04:42 2009
@@ -60,6 +60,17 @@
         return statistics;
     }
 
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.apache.commons.monitoring.Metric#add(double, org.apache.commons.monitoring.Unit)
+     */
+    public final void add( double delta, Unit unit )
+    {
+        delta = normalize( delta, unit );
+        add( delta );
+    }
+
     protected double normalize( double value, Unit unit )
     {
         if ( !this.unit.isCompatible( unit ) )

Modified: commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/metrics/NoOpCounter.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/metrics/NoOpCounter.java?rev=740659&r1=740658&r2=740659&view=diff
==============================================================================
--- commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/metrics/NoOpCounter.java
(original)
+++ commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/metrics/NoOpCounter.java
Wed Feb  4 09:04:42 2009
@@ -3,7 +3,6 @@
 import org.apache.commons.monitoring.Counter;
 import org.apache.commons.monitoring.Metric;
 import org.apache.commons.monitoring.Role;
-import org.apache.commons.monitoring.Unit;
 
 public class NoOpCounter
     extends AbstractMetric
@@ -24,7 +23,7 @@
         // NoOp
     }
 
-    public void add( double delta, Unit unit )
+    public void add( double delta )
     {
         // NoOp
     }

Modified: commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/metrics/NoOpGauge.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/metrics/NoOpGauge.java?rev=740659&r1=740658&r2=740659&view=diff
==============================================================================
--- commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/metrics/NoOpGauge.java
(original)
+++ commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/metrics/NoOpGauge.java
Wed Feb  4 09:04:42 2009
@@ -19,6 +19,11 @@
         return Metric.Type.GAUGE;
     }
 
+    public void add( double delta )
+    {
+        // NoOp
+    }
+
     public void reset()
     {
         // NoOp

Modified: commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/metrics/ObserverCounter.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/metrics/ObserverCounter.java?rev=740659&r1=740658&r2=740659&view=diff
==============================================================================
--- commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/metrics/ObserverCounter.java
(original)
+++ commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/metrics/ObserverCounter.java
Wed Feb  4 09:04:42 2009
@@ -3,7 +3,6 @@
 import org.apache.commons.math.stat.descriptive.SummaryStatistics;
 import org.apache.commons.monitoring.Counter;
 import org.apache.commons.monitoring.Metric;
-import org.apache.commons.monitoring.Unit;
 
 /**
  * A Counter that observe another Counter and computes stats until it gets detached
@@ -43,7 +42,7 @@
         delegate.threadSafeAdd( value );
     }
 
-    public void add( double delta, Unit unit )
+    public void add( double delta )
     {
         throw new UnsupportedOperationException( "Observer cannot be updated directly" );
     }

Modified: commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/metrics/ObserverGauge.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/metrics/ObserverGauge.java?rev=740659&r1=740658&r2=740659&view=diff
==============================================================================
--- commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/metrics/ObserverGauge.java
(original)
+++ commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/metrics/ObserverGauge.java
Wed Feb  4 09:04:42 2009
@@ -49,6 +49,11 @@
         return delegate.getValue();
     }
 
+    public void add( double delta )
+    {
+        throw new UnsupportedOperationException( "Observer cannot be updated directly" );
+    }
+
     public void increment( Unit unit )
     {
         throw new UnsupportedOperationException( "Observer cannot be updated directly" );

Modified: commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/metrics/ThreadSafeCounter.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/metrics/ThreadSafeCounter.java?rev=740659&r1=740658&r2=740659&view=diff
==============================================================================
--- commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/metrics/ThreadSafeCounter.java
(original)
+++ commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/metrics/ThreadSafeCounter.java
Wed Feb  4 09:04:42 2009
@@ -2,7 +2,6 @@
 
 import org.apache.commons.monitoring.Counter;
 import org.apache.commons.monitoring.Role;
-import org.apache.commons.monitoring.Unit;
 
 public abstract class ThreadSafeCounter
     extends ObservableMetric
@@ -23,9 +22,8 @@
         return Type.COUNTER;
     }
 
-    public void add( double delta, Unit unit )
+    public void add( double delta )
     {
-        delta = normalize( delta, unit );
         threadSafeAdd( delta );
         fireValueChanged( delta );
     }

Modified: commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/metrics/ThreadSafeGauge.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/metrics/ThreadSafeGauge.java?rev=740659&r1=740658&r2=740659&view=diff
==============================================================================
--- commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/metrics/ThreadSafeGauge.java
(original)
+++ commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/metrics/ThreadSafeGauge.java
Wed Feb  4 09:04:42 2009
@@ -47,9 +47,8 @@
         add( -1, unit );
     }
 
-    protected void add( double delta, Unit unit )
+    public void add( double delta )
     {
-        delta = normalize( delta, unit );
         double d = threadSafeAdd( delta );
         fireValueChanged( d );
     }
@@ -77,6 +76,11 @@
         fireValueChanged( d );
     }
 
+    /**
+     * Set the Gauge value in a thread-safe way
+     * 
+     * @param d value to set
+     */
     protected abstract void threadSafeSet( double d );
 
     protected void doReset()



Mime
View raw message