commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nico...@apache.org
Subject svn commit: r731976 - in /commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring: ./ metrics/
Date Tue, 06 Jan 2009 15:35:39 GMT
Author: nicolas
Date: Tue Jan  6 07:35:38 2009
New Revision: 731976

URL: http://svn.apache.org/viewvc?rev=731976&view=rev
Log:
use double instead of long to better support unit conversions (without data lost)

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/Gauge.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/ObservableMetric.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/RentrantLockCounter.java
    commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/metrics/RentrantLockGauge.java
    commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/metrics/SynchronizedCounter.java
    commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/metrics/SynchronizedGauge.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=731976&r1=731975&r2=731976&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
Tue Jan  6 07:35:38 2009
@@ -18,9 +18,9 @@
 package org.apache.commons.monitoring;
 
 /**
- * A counter to collect application processed items (bytes received, lines processed by a
batch,
- * time elapsed by some processing ...).
- *
+ * A counter to collect application processed items (bytes received, lines processed by a
batch, time elapsed by some
+ * processing ...).
+ * 
  * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
  */
 public interface Counter
@@ -29,13 +29,14 @@
 
     /**
      * Add value to the counter. Delta should not be negative (in such case a Gauge should
be used).
+     * 
      * @param delta
      */
-    void add( long delta, Unit unit );
+    void add( double delta, Unit unit );
 
-    public interface Observable extends Metric.Observable<Counter>, Counter
+    public interface Observable
+        extends Metric.Observable<Counter>, Counter
     {
 
     }
 }
-

Modified: commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/Gauge.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/Gauge.java?rev=731976&r1=731975&r2=731976&view=diff
==============================================================================
--- commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/Gauge.java
(original)
+++ commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/Gauge.java
Tue Jan  6 07:35:38 2009
@@ -22,20 +22,22 @@
  *
  * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
  */
-public interface Gauge extends Metric<Gauge>
+public interface Gauge
+    extends Metric<Gauge>
 {
     /**
      * @return the current Gauge value
      */
-    long getValue();
+    double getValue();
 
-    void increment(Unit unit);
+    void increment( Unit unit );
 
-    void set( long value, Unit unit );
+    void set( double value, Unit unit );
 
-    void decrement(Unit unit);
+    void decrement( Unit unit );
 
-    public interface Observable extends Metric.Observable<Gauge>, Gauge
+    public interface Observable
+        extends Metric.Observable<Gauge>, Gauge
     {
 
     }

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=731976&r1=731975&r2=731976&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
Tue Jan  6 07:35:38 2009
@@ -78,7 +78,7 @@
          * @param metric
          * @param value
          */
-        void onValueChanged( Observable<M> metric, long value );
+        void onValueChanged( Observable<M> metric, double 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=731976&r1=731975&r2=731976&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
Tue Jan  6 07:35:38 2009
@@ -56,7 +56,7 @@
         return statistics;
     }
 
-    protected long normalize( long value, Unit unit )
+    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=731976&r1=731975&r2=731976&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
Tue Jan  6 07:35:38 2009
@@ -24,7 +24,7 @@
         // NoOp
     }
 
-    public void add( long delta, Unit unit )
+    public void add( double delta, Unit unit )
     {
         // 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=731976&r1=731975&r2=731976&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
Tue Jan  6 07:35:38 2009
@@ -29,7 +29,7 @@
         // NoOp
     }
 
-    public long getValue()
+    public double getValue()
     {
         return 0;
     }
@@ -39,7 +39,7 @@
         // NoOp
     }
 
-    public void set( long value, Unit unit )
+    public void set( double value, Unit unit )
     {
         // NoOp
     }

Modified: commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/metrics/ObservableMetric.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/metrics/ObservableMetric.java?rev=731976&r1=731975&r2=731976&view=diff
==============================================================================
--- commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/metrics/ObservableMetric.java
(original)
+++ commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/metrics/ObservableMetric.java
Tue Jan  6 07:35:38 2009
@@ -40,12 +40,12 @@
         listeners.remove( listener );
     }
 
-    protected void fireValueChanged( long l )
+    protected void fireValueChanged( double d )
     {
         // Notify listeners
         for ( Listener<M> listener : listeners )
         {
-            listener.onValueChanged( this, l );
+            listener.onValueChanged( this, d );
         }
     }
 }

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=731976&r1=731975&r2=731976&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
Tue Jan  6 07:35:38 2009
@@ -38,12 +38,12 @@
         return observable;
     }
 
-    public void onValueChanged( Metric.Observable<Counter> metric, long value )
+    public void onValueChanged( Metric.Observable<Counter> metric, double value )
     {
         delegate.threadSafeAdd( value );
     }
 
-    public void add( long delta, Unit unit )
+    public void add( double delta, 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/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=731976&r1=731975&r2=731976&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
Tue Jan  6 07:35:38 2009
@@ -39,12 +39,12 @@
         return observable;
     }
 
-    public void onValueChanged( Metric.Observable<Gauge> metric, long value )
+    public void onValueChanged( Metric.Observable<Gauge> metric, double value )
     {
         delegate.threadSafeSet( value );
     }
 
-    public long getValue()
+    public double getValue()
     {
         return delegate.getValue();
     }
@@ -54,7 +54,7 @@
         throw new UnsupportedOperationException( "Observer cannot be updated directly" );
     }
 
-    public void set( long value, Unit unit )
+    public void set( double value, 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/RentrantLockCounter.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/metrics/RentrantLockCounter.java?rev=731976&r1=731975&r2=731976&view=diff
==============================================================================
--- commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/metrics/RentrantLockCounter.java
(original)
+++ commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/metrics/RentrantLockCounter.java
Tue Jan  6 07:35:38 2009
@@ -47,7 +47,7 @@
         super( role );
     }
 
-    protected void threadSafeAdd( long delta )
+    protected void threadSafeAdd( double delta )
     {
         lock.lock();
         try

Modified: commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/metrics/RentrantLockGauge.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/metrics/RentrantLockGauge.java?rev=731976&r1=731975&r2=731976&view=diff
==============================================================================
--- commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/metrics/RentrantLockGauge.java
(original)
+++ commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/metrics/RentrantLockGauge.java
Tue Jan  6 07:35:38 2009
@@ -50,12 +50,12 @@
         }
     }
 
-    protected void threadSafeSet( long l )
+    protected void threadSafeSet( double d )
     {
         lock.lock();
         try
         {
-            doThreadSafeSet( l );
+            doThreadSafeSet( d );
         }
         finally
         {

Modified: commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/metrics/SynchronizedCounter.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/metrics/SynchronizedCounter.java?rev=731976&r1=731975&r2=731976&view=diff
==============================================================================
--- commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/metrics/SynchronizedCounter.java
(original)
+++ commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/metrics/SynchronizedCounter.java
Tue Jan  6 07:35:38 2009
@@ -44,7 +44,7 @@
         super( role );
     }
 
-    protected synchronized void threadSafeAdd( long delta )
+    protected synchronized void threadSafeAdd( double delta )
     {
         doThreadSafeAdd( delta );
     }

Modified: commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/metrics/SynchronizedGauge.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/metrics/SynchronizedGauge.java?rev=731976&r1=731975&r2=731976&view=diff
==============================================================================
--- commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/metrics/SynchronizedGauge.java
(original)
+++ commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/metrics/SynchronizedGauge.java
Tue Jan  6 07:35:38 2009
@@ -53,8 +53,8 @@
         doReset();
     }
 
-    protected synchronized void threadSafeSet( long l )
+    protected synchronized void threadSafeSet( double d )
     {
-        doThreadSafeSet( l );
+        doThreadSafeSet( d );
     }
 }

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=731976&r1=731975&r2=731976&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
Tue Jan  6 07:35:38 2009
@@ -23,7 +23,7 @@
         return Type.COUNTER;
     }
 
-    public void add( long delta, Unit unit )
+    public void add( double delta, Unit unit )
     {
         delta = normalize( delta, unit );
         threadSafeAdd( delta );
@@ -35,9 +35,9 @@
      * expected to delegate computing to {@ #doThreadSafeAdd(long)}
      * @param delta
      */
-    protected abstract void threadSafeAdd( long delta );
+    protected abstract void threadSafeAdd( double delta );
 
-    protected void doThreadSafeAdd( long delta )
+    protected void doThreadSafeAdd( double delta )
     {
         getSummary().addValue( 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=731976&r1=731975&r2=731976&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
Tue Jan  6 07:35:38 2009
@@ -17,7 +17,7 @@
     extends ObservableMetric<Gauge>
     implements Gauge, Gauge.Observable
 {
-    protected long value;
+    protected double value;
 
     protected long lastUse;
 
@@ -32,7 +32,7 @@
         super( role );
     }
 
-    public long getValue()
+    public double getValue()
     {
         return value;
     }
@@ -47,14 +47,14 @@
         add( -1, unit );
     }
 
-    protected void add( long delta, Unit unit )
+    protected void add( double delta, Unit unit )
     {
         delta = normalize( delta, unit );
-        long l = threadSafeAdd( delta );
-        fireValueChanged( l );
+        double d = threadSafeAdd( delta );
+        fireValueChanged( d );
     }
 
-    protected long threadSafeAdd( long delta )
+    protected double threadSafeAdd( double delta )
     {
         threadSafeSet( value + delta );
         return value;
@@ -65,19 +65,19 @@
         return System.nanoTime();
     }
 
-    public long get()
+    public double get()
     {
         return value;
     }
 
-    public void set( long l, Unit unit )
+    public void set( double d, Unit unit )
     {
-        l = normalize( l, unit );
-        threadSafeSet( l );
-        fireValueChanged( l );
+        d = normalize( d, unit );
+        threadSafeSet( d );
+        fireValueChanged( d );
     }
 
-    protected abstract void threadSafeSet( long l );
+    protected abstract void threadSafeSet( double d );
 
     protected void doReset()
     {
@@ -87,9 +87,9 @@
         firstUse = Double.NaN;
     }
 
-    protected void doThreadSafeSet( long l )
+    protected void doThreadSafeSet( double d )
     {
-        value = l;
+        value = d;
         long now = nanotime();
         if ( Double.isNaN( firstUse ) )
         {
@@ -98,12 +98,12 @@
         else
         {
             long delta = now - lastUse;
-            long s = l * delta;
+            double s = d * delta;
             getSummary().addValue( s );
         }
         lastUse = now;
-        min.increment( l );
-        max.increment( l );
+        min.increment( d );
+        max.increment( d );
     }
 
     @Override



Mime
View raw message