commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nico...@apache.org
Subject svn commit: r782967 - in /commons/sandbox/monitoring/branches/modules: core/src/main/java/org/apache/commons/monitoring/ core/src/main/java/org/apache/commons/monitoring/metrics/ core/src/main/java/org/apache/commons/monitoring/monitors/ core/src/main/...
Date Tue, 09 Jun 2009 11:56:12 GMT
Author: nicolas
Date: Tue Jun  9 11:56:12 2009
New Revision: 782967

URL: http://svn.apache.org/viewvc?rev=782967&view=rev
Log:
visitor pattern to support data export

Added:
    commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/Visitable.java
    commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/Visitor.java
    commons/sandbox/monitoring/branches/modules/reporting/src/main/java/org/apache/commons/monitoring/reporting/AbstractFilteredVisitor.java
    commons/sandbox/monitoring/branches/modules/reporting/src/main/java/org/apache/commons/monitoring/reporting/JsonRenderer.java
    commons/sandbox/monitoring/branches/modules/reporting/src/main/java/org/apache/commons/monitoring/reporting/VisitorConfiguration.java
    commons/sandbox/monitoring/branches/modules/reporting/src/main/java/org/apache/commons/monitoring/reporting/VisitorConfigurationSupport.java
    commons/sandbox/monitoring/branches/modules/reporting/src/main/java/org/apache/commons/monitoring/reporting/XmlRenderer.java
    commons/sandbox/monitoring/branches/modules/reporting/src/test/java/org/apache/commons/monitoring/reporting/RendererTest.java
    commons/sandbox/monitoring/branches/modules/reporting/src/test/resources/org/
    commons/sandbox/monitoring/branches/modules/reporting/src/test/resources/org/apache/
    commons/sandbox/monitoring/branches/modules/reporting/src/test/resources/org/apache/commons/
    commons/sandbox/monitoring/branches/modules/reporting/src/test/resources/org/apache/commons/monitoring/
    commons/sandbox/monitoring/branches/modules/reporting/src/test/resources/org/apache/commons/monitoring/reporting/
    commons/sandbox/monitoring/branches/modules/reporting/src/test/resources/org/apache/commons/monitoring/reporting/RendererTest.xml
Modified:
    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/Monitor.java
    commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/Repository.java
    commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/Unit.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/monitors/AbstractMonitor.java
    commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/monitors/NullMonitor.java
    commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/repositories/AbstractRepository.java
    commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/repositories/RepositoryDecorator.java
    commons/sandbox/monitoring/branches/modules/reporting/pom.xml

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=782967&r1=782966&r2=782967&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 Jun  9 11:56:12 2009
@@ -26,6 +26,7 @@
  * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
  */
 public interface Metric
+    extends Visitable
 {
     public enum Type
     {

Modified: commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/Monitor.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/Monitor.java?rev=782967&r1=782966&r2=782967&view=diff
==============================================================================
--- commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/Monitor.java
(original)
+++ commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/Monitor.java
Tue Jun  9 11:56:12 2009
@@ -48,6 +48,7 @@
  * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
  */
 public interface Monitor
+    extends Visitable
 {
     // --- Predefined roles -------------------------------------------------------------------
 

Modified: commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/Repository.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/Repository.java?rev=782967&r1=782966&r2=782967&view=diff
==============================================================================
--- commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/Repository.java
(original)
+++ commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/Repository.java
Tue Jun  9 11:56:12 2009
@@ -21,8 +21,6 @@
 import java.util.EventListener;
 import java.util.Set;
 
-import org.apache.commons.monitoring.Monitor.Key;
-
 /**
  * The repository maintains a set of monitors and ensure unicity. It creates monitors on-demand
  * based on requested Keys. After creation, the monitor Key cannot be updated.
@@ -30,6 +28,7 @@
  * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
  */
 public interface Repository
+    extends Visitable
 {
     /**
      * Retrieve or create a monitor it's key

Modified: commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/Unit.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/Unit.java?rev=782967&r1=782966&r2=782967&view=diff
==============================================================================
--- commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/Unit.java
(original)
+++ commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/Unit.java
Tue Jun  9 11:56:12 2009
@@ -187,6 +187,10 @@
      */
     public double convert( double value, Unit unit )
     {
+        if ( unit == this )
+        {
+            return value;
+        }
         return value * unit.getScale() / this.getScale();
     }
 

Added: commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/Visitable.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/Visitable.java?rev=782967&view=auto
==============================================================================
--- commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/Visitable.java
(added)
+++ commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/Visitable.java
Tue Jun  9 11:56:12 2009
@@ -0,0 +1,26 @@
+/*
+ * 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.commons.monitoring;
+
+/**
+ * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
+ */
+public interface Visitable
+{
+    void accept( Visitor visitor );
+}

Added: commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/Visitor.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/Visitor.java?rev=782967&view=auto
==============================================================================
--- commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/Visitor.java
(added)
+++ commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/Visitor.java
Tue Jun  9 11:56:12 2009
@@ -0,0 +1,32 @@
+/*
+ * 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.commons.monitoring;
+
+/**
+ * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
+ */
+public interface Visitor
+{
+    void visit( Repository repository );
+
+    void visit( Monitor monitor );
+
+    void visit( Gauge gauge );
+
+    void visit( Counter counter );
+}

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=782967&r1=782966&r2=782967&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 Jun  9 11:56:12 2009
@@ -18,10 +18,13 @@
 package org.apache.commons.monitoring.metrics;
 
 import org.apache.commons.math.stat.descriptive.SummaryStatistics;
+import org.apache.commons.monitoring.Counter;
+import org.apache.commons.monitoring.Gauge;
 import org.apache.commons.monitoring.Metric;
 import org.apache.commons.monitoring.Monitor;
 import org.apache.commons.monitoring.Role;
 import org.apache.commons.monitoring.Unit;
+import org.apache.commons.monitoring.Visitor;
 
 /**
  * A simple implementation of {@link Metric}. Only provide methods to compute stats from
aggregated data provided by
@@ -193,4 +196,19 @@
     {
         return getSummary().getSumsq();
     }
+
+    public void accept( Visitor visitor )
+    {
+        switch ( getType() )
+        {
+            case COUNTER:
+                visitor.visit( (Counter) this );
+                break;
+            case GAUGE:
+            default:
+                visitor.visit( (Gauge) this );
+                break;
+        }
+    }
+
 }

Modified: commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/monitors/AbstractMonitor.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/monitors/AbstractMonitor.java?rev=782967&r1=782966&r2=782967&view=diff
==============================================================================
--- commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/monitors/AbstractMonitor.java
(original)
+++ commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/monitors/AbstractMonitor.java
Tue Jun  9 11:56:12 2009
@@ -27,6 +27,7 @@
 import org.apache.commons.monitoring.Metric;
 import org.apache.commons.monitoring.Monitor;
 import org.apache.commons.monitoring.Role;
+import org.apache.commons.monitoring.Visitor;
 
 /**
  * Abstract {@link Monitor} with implementation for base methods
@@ -138,4 +139,8 @@
         return (Gauge) getMetric( role );
     }
 
+    public void accept( Visitor visitor )
+    {
+        visitor.visit( this );
+    }
 }
\ No newline at end of file

Modified: commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/monitors/NullMonitor.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/monitors/NullMonitor.java?rev=782967&r1=782966&r2=782967&view=diff
==============================================================================
--- commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/monitors/NullMonitor.java
(original)
+++ commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/monitors/NullMonitor.java
Tue Jun  9 11:56:12 2009
@@ -9,6 +9,7 @@
 import org.apache.commons.monitoring.Monitor;
 import org.apache.commons.monitoring.Role;
 import org.apache.commons.monitoring.Unit;
+import org.apache.commons.monitoring.Visitor;
 import org.apache.commons.monitoring.metrics.NoOpCounter;
 import org.apache.commons.monitoring.metrics.NoOpGauge;
 
@@ -104,4 +105,9 @@
             return true;
         }
     }
+
+    public void accept( Visitor visitor )
+    {
+        // NoOp
+    }
 }

Modified: commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/repositories/AbstractRepository.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/repositories/AbstractRepository.java?rev=782967&r1=782966&r2=782967&view=diff
==============================================================================
--- commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/repositories/AbstractRepository.java
(original)
+++ commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/repositories/AbstractRepository.java
Tue Jun  9 11:56:12 2009
@@ -27,6 +27,7 @@
 
 import org.apache.commons.monitoring.Monitor;
 import org.apache.commons.monitoring.Repository;
+import org.apache.commons.monitoring.Visitor;
 import org.apache.commons.monitoring.Monitor.Key;
 
 /**
@@ -175,4 +176,9 @@
         }
     }
 
+    public void accept( Visitor visitor )
+    {
+        visitor.visit( this );
+    }
+
 }
\ No newline at end of file

Modified: commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/repositories/RepositoryDecorator.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/repositories/RepositoryDecorator.java?rev=782967&r1=782966&r2=782967&view=diff
==============================================================================
--- commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/repositories/RepositoryDecorator.java
(original)
+++ commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/repositories/RepositoryDecorator.java
Tue Jun  9 11:56:12 2009
@@ -23,6 +23,7 @@
 import org.apache.commons.monitoring.Monitor;
 import org.apache.commons.monitoring.Repository;
 import org.apache.commons.monitoring.StopWatch;
+import org.apache.commons.monitoring.Visitor;
 import org.apache.commons.monitoring.Monitor.Key;
 
 /**
@@ -105,6 +106,11 @@
         return decorated;
     }
 
+    public void accept( Visitor visitor )
+    {
+        decorated.accept( visitor );
+    }
+
     // --- Repository.Observable ---
 
     public void addListener( Listener listener )

Modified: commons/sandbox/monitoring/branches/modules/reporting/pom.xml
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/branches/modules/reporting/pom.xml?rev=782967&r1=782966&r2=782967&view=diff
==============================================================================
--- commons/sandbox/monitoring/branches/modules/reporting/pom.xml (original)
+++ commons/sandbox/monitoring/branches/modules/reporting/pom.xml Tue Jun  9 11:56:12 2009
@@ -19,5 +19,10 @@
       <version>4.5</version>
       <scope>test</scope>
     </dependency>
+    <dependency>
+    	<groupId>xmlunit</groupId>
+    	<artifactId>xmlunit</artifactId>
+    	<version>1.2</version>
+    </dependency>
   </dependencies>
 </project>
\ No newline at end of file

Added: commons/sandbox/monitoring/branches/modules/reporting/src/main/java/org/apache/commons/monitoring/reporting/AbstractFilteredVisitor.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/branches/modules/reporting/src/main/java/org/apache/commons/monitoring/reporting/AbstractFilteredVisitor.java?rev=782967&view=auto
==============================================================================
--- commons/sandbox/monitoring/branches/modules/reporting/src/main/java/org/apache/commons/monitoring/reporting/AbstractFilteredVisitor.java
(added)
+++ commons/sandbox/monitoring/branches/modules/reporting/src/main/java/org/apache/commons/monitoring/reporting/AbstractFilteredVisitor.java
Tue Jun  9 11:56:12 2009
@@ -0,0 +1,84 @@
+/*
+ * 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.commons.monitoring.reporting;
+
+import java.io.PrintWriter;
+
+import org.apache.commons.monitoring.Metric;
+import org.apache.commons.monitoring.Monitor;
+import org.apache.commons.monitoring.Repository;
+import org.apache.commons.monitoring.Visitor;
+
+/**
+ * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
+ */
+public abstract class AbstractFilteredVisitor
+    implements Visitor
+{
+    protected VisitorConfiguration configuration;
+
+    protected PrintWriter writer;
+
+    public AbstractFilteredVisitor( VisitorConfiguration configuration, PrintWriter writer
)
+    {
+        super();
+        this.configuration = configuration;
+        this.writer = writer;
+    }
+
+    public void visit( Repository repository )
+    {
+        boolean first = true;
+        for ( Monitor monitor : repository.getMonitors() )
+        {
+            if ( configuration.filter( monitor.getKey() ) )
+            {
+                if ( !first )
+                {
+                    next();
+                    first = false;
+                }
+                monitor.accept( this );
+            }
+        }
+    }
+
+    public void visit( Monitor monitor )
+    {
+        boolean first = true;
+        for ( Metric metric : monitor.getMetrics() )
+        {
+            if ( configuration.filter( metric.getRole() ) )
+            {
+                if ( !first )
+                {
+                    next();
+                    first = false;
+                }
+                metric.accept( this );
+            }
+        }
+    }
+
+    protected void next()
+    {
+        // Nop
+    }
+
+
+}

Added: commons/sandbox/monitoring/branches/modules/reporting/src/main/java/org/apache/commons/monitoring/reporting/JsonRenderer.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/branches/modules/reporting/src/main/java/org/apache/commons/monitoring/reporting/JsonRenderer.java?rev=782967&view=auto
==============================================================================
--- commons/sandbox/monitoring/branches/modules/reporting/src/main/java/org/apache/commons/monitoring/reporting/JsonRenderer.java
(added)
+++ commons/sandbox/monitoring/branches/modules/reporting/src/main/java/org/apache/commons/monitoring/reporting/JsonRenderer.java
Tue Jun  9 11:56:12 2009
@@ -0,0 +1,119 @@
+/*
+ * 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.commons.monitoring.reporting;
+
+import java.io.PrintWriter;
+
+import org.apache.commons.monitoring.Counter;
+import org.apache.commons.monitoring.Gauge;
+import org.apache.commons.monitoring.Monitor;
+import org.apache.commons.monitoring.Repository;
+
+/**
+ * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
+ */
+public class JsonRenderer
+    extends AbstractFilteredVisitor
+{
+    public JsonRenderer( VisitorConfiguration configuration, PrintWriter writer )
+    {
+        super( configuration, writer );
+    }
+
+    public void visit( Repository repository )
+    {
+        writer.append( "repository: {" );
+        super.visit( repository );
+        writer.append( "}\n" );
+    }
+
+    public void visit( Monitor monitor )
+    {
+        Monitor.Key key = monitor.getKey();
+        writer.append( "  \"" );
+        writer.append( key.getName() );
+        writer.append( "\": { category:\"" );
+        writer.append( key.getCategory() );
+        writer.append( "\", subsystem:\"" );
+        writer.append( key.getSubsystem() );
+        writer.append( "\",\n" );
+        super.visit( monitor );
+        writer.append( "  }\n" );
+    }
+
+    @Override
+    protected void next()
+    {
+        writer.append( "," );
+    }
+
+    public void visit( Gauge gauge )
+    {
+        writer.append( "    \"" ).append( gauge.getRole().getName() );
+        writer.append( "\": { type:\"gauge\", unit:\"" ).append( gauge.getUnit().getName()
);
+        writer.append( "\", value:\"" );
+        writer.append( configuration.format( gauge.getValue() ) );
+        writer.append( "\"\n             max:\"" );
+        writer.append( configuration.format( gauge.getMax() ) );
+        writer.append( "\", min:\"" );
+        writer.append( configuration.format( gauge.getMin() ) );
+        writer.append( "\", hits:\"" );
+        writer.append( configuration.format( gauge.getHits() ) );
+        writer.append( "\", standardDeviation:\"" );
+        writer.append( configuration.format( gauge.getStandardDeviation() ) );
+        writer.append( "\", variance:\"" );
+        writer.append( configuration.format( gauge.getVariance() ) );
+        writer.append( "\", mean:\"" );
+        writer.append( configuration.format( gauge.getMean() ) );
+        writer.append( "\", geometricMean:\"" );
+        writer.append( configuration.format( gauge.getGeometricMean() ) );
+        writer.append( "\", sumOfLogs:\"" );
+        writer.append( configuration.format( gauge.getSumOfLogs() ) );
+        writer.append( "\", somOfSquares:\"" );
+        writer.append( configuration.format( gauge.getSumOfSquares() ) );
+        writer.append( "\"}\n" );
+    }
+
+    public void visit( Counter counter )
+    {
+        writer.append( "    \"" ).append( counter.getRole().getName() );
+        writer.append( "\": { type:\"counter\", unit:\"" ).append( counter.getUnit().getName()
);
+        writer.append( "\", sum:\"" );
+        writer.append( configuration.format( counter.getSum() ) );
+        writer.append( "\"\n             max:\"" );
+        writer.append( configuration.format( counter.getMax() ) );
+        writer.append( "\", min:\"" );
+        writer.append( configuration.format( counter.getMin() ) );
+        writer.append( "\", hits:\"" );
+        writer.append( configuration.format( counter.getHits() ) );
+        writer.append( "\", standardDeviation:\"" );
+        writer.append( configuration.format( counter.getStandardDeviation() ) );
+        writer.append( "\", variance:\"" );
+        writer.append( configuration.format( counter.getVariance() ) );
+        writer.append( "\", mean:\"" );
+        writer.append( configuration.format( counter.getMean() ) );
+        writer.append( "\", geometricMean:\"" );
+        writer.append( configuration.format( counter.getGeometricMean() ) );
+        writer.append( "\", sumOfLogs:\"" );
+        writer.append( configuration.format( counter.getSumOfLogs() ) );
+        writer.append( "\", somOfSquares:\"" );
+        writer.append( configuration.format( counter.getSumOfSquares() ) );
+        writer.append( "\"}\n" );
+    }
+
+}
\ No newline at end of file

Added: commons/sandbox/monitoring/branches/modules/reporting/src/main/java/org/apache/commons/monitoring/reporting/VisitorConfiguration.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/branches/modules/reporting/src/main/java/org/apache/commons/monitoring/reporting/VisitorConfiguration.java?rev=782967&view=auto
==============================================================================
--- commons/sandbox/monitoring/branches/modules/reporting/src/main/java/org/apache/commons/monitoring/reporting/VisitorConfiguration.java
(added)
+++ commons/sandbox/monitoring/branches/modules/reporting/src/main/java/org/apache/commons/monitoring/reporting/VisitorConfiguration.java
Tue Jun  9 11:56:12 2009
@@ -0,0 +1,33 @@
+/*
+ * 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.commons.monitoring.reporting;
+
+import org.apache.commons.monitoring.Role;
+import org.apache.commons.monitoring.Monitor.Key;
+
+/**
+ * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
+ */
+public interface VisitorConfiguration
+{
+    boolean filter( Key key );
+
+    boolean filter( Role role );
+
+    String format( double value );
+}

Added: commons/sandbox/monitoring/branches/modules/reporting/src/main/java/org/apache/commons/monitoring/reporting/VisitorConfigurationSupport.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/branches/modules/reporting/src/main/java/org/apache/commons/monitoring/reporting/VisitorConfigurationSupport.java?rev=782967&view=auto
==============================================================================
--- commons/sandbox/monitoring/branches/modules/reporting/src/main/java/org/apache/commons/monitoring/reporting/VisitorConfigurationSupport.java
(added)
+++ commons/sandbox/monitoring/branches/modules/reporting/src/main/java/org/apache/commons/monitoring/reporting/VisitorConfigurationSupport.java
Tue Jun  9 11:56:12 2009
@@ -0,0 +1,43 @@
+/*
+ * 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.commons.monitoring.reporting;
+
+import org.apache.commons.monitoring.Role;
+import org.apache.commons.monitoring.Monitor.Key;
+
+/**
+ * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
+ */
+public class VisitorConfigurationSupport
+    implements VisitorConfiguration
+{
+    public boolean filter( Key key )
+    {
+        return true;
+    }
+
+    public boolean filter( Role role )
+    {
+        return true;
+    }
+
+    public String format( double value )
+    {
+        return String.valueOf( value );
+    }
+}

Added: commons/sandbox/monitoring/branches/modules/reporting/src/main/java/org/apache/commons/monitoring/reporting/XmlRenderer.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/branches/modules/reporting/src/main/java/org/apache/commons/monitoring/reporting/XmlRenderer.java?rev=782967&view=auto
==============================================================================
--- commons/sandbox/monitoring/branches/modules/reporting/src/main/java/org/apache/commons/monitoring/reporting/XmlRenderer.java
(added)
+++ commons/sandbox/monitoring/branches/modules/reporting/src/main/java/org/apache/commons/monitoring/reporting/XmlRenderer.java
Tue Jun  9 11:56:12 2009
@@ -0,0 +1,114 @@
+/*
+ * 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.commons.monitoring.reporting;
+
+import java.io.PrintWriter;
+
+import org.apache.commons.monitoring.Counter;
+import org.apache.commons.monitoring.Gauge;
+import org.apache.commons.monitoring.Monitor;
+import org.apache.commons.monitoring.Repository;
+
+/**
+ * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
+ */
+public class XmlRenderer
+    extends AbstractFilteredVisitor
+{
+
+    public XmlRenderer( VisitorConfiguration configuration, PrintWriter writer )
+    {
+        super( configuration, writer );
+    }
+
+    public void visit( Repository repository )
+    {
+        writer.append( "<repository>\n" );
+        super.visit( repository );
+        writer.append( "</repository>\n" );
+    }
+
+    public void visit( Monitor monitor )
+    {
+        Monitor.Key key = monitor.getKey();
+        writer.append( "  <monitor name=\"" );
+        writer.append( key.getName() );
+        writer.append( "\" category=\"" );
+        writer.append( key.getCategory() );
+        writer.append( "\" subsystem=\"" );
+        writer.append( key.getSubsystem() );
+        writer.append( "\">\n" );
+        super.visit( monitor );
+        writer.append( "  </monitor>\n" );
+    }
+
+    public void visit( Gauge gauge )
+    {
+        writer.append( "    <gauge role=\"" ).append( gauge.getRole().getName() );
+        writer.append( "\" unit=\"" ).append( gauge.getUnit().getName() );
+        writer.append( "\" value=\"" );
+        writer.append( configuration.format( gauge.getValue() ) );
+        writer.append( "\"\n             max=\"" );
+        writer.append( configuration.format( gauge.getMax() ) );
+        writer.append( "\" min=\"" );
+        writer.append( configuration.format( gauge.getMin() ) );
+        writer.append( "\" hits=\"" );
+        writer.append( configuration.format( gauge.getHits() ) );
+        writer.append( "\" standardDeviation=\"" );
+        writer.append( configuration.format( gauge.getStandardDeviation() ) );
+        writer.append( "\" variance=\"" );
+        writer.append( configuration.format( gauge.getVariance() ) );
+        writer.append( "\" mean=\"" );
+        writer.append( configuration.format( gauge.getMean() ) );
+        writer.append( "\" geometricMean=\"" );
+        writer.append( configuration.format( gauge.getGeometricMean() ) );
+        writer.append( "\" sumOfLogs=\"" );
+        writer.append( configuration.format( gauge.getSumOfLogs() ) );
+        writer.append( "\" somOfSquares=\"" );
+        writer.append( configuration.format( gauge.getSumOfSquares() ) );
+        writer.append( "\" />\n" );
+    }
+
+    public void visit( Counter counter )
+    {
+        writer.append( "    <counter role=\"" ).append( counter.getRole().getName() );
+        writer.append( "\" unit=\"" ).append( counter.getUnit().getName() );
+        writer.append( "\" sum=\"" );
+        writer.append( configuration.format( counter.getSum() ) );
+        writer.append( "\"\n             max=\"" );
+        writer.append( configuration.format( counter.getMax() ) );
+        writer.append( "\" min=\"" );
+        writer.append( configuration.format( counter.getMin() ) );
+        writer.append( "\" hits=\"" );
+        writer.append( configuration.format( counter.getHits() ) );
+        writer.append( "\" standardDeviation=\"" );
+        writer.append( configuration.format( counter.getStandardDeviation() ) );
+        writer.append( "\" variance=\"" );
+        writer.append( configuration.format( counter.getVariance() ) );
+        writer.append( "\" mean=\"" );
+        writer.append( configuration.format( counter.getMean() ) );
+        writer.append( "\" geometricMean=\"" );
+        writer.append( configuration.format( counter.getGeometricMean() ) );
+        writer.append( "\" sumOfLogs=\"" );
+        writer.append( configuration.format( counter.getSumOfLogs() ) );
+        writer.append( "\" somOfSquares=\"" );
+        writer.append( configuration.format( counter.getSumOfSquares() ) );
+        writer.append( "\" />\n" );
+    }
+
+}
\ No newline at end of file

Added: commons/sandbox/monitoring/branches/modules/reporting/src/test/java/org/apache/commons/monitoring/reporting/RendererTest.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/branches/modules/reporting/src/test/java/org/apache/commons/monitoring/reporting/RendererTest.java?rev=782967&view=auto
==============================================================================
--- commons/sandbox/monitoring/branches/modules/reporting/src/test/java/org/apache/commons/monitoring/reporting/RendererTest.java
(added)
+++ commons/sandbox/monitoring/branches/modules/reporting/src/test/java/org/apache/commons/monitoring/reporting/RendererTest.java
Tue Jun  9 11:56:12 2009
@@ -0,0 +1,75 @@
+/*
+ * 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.commons.monitoring.reporting;
+
+import static org.apache.commons.monitoring.Monitor.CONCURRENCY;
+import static org.apache.commons.monitoring.Monitor.FAILURES;
+import static org.apache.commons.monitoring.Unit.UNARY;
+
+import java.io.InputStreamReader;
+import java.io.PrintWriter;
+import java.io.Reader;
+import java.io.StringReader;
+import java.io.StringWriter;
+
+import org.apache.commons.monitoring.Repository;
+import org.apache.commons.monitoring.Visitor;
+import org.apache.commons.monitoring.repositories.DefaultRepository;
+import org.custommonkey.xmlunit.XMLAssert;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
+ */
+public class RendererTest
+{
+    private Repository repository;
+
+    @Before
+    public void setup()
+    {
+        repository = new DefaultRepository();
+        repository.getMonitor( "RendererTest", "unit", "test" ).getCounter( FAILURES ).add(
1.0 );
+        repository.getMonitor( "RendererTest", "unit", "test" ).getGauge( CONCURRENCY ).increment(
UNARY );
+    }
+
+    @Test
+    public void renderToXML()
+        throws Exception
+    {
+        StringWriter out = new StringWriter();
+        Visitor v = new XmlRenderer( new VisitorConfigurationSupport(), new PrintWriter(
out ) );
+        repository.accept( v );
+
+        Reader expected = new InputStreamReader( getClass().getResourceAsStream( "RendererTest.xml"
) );
+        XMLAssert.assertXMLEqual( expected, new StringReader( out.toString() ) );
+    }
+
+    @Test
+    public void renderToJSON()
+        throws Exception
+    {
+        StringWriter out = new StringWriter();
+        Visitor v = new JsonRenderer( new VisitorConfigurationSupport(), new PrintWriter(
out ) );
+        repository.accept( v );
+
+        System.out.println( out.toString() );
+        // JSON Testing framework
+    }
+}

Added: commons/sandbox/monitoring/branches/modules/reporting/src/test/resources/org/apache/commons/monitoring/reporting/RendererTest.xml
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/branches/modules/reporting/src/test/resources/org/apache/commons/monitoring/reporting/RendererTest.xml?rev=782967&view=auto
==============================================================================
--- commons/sandbox/monitoring/branches/modules/reporting/src/test/resources/org/apache/commons/monitoring/reporting/RendererTest.xml
(added)
+++ commons/sandbox/monitoring/branches/modules/reporting/src/test/resources/org/apache/commons/monitoring/reporting/RendererTest.xml
Tue Jun  9 11:56:12 2009
@@ -0,0 +1,9 @@
+<repository>
+  <monitor name="RendererTest" category="unit" subsystem="test">
+    <counter role="failures" unit="" sum="1.0" max="1.0" min="1.0" hits="1.0" standardDeviation="0.0"
variance="0.0"
+      mean="1.0" geometricMean="1.0" sumOfLogs="0.0" somOfSquares="1.0" />
+    <gauge role="concurrency" unit="" value="1.0" max="NaN" min="NaN" hits="0.0" standardDeviation="NaN"
variance="NaN"
+      mean="NaN" geometricMean="NaN" sumOfLogs="NaN" somOfSquares="NaN" />
+  </monitor>
+</repository>
+



Mime
View raw message