You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ni...@apache.org on 2008/03/06 16:25:19 UTC

svn commit: r634300 - in /commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/reporting: AbstractRenderer.java HtmlRenderer.java JsonRenderer.java TxtRenderer.java XmlRenderer.java

Author: nicolas
Date: Thu Mar  6 07:25:17 2008
New Revision: 634300

URL: http://svn.apache.org/viewvc?rev=634300&view=rev
Log:
fix bad unit scaling for "hits"

Modified:
    commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/reporting/AbstractRenderer.java
    commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/reporting/HtmlRenderer.java
    commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/reporting/JsonRenderer.java
    commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/reporting/TxtRenderer.java
    commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/reporting/XmlRenderer.java

Modified: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/reporting/AbstractRenderer.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/reporting/AbstractRenderer.java?rev=634300&r1=634299&r2=634300&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/reporting/AbstractRenderer.java (original)
+++ commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/reporting/AbstractRenderer.java Thu Mar  6 07:25:17 2008
@@ -53,12 +53,12 @@
         {
             if ( options.render( monitor ) )
             {
-                if (count > 0)
+                if ( count > 0 )
                 {
                     hasNext( writer, Monitor.class );
                 }
                 render( writer, monitor, options );
-                count ++;
+                count++;
             }
         }
     }
@@ -83,7 +83,7 @@
         {
             StatValue value = (StatValue) iterator.next();
             render( writer, value, options );
-            if (iterator.hasNext())
+            if ( iterator.hasNext() )
             {
                 hasNext( writer, StatValue.class );
             }
@@ -97,7 +97,7 @@
         for ( Iterator<StatValue> iterator = values.iterator(); iterator.hasNext(); )
         {
             StatValue value = (StatValue) iterator.next();
-            if ( ! options.render( value ))
+            if ( !options.render( value ) )
             {
                 iterator.remove();
             }
@@ -108,7 +108,7 @@
             {
                 return value1.getRole().compareTo( value2.getRole() );
             }
-        });
+        } );
         return values;
     }
 
@@ -119,7 +119,7 @@
             Counter counter = (Counter) value;
             if ( options.render( value, "hits" ) )
             {
-                render( writer, value, "hits", counter.getHits(), options );
+                render( writer, value, "hits", counter.getHits(), options, 0 );
             }
             if ( options.render( value, "sum" ) )
             {
@@ -140,50 +140,73 @@
         }
         if ( options.render( value, "deviation" ) )
         {
-            render( writer, value, "deviation", value.getStandardDeviation(), options );
+            render( writer, value, "deviation", value.getStandardDeviation(), options, 1 );
         }
         if ( options.render( value, "value" ) )
         {
-            render( writer, value, "value", value.get(), options );
+            render( writer, value, "value", value.get(), options, 1 );
         }
     }
 
     protected abstract void render( PrintWriter writer, Key key );
 
-
     protected void render( PrintWriter writer, StatValue value, String attribute, Number number, Options options )
     {
+        render( writer, value, attribute, number, options, 1 );
+    }
+
+    /**
+     * Render a StatValue attribute
+     *
+     * @param writer output
+     * @param value the StatValue that hold data to be rendered
+     * @param attribute the StatValue attribute name to be rendered
+     * @param number the the StatValue attribute value to be rendered
+     * @param ratio the ratio between attribute unit and statValue unit (in power of 10)
+     * @param options the rendering options
+     */
+    protected void render( PrintWriter writer, StatValue value, String attribute, Number number, Options options,
+                           int ratio )
+    {
         if ( number instanceof Double )
         {
-            renderInternal( writer, value, attribute, number.doubleValue(), options );
+            renderInternal( writer, value, attribute, number.doubleValue(), options, ratio );
         }
         else
         {
-            renderInternal( writer, value, attribute, number.longValue(), options );
+            renderInternal( writer, value, attribute, number.longValue(), options, ratio );
         }
     }
 
-    private void renderInternal( PrintWriter writer, StatValue value, String attribute, long l, Options options )
+    private void renderInternal( PrintWriter writer, StatValue value, String attribute, long l, Options options,
+                                 int ratio )
     {
         Unit unit = options.unitFor( value );
-        if (unit != null)
+        if ( unit != null )
         {
-            l = l / unit.getScale();
+            while ( ratio-- > 0 )
+            {
+                l = l / unit.getScale();
+            }
         }
         writer.append( NumberFormat.getInstance( options.getLocale() ).format( l ) );
     }
 
-    private void renderInternal( PrintWriter writer, StatValue value, String attribute, double d, Options options )
+    private void renderInternal( PrintWriter writer, StatValue value, String attribute, double d, Options options,
+                                 int ratio )
     {
-        if (Double.isNaN( d ))
+        if ( Double.isNaN( d ) )
         {
             writer.append( "-" );
             return;
         }
         Unit unit = options.unitFor( value );
-        if (unit != null)
+        if ( unit != null )
         {
-            d = d / unit.getScale();
+            while ( ratio-- > 0 )
+            {
+                d = d / unit.getScale();
+            }
         }
         writer.append( DecimalFormat.getNumberInstance( options.getLocale() ).format( d ) );
     }

Modified: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/reporting/HtmlRenderer.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/reporting/HtmlRenderer.java?rev=634300&r1=634299&r2=634300&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/reporting/HtmlRenderer.java (original)
+++ commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/reporting/HtmlRenderer.java Thu Mar  6 07:25:17 2008
@@ -154,27 +154,14 @@
         writer.print( ")" );
     }
 
-    /**
-     * {@inheritDoc}
-     *
-     * @see org.apache.commons.monitoring.reporting.AbstractRenderer#render(java.io.PrintWriter,
-     * org.apache.commons.monitoring.StatValue, String, Number,
-     * org.apache.commons.monitoring.reporting.Renderer.Options)
-     */
     @Override
-    protected void render( PrintWriter writer, StatValue value, String attribute, Number number, Options options )
+    protected void render( PrintWriter writer, StatValue value, String attribute, Number number, Options options, int ratio )
     {
         writer.print( "<td>" );
-        super.render( writer, value, attribute, number, options );
+        super.render( writer, value, attribute, number, options, ratio );
         writer.print( "</td>" );
     }
 
-    /**
-     * {@inheritDoc}
-     *
-     * @see org.apache.commons.monitoring.reporting.AbstractRenderer#render(java.io.PrintWriter,
-     * org.apache.commons.monitoring.Monitor.Key)
-     */
     @Override
     protected void render( PrintWriter writer, Key key )
     {

Modified: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/reporting/JsonRenderer.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/reporting/JsonRenderer.java?rev=634300&r1=634299&r2=634300&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/reporting/JsonRenderer.java (original)
+++ commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/reporting/JsonRenderer.java Thu Mar  6 07:25:17 2008
@@ -81,26 +81,27 @@
         writer.print( "}" );
     }
 
+    /** Current rendering state */
     private StatValue currentValue;
-    private boolean first;
+    private boolean firstAttribute;
 
     @Override
-    protected void render( PrintWriter writer, StatValue value, String attribute, Number number, Options options )
+    protected void render( PrintWriter writer, StatValue value, String attribute, Number number, Options options, int ratio )
     {
         if (currentValue != value)
         {
             currentValue = value;
-            first = true;
+            firstAttribute = true;
         }
 
-        if (!first)
+        if (!firstAttribute)
         {
             writer.print( ',' );
         }
         writer.print( attribute );
         writer.print( ":\"" );
-        super.render( writer, value, attribute, number, options );
+        super.render( writer, value, attribute, number, options, ratio );
         writer.print( '\"' );
-        first = false;
+        firstAttribute = false;
     }
 }

Modified: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/reporting/TxtRenderer.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/reporting/TxtRenderer.java?rev=634300&r1=634299&r2=634300&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/reporting/TxtRenderer.java (original)
+++ commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/reporting/TxtRenderer.java Thu Mar  6 07:25:17 2008
@@ -45,12 +45,12 @@
     }
 
     @Override
-    protected void render( PrintWriter writer, StatValue value, String attribute, Number number, Options options )
+    protected void render( PrintWriter writer, StatValue value, String attribute, Number number, Options options, int ratio )
     {
         writer.print( "    " );
         writer.print( attribute );
         writer.print( " : " );
-        super.render( writer, value, attribute, number, options );
+        super.render( writer, value, attribute, number, options, ratio );
         writer.println();
     }
 

Modified: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/reporting/XmlRenderer.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/reporting/XmlRenderer.java?rev=634300&r1=634299&r2=634300&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/reporting/XmlRenderer.java (original)
+++ commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/reporting/XmlRenderer.java Thu Mar  6 07:25:17 2008
@@ -77,12 +77,12 @@
     }
 
     @Override
-    protected void render( PrintWriter writer, StatValue value, String attribute, Number number, Options options )
+    protected void render( PrintWriter writer, StatValue value, String attribute, Number number, Options options, int ratio )
     {
         writer.print( ' ' );
         writer.print( attribute );
         writer.print( "=\"" );
-        super.render( writer, value, attribute, number, options );
+        super.render( writer, value, attribute, number, options, ratio );
         writer.print( '\"' );
     }