commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nico...@apache.org
Subject svn commit: r633810 [1/3] - in /commons/sandbox/monitoring/trunk: ./ src/main/java/org/apache/commons/monitoring/ src/main/java/org/apache/commons/monitoring/impl/ src/main/java/org/apache/commons/monitoring/impl/monitors/ src/main/java/org/apache/comm...
Date Wed, 05 Mar 2008 10:48:54 GMT
Author: nicolas
Date: Wed Mar  5 02:48:38 2008
New Revision: 633810

URL: http://svn.apache.org/viewvc?rev=633810&view=rev
Log:
- implementations refactored as a class hierarchy, beeing easier to extend and cleaner to discover repository features
- dedicated packages for component implementations
- reporting for HTML output
- web UI servlet extending HTML reporting with JavaScript enhancements (JQuery)

Added:
    commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/monitors/
    commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/monitors/AbstractMonitor.java   (contents, props changed)
      - copied, changed from r632970, commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/AbstractMonitor.java
    commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/monitors/CompositeValuesMonitor.java   (contents, props changed)
      - copied, changed from r632970, commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/CompositeValuesMonitor.java
    commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/monitors/CreateValuesOnDemandMonitor.java   (contents, props changed)
      - copied, changed from r632970, commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/CreateValuesOnDemandMonitor.java
    commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/monitors/ObservableMonitor.java   (contents, props changed)
      - copied, changed from r632970, commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/ListenableMonitor.java
    commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/repositories/
    commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/repositories/AbstractRepository.java   (contents, props changed)
      - copied, changed from r632970, commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/AbstractRepository.java
    commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/repositories/ConfigurableImplementationsRepository.java   (with props)
    commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/repositories/CreateMonitorsOnDemandRepository.java   (with props)
    commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/repositories/DefaultRepository.java   (contents, props changed)
      - copied, changed from r632970, commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/DefaultRepository.java
    commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/repositories/ObservableRepository.java   (with props)
    commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/stopwatches/
    commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/stopwatches/DefaultStopWatch.java
      - copied, changed from r632970, commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/DefaultStopWatch.java
    commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/stopwatches/ExecutionStopWatch.java   (with props)
    commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/values/
    commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/values/AbstractStatValue.java   (contents, props changed)
      - copied, changed from r632970, commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/AbstractStatValue.java
    commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/values/CompositeCounter.java   (contents, props changed)
      - copied, changed from r632970, commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/CompositeCounter.java
    commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/values/CompositeGauge.java   (contents, props changed)
      - copied, changed from r632970, commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/CompositeGauge.java
    commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/values/ThreadSafeCounter.java   (contents, props changed)
      - copied, changed from r632970, commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/ThreadSafeCounter.java
    commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/values/ThreadSafeGauge.java   (contents, props changed)
      - copied, changed from r632970, commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/ThreadSafeGauge.java
    commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/reporting/HtmlRenderer.java   (with props)
    commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/reporting/Selector.java   (with props)
    commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/reporting/SelectorPeriodicLogger.java   (contents, props changed)
      - copied, changed from r632970, commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/reporting/AppendToFilePeriodicLogger.java
    commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/reporting/web/
    commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/reporting/web/MonitoringServlet.java   (with props)
    commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/reporting/web/NiceHtmlRenderer.java   (with props)
    commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/reporting/web/WebUIServlet.java   (with props)
    commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/support/java13/README.txt   (props changed)
      - copied unchanged from r632970, commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/support/java13/README
    commons/sandbox/monitoring/trunk/src/main/resources/JQUERY-LICENSE.txt   (with props)
    commons/sandbox/monitoring/trunk/src/main/resources/asc.gif   (with props)
    commons/sandbox/monitoring/trunk/src/main/resources/commons-monitoring.css   (with props)
    commons/sandbox/monitoring/trunk/src/main/resources/commons-monitoring.js   (with props)
    commons/sandbox/monitoring/trunk/src/main/resources/desc.gif   (with props)
    commons/sandbox/monitoring/trunk/src/main/resources/jquery-1.2.3.pack.js   (with props)
    commons/sandbox/monitoring/trunk/src/main/resources/jquery.tablesorter.pack.js   (with props)
    commons/sandbox/monitoring/trunk/src/main/webapp/
    commons/sandbox/monitoring/trunk/src/main/webapp/WEB-INF/
    commons/sandbox/monitoring/trunk/src/main/webapp/WEB-INF/web.xml   (with props)
    commons/sandbox/monitoring/trunk/src/main/webapp/test.html   (with props)
    commons/sandbox/monitoring/trunk/src/test/java/org/apache/commons/monitoring/reporting/SelectorTest.java   (with props)
    commons/sandbox/monitoring/trunk/src/test/resources/org/apache/commons/monitoring/reporting/RendererTest.html   (with props)
Removed:
    commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/AbstractMonitor.java
    commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/AbstractRepository.java
    commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/AbstractStatValue.java
    commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/CompositeCounter.java
    commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/CompositeGauge.java
    commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/CompositeValuesMonitor.java
    commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/CreateValuesOnDemandMonitor.java
    commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/DefaultRepository.java
    commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/DefaultStopWatch.java
    commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/ListenableMonitor.java
    commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/ThreadSafeCounter.java
    commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/ThreadSafeGauge.java
    commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/reporting/AppendToFilePeriodicLogger.java
    commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/support/java13/README
Modified:
    commons/sandbox/monitoring/trunk/pom.xml
    commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/ExecutionStack.java
    commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/Monitor.java
    commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/Monitoring.java
    commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/Repository.java
    commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/StatValue.java
    commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/listeners/SecondaryMonitor.java
    commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/listeners/SecondaryRepository.java
    commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/reporting/AbstractPeriodicLogger.java
    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/JsonRenderer.java
    commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/reporting/Renderer.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
    commons/sandbox/monitoring/trunk/src/site/xdoc/instrumentation.xml
    commons/sandbox/monitoring/trunk/src/site/xdoc/listeners.xml
    commons/sandbox/monitoring/trunk/src/test/java/org/apache/commons/monitoring/ExecutionStackTest.java
    commons/sandbox/monitoring/trunk/src/test/java/org/apache/commons/monitoring/MonitoringTest.java
    commons/sandbox/monitoring/trunk/src/test/java/org/apache/commons/monitoring/StopWatchTest.java
    commons/sandbox/monitoring/trunk/src/test/java/org/apache/commons/monitoring/impl/CompositeValuesMonitorTest.java
    commons/sandbox/monitoring/trunk/src/test/java/org/apache/commons/monitoring/impl/DefaultRepositoryTest.java
    commons/sandbox/monitoring/trunk/src/test/java/org/apache/commons/monitoring/impl/ThreadSafeCounterTest.java
    commons/sandbox/monitoring/trunk/src/test/java/org/apache/commons/monitoring/impl/ThreadSafeGaugeTest.java
    commons/sandbox/monitoring/trunk/src/test/java/org/apache/commons/monitoring/listener/SecondaryReposioryTest.java
    commons/sandbox/monitoring/trunk/src/test/java/org/apache/commons/monitoring/listener/ThresholdListenerTest.java
    commons/sandbox/monitoring/trunk/src/test/java/org/apache/commons/monitoring/reporting/RendererTest.java
    commons/sandbox/monitoring/trunk/src/test/resources/org/apache/commons/monitoring/reporting/RendererTest.js

Modified: commons/sandbox/monitoring/trunk/pom.xml
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/pom.xml?rev=633810&r1=633809&r2=633810&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/pom.xml (original)
+++ commons/sandbox/monitoring/trunk/pom.xml Wed Mar  5 02:48:38 2008
@@ -36,6 +36,14 @@
 
   <dependencies>
     <dependency>
+      <groupId>javax.servlet</groupId>
+      <artifactId>servlet-api</artifactId>
+      <version>2.3</version>
+      <scope>provided</scope>
+      <optional>true</optional>
+    </dependency>
+
+    <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
       <version>3.8.1</version>
@@ -167,6 +175,20 @@
           </execution>
         </executions>
       </plugin>
+
+      <plugin>
+        <!-- to manually test the Web UI -->
+        <groupId>org.mortbay.jetty</groupId>
+        <artifactId>maven-jetty-plugin</artifactId>
+        <version>6.1.7</version>
+        <configuration>
+          <scanIntervalSeconds>10</scanIntervalSeconds>
+          <webAppConfig>
+            <contextPath>/monitoring</contextPath>
+            <tempDirectory>${project.build.directory}/work</tempDirectory>
+          </webAppConfig>
+        </configuration>
+      </plugin>
     </plugins>
   </build>
   <distributionManagement>
@@ -195,4 +217,5 @@
       </plugin>
     </plugins>
   </reporting>
+
 </project>

Modified: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/ExecutionStack.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/ExecutionStack.java?rev=633810&r1=633809&r2=633810&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/ExecutionStack.java (original)
+++ commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/ExecutionStack.java Wed Mar  5 02:48:38 2008
@@ -20,7 +20,7 @@
 import java.util.LinkedList;
 import java.util.List;
 
-import org.apache.commons.monitoring.impl.DefaultStopWatch;
+import org.apache.commons.monitoring.StopWatch;
 
 /**
  * Sometime we need to compare elapsed time from a high level process with fine-grained
@@ -43,36 +43,14 @@
         super();
     }
 
-    private static ThreadLocal<List<DefaultStopWatch>> local = new ThreadLocal<List<DefaultStopWatch>>();
+    private static ThreadLocal<List<StopWatch>> local = new ThreadLocal<List<StopWatch>>();
 
-    public static void push( DefaultStopWatch stopWatch )
+    public static void push( StopWatch stopWatch )
     {
         getExecution().add( stopWatch );
     }
 
     /**
-     * Pause all running stopWatches
-     */
-    public static void pause()
-    {
-        for ( StopWatch stopWatch : getExecution() )
-        {
-            stopWatch.pause();
-        }
-    }
-
-    /**
-     * Resume all stopWatches
-     */
-    public static void resume()
-    {
-        for ( StopWatch stopWatch : getExecution() )
-        {
-            stopWatch.resume();
-        }
-    }
-
-    /**
      *
      * @return <code>true</code> if all stopWatches are stopped (execution is finished)
      */
@@ -89,14 +67,25 @@
     }
 
     /**
+     * Indicates if the StopWatch is the top-level element in the execution
+     * @param stopWatch a stopwatch to test
+     * @return <code>true</code> is the stopWatch is the first one registered during execution
+     */
+    public static boolean isTopLevel( StopWatch stopWatch )
+    {
+        List<StopWatch> exec = local.get();
+        return ( exec != null ) && ( ! exec.isEmpty() ) && stopWatch.equals( exec.get( 0 ) );
+    }
+
+    /**
      * @return the ordered list of StopWatches used during execution
      */
-    public static List<DefaultStopWatch> getExecution()
+    public static List<StopWatch> getExecution()
     {
-        List<DefaultStopWatch> exec = local.get();
+        List<StopWatch> exec = local.get();
         if (exec == null)
         {
-            exec = new LinkedList<DefaultStopWatch>();
+            exec = new LinkedList<StopWatch>();
             local.set( exec );
         }
         return local.get();

Modified: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/Monitor.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/Monitor.java?rev=633810&r1=633809&r2=633810&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/Monitor.java (original)
+++ commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/Monitor.java Wed Mar  5 02:48:38 2008
@@ -222,12 +222,28 @@
 
     }
 
-    void addListener( Listener listener );
-
-    void removeListener( Listener listener );
 
+    /**
+     * Listener interface to get notified on montor events
+     */
     public static interface Listener
     {
         void onStatValueRegistered( StatValue value );
+    }
+
+    /**
+     * Monitor that accepts Listeners and notify them on monitor events
+     */
+    public static interface Observable extends Monitor
+    {
+        /**
+         * @param listener listener to get registered
+         */
+        void addListener( Listener listener );
+
+        /**
+         * @param listener listener to get removed
+         */
+        void removeListener( Listener listener );
     }
 }

Modified: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/Monitoring.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/Monitoring.java?rev=633810&r1=633809&r2=633810&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/Monitoring.java (original)
+++ commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/Monitoring.java Wed Mar  5 02:48:38 2008
@@ -17,8 +17,8 @@
 
 package org.apache.commons.monitoring;
 
-import org.apache.commons.monitoring.impl.DefaultRepository;
-import org.apache.commons.monitoring.impl.DefaultStopWatch;
+import org.apache.commons.monitoring.impl.repositories.DefaultRepository;
+import org.apache.commons.monitoring.StopWatch;
 
 /**
  * Utility class for simpified application instrumentation

Modified: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/Repository.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/Repository.java?rev=633810&r1=633809&r2=633810&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/Repository.java (original)
+++ commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/Repository.java Wed Mar  5 02:48:38 2008
@@ -65,16 +65,6 @@
      */
     void reset();
 
-    /**
-     * @param listener listener to get registered
-     */
-    void addListener( Listener listener );
-
-    /**
-     *
-     * @param listener listener to get deregistered
-     */
-    void removeListener( Listener listener );
 
     /**
      * Start a StopWatch to monitor execution
@@ -85,10 +75,8 @@
 
     /**
      * Listener interface to get notified on repository events
-     *
-     * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
      */
-    static interface Listener
+    public static interface Listener
     {
         /**
          * A monitor has just been created. Can be used to add custom StatValues or
@@ -98,6 +86,23 @@
          * @param monitor
          */
         void newMonitorInstance( Monitor monitor );
+    }
+
+    /**
+     * Repository that accepts Listeners and notify them on repository events
+     */
+    public static interface Observable extends Repository
+    {
+
+        /**
+         * @param listener listener to get registered
+         */
+        void addListener( Listener listener );
+
+        /**
+         * @param listener listener to get removed
+         */
+        void removeListener( Listener listener );
     }
 
 }

Modified: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/StatValue.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/StatValue.java?rev=633810&r1=633809&r2=633810&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/StatValue.java (original)
+++ commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/StatValue.java Wed Mar  5 02:48:38 2008
@@ -26,7 +26,6 @@
  */
 public interface StatValue
 {
-    String getUnit();
 
     /**
      * @return the value
@@ -78,10 +77,10 @@
 
     void removeListener( Listener listener );
 
+    String getUnit();
+
     /**
      * Listener for StatValue events
-     *
-     * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
      */
     public static interface Listener
     {

Copied: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/monitors/AbstractMonitor.java (from r632970, commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/AbstractMonitor.java)
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/monitors/AbstractMonitor.java?p2=commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/monitors/AbstractMonitor.java&p1=commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/AbstractMonitor.java&r1=632970&r2=633810&rev=633810&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/AbstractMonitor.java (original)
+++ commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/monitors/AbstractMonitor.java Wed Mar  5 02:48:38 2008
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package org.apache.commons.monitoring.impl;
+package org.apache.commons.monitoring.impl.monitors;
 
 import java.util.Collection;
 import java.util.Collections;
@@ -78,6 +78,7 @@
      * @return a previously registered StatValue if existed, or <code>null</code>
      * if value has been successfully registered
      */
+    @SuppressWarnings("unchecked")
     protected <T extends StatValue> T register( T value )
     {
         value.setMonitor( this );

Propchange: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/monitors/AbstractMonitor.java
------------------------------------------------------------------------------
    svn:mergeinfo = 

Copied: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/monitors/CompositeValuesMonitor.java (from r632970, commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/CompositeValuesMonitor.java)
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/monitors/CompositeValuesMonitor.java?p2=commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/monitors/CompositeValuesMonitor.java&p1=commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/CompositeValuesMonitor.java&r1=632970&r2=633810&rev=633810&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/CompositeValuesMonitor.java (original)
+++ commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/monitors/CompositeValuesMonitor.java Wed Mar  5 02:48:38 2008
@@ -15,10 +15,12 @@
  * limitations under the License.
  */
 
-package org.apache.commons.monitoring.impl;
+package org.apache.commons.monitoring.impl.monitors;
 
 import org.apache.commons.monitoring.Counter;
 import org.apache.commons.monitoring.Gauge;
+import org.apache.commons.monitoring.impl.values.CompositeCounter;
+import org.apache.commons.monitoring.impl.values.CompositeGauge;
 
 /**
  * A Monitor implementation that creates {@link Composite} Gauges and Counters.

Propchange: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/monitors/CompositeValuesMonitor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/monitors/CompositeValuesMonitor.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/monitors/CompositeValuesMonitor.java
------------------------------------------------------------------------------
    svn:mergeinfo = 

Propchange: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/monitors/CompositeValuesMonitor.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Copied: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/monitors/CreateValuesOnDemandMonitor.java (from r632970, commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/CreateValuesOnDemandMonitor.java)
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/monitors/CreateValuesOnDemandMonitor.java?p2=commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/monitors/CreateValuesOnDemandMonitor.java&p1=commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/CreateValuesOnDemandMonitor.java&r1=632970&r2=633810&rev=633810&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/CreateValuesOnDemandMonitor.java (original)
+++ commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/monitors/CreateValuesOnDemandMonitor.java Wed Mar  5 02:48:38 2008
@@ -15,10 +15,12 @@
  * limitations under the License.
  */
 
-package org.apache.commons.monitoring.impl;
+package org.apache.commons.monitoring.impl.monitors;
 
 import org.apache.commons.monitoring.Counter;
 import org.apache.commons.monitoring.Gauge;
+import org.apache.commons.monitoring.impl.values.ThreadSafeCounter;
+import org.apache.commons.monitoring.impl.values.ThreadSafeGauge;
 
 /**
  * implementation of the <code>Monitor</code> interface that creates StatValues on
@@ -28,7 +30,7 @@
  * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
  */
 public class CreateValuesOnDemandMonitor
-    extends ListenableMonitor
+    extends ObservableMonitor
 {
 
     public CreateValuesOnDemandMonitor( Key key )
@@ -58,7 +60,6 @@
     protected Counter newCounterInstance( String role )
     {
         return new ThreadSafeCounter( role );
-
     }
 
     /**

Propchange: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/monitors/CreateValuesOnDemandMonitor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/monitors/CreateValuesOnDemandMonitor.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/monitors/CreateValuesOnDemandMonitor.java
------------------------------------------------------------------------------
    svn:mergeinfo = 

Copied: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/monitors/ObservableMonitor.java (from r632970, commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/ListenableMonitor.java)
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/monitors/ObservableMonitor.java?p2=commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/monitors/ObservableMonitor.java&p1=commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/ListenableMonitor.java&r1=632970&r2=633810&rev=633810&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/ListenableMonitor.java (original)
+++ commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/monitors/ObservableMonitor.java Wed Mar  5 02:48:38 2008
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package org.apache.commons.monitoring.impl;
+package org.apache.commons.monitoring.impl.monitors;
 
 import java.util.List;
 import java.util.concurrent.CopyOnWriteArrayList;
@@ -28,24 +28,27 @@
  *
  * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
  */
-public abstract class ListenableMonitor extends AbstractMonitor implements Monitor
+public abstract class ObservableMonitor
+    extends AbstractMonitor
+    implements Monitor.Observable
 {
 
     private List<Listener> listeners;
 
     /**
      * Constructor
+     *
      * @param key the monitor identifier
      */
-    public ListenableMonitor( Key key )
+    public ObservableMonitor( Key key )
     {
         super( key );
         this.listeners = new CopyOnWriteArrayList<Listener>();
     }
 
-
     /**
      * Register the StatValue for the role, if none was registered before
+     *
      * @param value
      * @param role
      * @return the value registered, or a previously existing one
@@ -54,7 +57,7 @@
     protected <T extends StatValue> T register( T value )
     {
         T previous = (T) super.register( value );
-        if (previous != null)
+        if ( previous != null )
         {
             return previous;
         }
@@ -64,7 +67,6 @@
         }
         return null;
     }
-
 
     public void addListener( Listener listener )
     {

Propchange: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/monitors/ObservableMonitor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/monitors/ObservableMonitor.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/monitors/ObservableMonitor.java
------------------------------------------------------------------------------
    svn:mergeinfo = 

Propchange: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/monitors/ObservableMonitor.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Copied: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/repositories/AbstractRepository.java (from r632970, commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/AbstractRepository.java)
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/repositories/AbstractRepository.java?p2=commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/repositories/AbstractRepository.java&p1=commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/AbstractRepository.java&r1=632970&r2=633810&rev=633810&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/AbstractRepository.java (original)
+++ commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/repositories/AbstractRepository.java Wed Mar  5 02:48:38 2008
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package org.apache.commons.monitoring.impl;
+package org.apache.commons.monitoring.impl.repositories;
 
 import java.util.Collection;
 import java.util.Collections;
@@ -27,11 +27,11 @@
 
 import org.apache.commons.monitoring.Monitor;
 import org.apache.commons.monitoring.Repository;
-import org.apache.commons.monitoring.StopWatch;
 import org.apache.commons.monitoring.Monitor.Key;
 
 /**
- * Abstract implementation of {@link Repository} with support for base methods
+ * Abstract implementation of {@link Repository} with support for base methods.
+ * <p>
  *
  * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
  */
@@ -43,6 +43,7 @@
     public AbstractRepository()
     {
         super();
+        // register default implementation.
         this.monitors = new ConcurrentHashMap<Monitor.Key, Monitor>( 50 );
     }
 
@@ -135,16 +136,6 @@
         {
             monitor.reset();
         }
-    }
-
-
-    /**
-     * {@inheritDoc}
-     * @see org.apache.commons.monitoring.Repository#start(org.apache.commons.monitoring.Monitor)
-     */
-    public StopWatch start( Monitor monitor )
-    {
-        return new DefaultStopWatch( monitor );
     }
 
 }

Propchange: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/repositories/AbstractRepository.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/repositories/AbstractRepository.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/repositories/AbstractRepository.java
------------------------------------------------------------------------------
    svn:mergeinfo = 

Propchange: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/repositories/AbstractRepository.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/repositories/ConfigurableImplementationsRepository.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/repositories/ConfigurableImplementationsRepository.java?rev=633810&view=auto
==============================================================================
--- commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/repositories/ConfigurableImplementationsRepository.java (added)
+++ commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/repositories/ConfigurableImplementationsRepository.java Wed Mar  5 02:48:38 2008
@@ -0,0 +1,110 @@
+/*
+ * 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.impl.repositories;
+
+import java.lang.reflect.Constructor;
+
+import org.apache.commons.monitoring.Monitor;
+import org.apache.commons.monitoring.StopWatch;
+import org.apache.commons.monitoring.Monitor.Key;
+
+/**
+ * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
+ */
+public class ConfigurableImplementationsRepository
+    extends CreateMonitorsOnDemandRepository
+{
+    private Constructor<? extends StopWatch> stopWatchConstructor;
+
+    private Constructor<? extends Monitor> monitorConstructor;
+
+    /**
+     * Constructor
+     * @param stopWatchImplementation the StopWatch implementation to use
+     * @param monitorImplementation the Monitor implementation to use
+     */
+    public ConfigurableImplementationsRepository( Class<? extends StopWatch> stopWatchImplementation,
+                                                  Class<? extends Monitor> monitorImplementation )
+    {
+        super();
+        setStopWatchImplementation( stopWatchImplementation );
+        setMonitorImplementation( monitorImplementation );
+    }
+
+    protected void setStopWatchImplementation( Class<? extends StopWatch> implementation )
+    {
+        try
+        {
+            stopWatchConstructor = implementation.getConstructor( Monitor.class );
+        }
+        catch ( Exception e )
+        {
+            throw new IllegalStateException( "Invalid StopWatch implemenation. Constructor <init>(Monitor) required", e );
+        }
+    }
+
+    protected void setMonitorImplementation( Class<? extends Monitor> implementation )
+    {
+        try
+        {
+            monitorConstructor = implementation.getConstructor( Monitor.Key.class );
+        }
+        catch ( Exception e )
+        {
+            throw new IllegalStateException(
+                "Invalid StopWatch implemenation. Constructor <init>(Monitor.Key) required", e );
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     *
+     * @see org.apache.commons.monitoring.impl.repositories.AbstractRepository#newMonitorInstance(org.apache.commons.monitoring.Monitor.Key)
+     */
+    @Override
+    protected Monitor newMonitorInstance( Key key )
+    {
+        try
+        {
+            return monitorConstructor.newInstance( key );
+        }
+        catch ( Exception e )
+        {
+            throw new IllegalStateException( "Invalid stopWatchConstructor configured in repository "
+                + stopWatchConstructor );
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     *
+     * @see org.apache.commons.monitoring.Repository#start(org.apache.commons.monitoring.Monitor)
+     */
+    public StopWatch start( Monitor monitor )
+    {
+        try
+        {
+            return stopWatchConstructor.newInstance( monitor );
+        }
+        catch ( Exception e )
+        {
+            throw new IllegalStateException( "Invalid stopWatchConstructor configured in repository "
+                + stopWatchConstructor );
+        }
+    }
+}

Propchange: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/repositories/ConfigurableImplementationsRepository.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/repositories/ConfigurableImplementationsRepository.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/repositories/ConfigurableImplementationsRepository.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/repositories/CreateMonitorsOnDemandRepository.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/repositories/CreateMonitorsOnDemandRepository.java?rev=633810&view=auto
==============================================================================
--- commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/repositories/CreateMonitorsOnDemandRepository.java (added)
+++ commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/repositories/CreateMonitorsOnDemandRepository.java Wed Mar  5 02:48:38 2008
@@ -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.commons.monitoring.impl.repositories;
+
+import org.apache.commons.monitoring.Monitor;
+import org.apache.commons.monitoring.Monitor.Key;
+
+/**
+ * Abstract implementation of a Repository that creates and register new Monitor instances
+ * as the monitored application request them.
+ *
+ * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
+ */
+public abstract class CreateMonitorsOnDemandRepository
+    extends ObservableRepository
+{
+
+    /**
+     * Retrieve a monitor an creates / register a new instance if required
+     * <p>
+     * {@inheritDoc}
+     * @see org.apache.commons.monitoring.impl.repositories.AbstractRepository#getMonitor(org.apache.commons.monitoring.Monitor.Key)
+     */
+    @Override
+    protected Monitor getMonitor( Key key )
+    {
+        Monitor monitor = super.getMonitor( key );
+        if ( monitor == null )
+        {
+            monitor = newMonitorInstance( key );
+            Monitor previous = register( monitor );
+            if ( previous != null )
+            {
+                monitor = previous;
+            }
+        }
+        return monitor;
+    }
+
+    protected abstract Monitor newMonitorInstance( Key key );
+
+}

Propchange: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/repositories/CreateMonitorsOnDemandRepository.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/repositories/CreateMonitorsOnDemandRepository.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/repositories/CreateMonitorsOnDemandRepository.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Copied: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/repositories/DefaultRepository.java (from r632970, commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/DefaultRepository.java)
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/repositories/DefaultRepository.java?p2=commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/repositories/DefaultRepository.java&p1=commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/DefaultRepository.java&r1=632970&r2=633810&rev=633810&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/DefaultRepository.java (original)
+++ commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/repositories/DefaultRepository.java Wed Mar  5 02:48:38 2008
@@ -15,55 +15,20 @@
  * limitations under the License.
  */
 
-package org.apache.commons.monitoring.impl;
+package org.apache.commons.monitoring.impl.repositories;
 
-import java.util.List;
-import java.util.concurrent.CopyOnWriteArrayList;
+import org.apache.commons.monitoring.impl.monitors.CompositeValuesMonitor;
+import org.apache.commons.monitoring.impl.stopwatches.DefaultStopWatch;
 
-import org.apache.commons.monitoring.Monitor;
-
-public class DefaultRepository extends AbstractRepository
+/**
+ * Default Repository implementation
+ *
+ * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
+ */
+public class DefaultRepository extends ConfigurableImplementationsRepository
 {
-
-    private List<Listener> listeners = new CopyOnWriteArrayList<Listener>();
-
     public DefaultRepository()
     {
-        super();
-    }
-
-    public void addListener( Listener listener )
-    {
-        listeners.add( listener );
-    }
-
-    public void removeListener( Listener listener )
-    {
-        listeners.remove( listener );
-    }
-
-    public Monitor getMonitor( Monitor.Key key )
-    {
-        Monitor monitor = super.getMonitor( key );
-        if ( monitor == null )
-        {
-            monitor = newMonitorInstance( key );
-            Monitor previous = register( monitor );
-            if ( previous != null )
-            {
-                return  previous;
-            }
-            for ( Listener listener : listeners )
-            {
-                listener.newMonitorInstance( monitor );
-            }
-        }
-        return monitor;
+        super( DefaultStopWatch.class, CompositeValuesMonitor.class );
     }
-
-    protected Monitor newMonitorInstance( Monitor.Key key )
-    {
-        return new CompositeValuesMonitor( key );
-    }
-
 }

Propchange: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/repositories/DefaultRepository.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/repositories/DefaultRepository.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/repositories/DefaultRepository.java
------------------------------------------------------------------------------
    svn:mergeinfo = 

Added: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/repositories/ObservableRepository.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/repositories/ObservableRepository.java?rev=633810&view=auto
==============================================================================
--- commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/repositories/ObservableRepository.java (added)
+++ commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/repositories/ObservableRepository.java Wed Mar  5 02:48:38 2008
@@ -0,0 +1,68 @@
+/*
+ * 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.impl.repositories;
+
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import org.apache.commons.monitoring.Monitor;
+import org.apache.commons.monitoring.Repository;
+
+/**
+ * Implement observale pattern on the repository
+ *
+ * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
+ */
+public abstract class ObservableRepository
+    extends AbstractRepository
+    implements Repository.Observable
+{
+
+    protected List<Listener> listeners = new CopyOnWriteArrayList<Listener>();
+
+    public void addListener( Listener listener )
+    {
+        listeners.add( listener );
+    }
+
+    public void removeListener( Listener listener )
+    {
+        listeners.remove( listener );
+    }
+
+    /**
+     * {@inheritDoc}
+     *
+     * @see org.apache.commons.monitoring.impl.repositories.AbstractRepository#register(org.apache.commons.monitoring.Monitor)
+     */
+    @Override
+    protected Monitor register( Monitor monitor )
+    {
+        Monitor previous = super.register( monitor );
+        if ( previous != null )
+        {
+            return previous;
+        }
+        for ( Listener listener : listeners )
+        {
+            listener.newMonitorInstance( monitor );
+        }
+        return null;
+    }
+
+}

Propchange: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/repositories/ObservableRepository.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/repositories/ObservableRepository.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/repositories/ObservableRepository.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Copied: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/stopwatches/DefaultStopWatch.java (from r632970, commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/DefaultStopWatch.java)
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/stopwatches/DefaultStopWatch.java?p2=commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/stopwatches/DefaultStopWatch.java&p1=commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/DefaultStopWatch.java&r1=632970&r2=633810&rev=633810&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/DefaultStopWatch.java (original)
+++ commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/stopwatches/DefaultStopWatch.java Wed Mar  5 02:48:38 2008
@@ -15,22 +15,14 @@
  * limitations under the License.
  */
 
-package org.apache.commons.monitoring.impl;
+package org.apache.commons.monitoring.impl.stopwatches;
 
-import java.util.Stack;
-
-import org.apache.commons.monitoring.ExecutionStack;
 import org.apache.commons.monitoring.Monitor;
 import org.apache.commons.monitoring.StopWatch;
 
 /**
  * Estimates the time required for process execution (monitored method, service
  * invocation, database request...).
- * <p>
- * The StopWatch maintains a threadLocal stack of active StopWatches. When a new
- * StopWatch is created by a sub-process, it automatically pause the "parent"
- * running StopWatch, so that the top-level elapsed time = Sum( all StopWatches
- * running times ).
  *
  * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
  */
@@ -54,10 +46,6 @@
     /** Monitor that is notified of process execution state */
     private final Monitor monitor;
 
-    private static boolean traceExecution;
-
-    private static final ThreadLocal<Stack<DefaultStopWatch>> STACK = new ThreadLocal<Stack<DefaultStopWatch>>();
-
     /**
      * Constructor.
      * <p>
@@ -75,42 +63,6 @@
         {
             monitor.getGauge( Monitor.CONCURRENCY ).increment();
         }
-        push();
-        if ( traceExecution )
-        {
-            ExecutionStack.push( this );
-        }
-    }
-
-    private void push()
-    {
-        Stack<DefaultStopWatch> stack = getStack();
-        if ( !stack.empty() )
-        {
-            stack.peek().pause();
-        }
-        stack.push( this );
-    }
-
-    private void pop()
-    {
-        Stack<DefaultStopWatch> stack = getStack();
-        stack.pop();
-        if ( !stack.empty() )
-        {
-            stack.peek().resume();
-        }
-    }
-
-    private Stack<DefaultStopWatch> getStack()
-    {
-        Stack<DefaultStopWatch> stack = STACK.get();
-        if ( stack == null )
-        {
-            stack = new Stack<DefaultStopWatch>();
-            STACK.set( stack );
-        }
-        return stack;
     }
 
     /**
@@ -177,11 +129,6 @@
                 monitor.getGauge( Monitor.CONCURRENCY ).decrement();
                 monitor.getCounter( Monitor.PERFORMANCES ).add( getElapsedTime() );
             }
-            pop();
-        }
-        if ( traceExecution && ExecutionStack.isFinished() )
-        {
-            ExecutionStack.clear();
         }
     }
 
@@ -214,11 +161,6 @@
             {
                 monitor.getGauge( Monitor.CONCURRENCY ).decrement();
             }
-            pop();
-        }
-        if ( traceExecution && ExecutionStack.isFinished() )
-        {
-            ExecutionStack.clear();
         }
     }
 
@@ -228,7 +170,7 @@
      * Monitored application should use a <code>try/finally</code> block to
      * ensure on of {@link #stop()} or {@link #cancel()} method is invoked, even
      * when an exception occurs. To avoid StopWatches to keep running if the
-     * application didn't follow this recommandation, the finalizer is used to
+     * application didn't follow this recommendation, the finalizer is used to
      * cancel the StopWatch and will log a educational warning.
      *
      * @see java.lang.Object#finalize()
@@ -307,16 +249,5 @@
     public Monitor getMonitor()
     {
         return monitor;
-    }
-
-    /**
-     * Enable automatic registration to the ExecutionStack and cleanup after the
-     * last stopWatch has been stopped.
-     *
-     * @param traceExecution
-     */
-    public static void setTraceExecution( boolean traceExecution )
-    {
-        DefaultStopWatch.traceExecution = traceExecution;
     }
 }

Added: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/stopwatches/ExecutionStopWatch.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/stopwatches/ExecutionStopWatch.java?rev=633810&view=auto
==============================================================================
--- commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/stopwatches/ExecutionStopWatch.java (added)
+++ commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/stopwatches/ExecutionStopWatch.java Wed Mar  5 02:48:38 2008
@@ -0,0 +1,71 @@
+/*
+ * 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.impl.stopwatches;
+
+import org.apache.commons.monitoring.ExecutionStack;
+import org.apache.commons.monitoring.Monitor;
+
+/**
+ * Derives from StopWathc default implementation to maintain a list of all
+ * topWatches involved in the running process.
+ *
+ * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
+ */
+public class ExecutionStopWatch
+    extends DefaultStopWatch
+{
+    /**
+     * @param monitor
+     */
+    public ExecutionStopWatch( Monitor monitor )
+    {
+        super( monitor );
+        ExecutionStack.push( this );
+    }
+
+    /**
+     * {@inheritDoc}
+     *
+     * @see org.apache.commons.monitoring.impl.stopwatches.DefaultStopWatch#stop()
+     */
+    @Override
+    public void stop()
+    {
+        super.stop();
+        if ( ExecutionStack.isTopLevel( this ) )
+        {
+            ExecutionStack.clear();
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     *
+     * @see org.apache.commons.monitoring.impl.stopwatches.DefaultStopWatch#cancel()
+     */
+    @Override
+    public void cancel()
+    {
+        super.cancel();
+        if ( ExecutionStack.isTopLevel( this ) )
+        {
+            ExecutionStack.clear();
+        }
+    }
+
+}

Propchange: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/stopwatches/ExecutionStopWatch.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/stopwatches/ExecutionStopWatch.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/stopwatches/ExecutionStopWatch.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Copied: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/values/AbstractStatValue.java (from r632970, commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/AbstractStatValue.java)
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/values/AbstractStatValue.java?p2=commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/values/AbstractStatValue.java&p1=commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/AbstractStatValue.java&r1=632970&r2=633810&rev=633810&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/AbstractStatValue.java (original)
+++ commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/values/AbstractStatValue.java Wed Mar  5 02:48:38 2008
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package org.apache.commons.monitoring.impl;
+package org.apache.commons.monitoring.impl.values;
 
 import java.util.List;
 import java.util.concurrent.CopyOnWriteArrayList;

Propchange: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/values/AbstractStatValue.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/values/AbstractStatValue.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/values/AbstractStatValue.java
------------------------------------------------------------------------------
    svn:mergeinfo = 

Copied: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/values/CompositeCounter.java (from r632970, commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/CompositeCounter.java)
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/values/CompositeCounter.java?p2=commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/values/CompositeCounter.java&p1=commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/CompositeCounter.java&r1=632970&r2=633810&rev=633810&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/CompositeCounter.java (original)
+++ commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/values/CompositeCounter.java Wed Mar  5 02:48:38 2008
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package org.apache.commons.monitoring.impl;
+package org.apache.commons.monitoring.impl.values;
 
 import java.util.Collection;
 import java.util.Collections;

Propchange: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/values/CompositeCounter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/values/CompositeCounter.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/values/CompositeCounter.java
------------------------------------------------------------------------------
    svn:mergeinfo = 

Propchange: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/values/CompositeCounter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Copied: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/values/CompositeGauge.java (from r632970, commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/CompositeGauge.java)
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/values/CompositeGauge.java?p2=commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/values/CompositeGauge.java&p1=commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/CompositeGauge.java&r1=632970&r2=633810&rev=633810&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/CompositeGauge.java (original)
+++ commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/values/CompositeGauge.java Wed Mar  5 02:48:38 2008
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package org.apache.commons.monitoring.impl;
+package org.apache.commons.monitoring.impl.values;
 
 import java.util.Collection;
 import java.util.Collections;

Propchange: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/values/CompositeGauge.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/values/CompositeGauge.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/values/CompositeGauge.java
------------------------------------------------------------------------------
    svn:mergeinfo = 

Propchange: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/values/CompositeGauge.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Copied: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/values/ThreadSafeCounter.java (from r632970, commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/ThreadSafeCounter.java)
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/values/ThreadSafeCounter.java?p2=commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/values/ThreadSafeCounter.java&p1=commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/ThreadSafeCounter.java&r1=632970&r2=633810&rev=633810&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/ThreadSafeCounter.java (original)
+++ commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/values/ThreadSafeCounter.java Wed Mar  5 02:48:38 2008
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package org.apache.commons.monitoring.impl;
+package org.apache.commons.monitoring.impl.values;
 
 import org.apache.commons.monitoring.Counter;
 

Propchange: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/values/ThreadSafeCounter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/values/ThreadSafeCounter.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/values/ThreadSafeCounter.java
------------------------------------------------------------------------------
    svn:mergeinfo = 

Propchange: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/values/ThreadSafeCounter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Copied: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/values/ThreadSafeGauge.java (from r632970, commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/ThreadSafeGauge.java)
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/values/ThreadSafeGauge.java?p2=commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/values/ThreadSafeGauge.java&p1=commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/ThreadSafeGauge.java&r1=632970&r2=633810&rev=633810&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/ThreadSafeGauge.java (original)
+++ commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/values/ThreadSafeGauge.java Wed Mar  5 02:48:38 2008
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package org.apache.commons.monitoring.impl;
+package org.apache.commons.monitoring.impl.values;
 
 import org.apache.commons.monitoring.Gauge;
 

Propchange: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/values/ThreadSafeGauge.java
------------------------------------------------------------------------------
    svn:mergeinfo = 

Modified: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/listeners/SecondaryMonitor.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/listeners/SecondaryMonitor.java?rev=633810&r1=633809&r2=633810&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/listeners/SecondaryMonitor.java (original)
+++ commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/listeners/SecondaryMonitor.java Wed Mar  5 02:48:38 2008
@@ -20,7 +20,7 @@
 import org.apache.commons.monitoring.Composite;
 import org.apache.commons.monitoring.Monitor;
 import org.apache.commons.monitoring.StatValue;
-import org.apache.commons.monitoring.impl.AbstractMonitor;
+import org.apache.commons.monitoring.impl.monitors.AbstractMonitor;
 
 /**
  * A Monitor implementation that maintains a set of secondary StatValues in sync
@@ -38,11 +38,11 @@
 {
 
     /** The primary monitor */
-    private Monitor monitor;
+    private Monitor.Observable monitor;
 
     private boolean detached;
 
-    public SecondaryMonitor( Monitor monitor )
+    public SecondaryMonitor( Monitor.Observable monitor )
     {
         super( monitor.getKey() );
         this.monitor = monitor;
@@ -54,6 +54,7 @@
         monitor.addListener( this );
     }
 
+    @SuppressWarnings("unchecked")
     public void detach()
     {
         this.detached = true;
@@ -66,22 +67,13 @@
         }
     }
 
+    @SuppressWarnings("unchecked")
     public void onStatValueRegistered( StatValue value )
     {
         if ( !detached && value instanceof Composite )
         {
             register( ( (Composite<StatValue>) value ).createSecondary() );
         }
-    }
-
-    public void addListener( Listener listener )
-    {
-        throw new UnsupportedOperationException( "Only primary Monitor accepts listeners" );
-    }
-
-    public void removeListener( Listener listener )
-    {
-        throw new UnsupportedOperationException( "Only primary Monitor accepts listeners" );
     }
 
 }

Modified: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/listeners/SecondaryRepository.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/listeners/SecondaryRepository.java?rev=633810&r1=633809&r2=633810&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/listeners/SecondaryRepository.java (original)
+++ commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/listeners/SecondaryRepository.java Wed Mar  5 02:48:38 2008
@@ -17,31 +17,41 @@
 
 package org.apache.commons.monitoring.listeners;
 
-import java.util.Collection;
-
 import org.apache.commons.monitoring.Monitor;
 import org.apache.commons.monitoring.Repository;
-import org.apache.commons.monitoring.impl.AbstractRepository;
+import org.apache.commons.monitoring.StopWatch;
+import org.apache.commons.monitoring.impl.repositories.AbstractRepository;
 
 /**
+ * A repository implementation that registers as a <tt>Listener</tt> to an
+ * <tt>Observable</tt> repository and maintains a set of Monitors in sync with
+ * the observed repository.
+ * <p>
+ * As a <tt>Detachable</tt> implementation, the SecondaryRepository can be
+ * detached from the observed repository and used to build a report for the
+ * observed period.
  *
  * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
  */
 public class SecondaryRepository
-    extends AbstractRepository implements Repository.Listener, Detachable
+    extends AbstractRepository
+    implements Repository.Listener, Detachable
 {
-    private Repository repository;
+    private Repository.Observable repository;
 
     private boolean detached;
 
-    public SecondaryRepository( Repository repository )
+    public SecondaryRepository( Repository.Observable repository )
     {
         super();
         this.repository = repository;
         this.detached = false;
         for ( Monitor monitor : repository.getMonitors() )
         {
-            register( new SecondaryMonitor( monitor ) );
+            if ( monitor instanceof Monitor.Observable )
+            {
+                register( new SecondaryMonitor( (Monitor.Observable) monitor ) );
+            }
         }
         repository.addListener( this );
     }
@@ -52,7 +62,7 @@
         repository.removeListener( this );
         for ( Monitor monitor : getMonitors() )
         {
-            ((Detachable) monitor).detach();
+            ( (Detachable) monitor ).detach();
         }
     }
 
@@ -61,26 +71,18 @@
      */
     public void newMonitorInstance( Monitor monitor )
     {
-        if ( ! detached )
+        if ( !detached && monitor instanceof Monitor.Observable )
         {
-            register( new SecondaryMonitor( monitor ) );
+            register( new SecondaryMonitor( (Monitor.Observable) monitor ) );
         }
     }
 
     /**
-     * @see org.apache.commons.monitoring.Repository#addListener(org.apache.commons.monitoring.Repository.Listener)
+     * {@inheritDoc}
+     * @see org.apache.commons.monitoring.Repository#start(org.apache.commons.monitoring.Monitor)
      */
-    public void addListener( Listener listener )
+    public StopWatch start( Monitor monitor )
     {
-        throw new UnsupportedOperationException( "Only primary Repository accepts listeners" );
+        throw new UnsupportedOperationException( "Not available on a secondary repository" );
     }
-
-    /**
-     * @see org.apache.commons.monitoring.Repository#removeListener(org.apache.commons.monitoring.Repository.Listener)
-     */
-    public void removeListener( Listener listener )
-    {
-        throw new UnsupportedOperationException( "Only primary Repository accepts listeners" );
-    }
-
 }

Modified: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/reporting/AbstractPeriodicLogger.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/reporting/AbstractPeriodicLogger.java?rev=633810&r1=633809&r2=633810&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/reporting/AbstractPeriodicLogger.java (original)
+++ commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/reporting/AbstractPeriodicLogger.java Wed Mar  5 02:48:38 2008
@@ -40,7 +40,7 @@
     private Timer timer;
 
     /** The observed repository */
-    private Repository repository;
+    private Repository.Observable repository;
 
     /** The observed repository */
     private SecondaryRepository secondary;
@@ -50,7 +50,7 @@
      * @param period the period (in ms) to log the monitoring state
      * @param repository the target monitoring repository
      */
-    public AbstractPeriodicLogger( long period, Repository repository )
+    public AbstractPeriodicLogger( long period, Repository.Observable repository )
     {
         super();
         this.secondary = new SecondaryRepository( repository );

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=633810&r1=633809&r2=633810&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 Wed Mar  5 02:48:38 2008
@@ -19,6 +19,11 @@
 
 import java.io.PrintWriter;
 import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
 
 import org.apache.commons.monitoring.Monitor;
 import org.apache.commons.monitoring.StatValue;
@@ -26,46 +31,93 @@
 
 /**
  * Render a collection of monitor for reporting
- * 
+ *
  * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
  */
 public abstract class AbstractRenderer
     implements Renderer
 {
-    private final Collection<String> roles;
+    public static final Renderer.Filter ALL = new Renderer.Filter()
+    {
+        public boolean render( Object object )
+        {
+            return true;
+        }
+    };
 
-    private final PrintWriter writer;
+    public final void render( PrintWriter writer, Collection<Monitor> monitors )
+    {
+        render( writer, monitors, ALL );
+    }
+
+    public void render( PrintWriter writer, Collection<Monitor> monitors, Filter filter )
+    {
+        int count = 0;
+        for ( Monitor monitor : monitors )
+        {
+            if ( filter.render( monitor ) )
+            {
+                if (count > 0)
+                {
+                    hasNext( writer, Monitor.class );
+                }
+                render( writer, monitor, filter );
+                count ++;
+            }
+        }
+    }
 
-    public AbstractRenderer( PrintWriter writer, Collection<String> roles )
+    @SuppressWarnings("unchecked")
+    protected void hasNext( PrintWriter writer, Class type )
     {
-        super();
-        this.roles = roles;
-        this.writer = writer;
+        // Nop
     }
 
-    protected void write( String string )
+    protected void render( PrintWriter writer, Monitor monitor, Filter filter )
     {
-        writer.append( string );
+        render( writer, monitor.getKey() );
+        renderStatValues( writer, monitor, filter );
     }
 
-    public void render( Collection<Monitor> monitors )
+    protected int renderStatValues( PrintWriter writer, Monitor monitor, Filter filter )
     {
-        for ( Monitor monitor : monitors )
+
+        // Sort values by role to ensure predictable result
+        List<StatValue> values = getOrderedStatValues( monitor, filter );
+        for ( Iterator<StatValue> iterator = values.iterator(); iterator.hasNext(); )
         {
-            render( monitor );
+            StatValue value = (StatValue) iterator.next();
+            render( writer, value );
+            if (iterator.hasNext())
+            {
+                hasNext( writer, StatValue.class );
+            }
         }
+        return values.size();
     }
 
-    public void render( Monitor monitor )
+    protected List<StatValue> getOrderedStatValues( Monitor monitor, Filter filter )
     {
-        render( monitor.getKey() );
-        for ( String role : roles )
+        List<StatValue> values = new LinkedList<StatValue>( monitor.getValues() );
+        for ( Iterator<StatValue> iterator = values.iterator(); iterator.hasNext(); )
         {
-            render( monitor.getValue( role ), role );
+            StatValue value = (StatValue) iterator.next();
+            if ( ! filter.render( value ))
+            {
+                iterator.remove();
+            }
         }
+        Collections.sort( values, new Comparator<StatValue>()
+        {
+            public int compare( StatValue value1, StatValue value2 )
+            {
+                return value1.getRole().compareTo( value2.getRole() );
+            }
+        });
+        return values;
     }
 
-    public abstract void render( StatValue value, String role );
+    protected abstract void render( PrintWriter writer, StatValue value );
 
-    public abstract void render( Key key );
+    protected abstract void render( PrintWriter writer, Key key );
 }

Added: 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=633810&view=auto
==============================================================================
--- commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/reporting/HtmlRenderer.java (added)
+++ commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/reporting/HtmlRenderer.java Wed Mar  5 02:48:38 2008
@@ -0,0 +1,196 @@
+/*
+ * 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 java.util.Collection;
+import java.util.List;
+
+import org.apache.commons.monitoring.Counter;
+import org.apache.commons.monitoring.Monitor;
+import org.apache.commons.monitoring.StatValue;
+import org.apache.commons.monitoring.Monitor.Key;
+
+/**
+ * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
+ */
+public class HtmlRenderer
+    extends AbstractRenderer
+{
+
+    /**
+     * {@inheritDoc}
+     *
+     * @see org.apache.commons.monitoring.reporting.AbstractRenderer#render(java.io.PrintWriter,
+     * java.util.Collection,
+     * org.apache.commons.monitoring.reporting.Renderer.Filter)
+     */
+    @Override
+    public void render( PrintWriter writer, Collection<Monitor> monitors, Filter filter )
+    {
+        documentHead( writer );
+        tableStartTag( writer );
+        tableHead( writer, monitors, filter );
+        super.render( writer, monitors, filter );
+        writer.append( "</tr></tbody>" );
+        tableEndTag( writer );
+        documentFoot( writer );
+    }
+
+    /**
+     * @param writer
+     */
+    protected void tableStartTag( PrintWriter writer )
+    {
+        writer.append( "<table>" );
+    }
+
+    /**
+     * @param writer
+     */
+    protected void tableEndTag( PrintWriter writer )
+    {
+        writer.append( "</table>" );
+    }
+
+    /**
+     * @param writer
+     */
+    protected void documentHead( PrintWriter writer )
+    {
+        writer.append( "<html><body>" );
+    }
+
+    protected void tableHead( PrintWriter writer, Collection<Monitor> monitors, Filter filter )
+    {
+        writer.append( "<thead><tr><th rowspan='2'>name</th><th rowspan='2'>category</th><th rowspan='2'>subsystem</th>" );
+        Monitor monitor = monitors.iterator().next();
+        List<StatValue> values = getOrderedStatValues( monitor, filter );
+        for ( StatValue value : values )
+        {
+            if ( value instanceof Counter )
+            {
+                writer.append( "<th colspan='7'>" );
+            }
+            else
+            {
+                writer.append( "<th colspan='5'>" );
+            }
+            writer.append( value.getRole() );
+            if ( value.getUnit() != null )
+            {
+                writer.append( " (" );
+                writer.append( value.getUnit() );
+                writer.append( ")" );
+            }
+            writer.append( "</th>" );
+        }
+        writer.append( "</tr>" );
+        writer.append( "<tr>" );
+        for ( StatValue value : values )
+        {
+            writer.append( "<th>value</th><th>min</th><th>max</th><th>mean</th><th>dev.</th>" );
+            if ( value instanceof Counter )
+            {
+                writer.append( "<th>sum</th><th>hits</th>" );
+            }
+        }
+        writer.append( "</tr></thead><tbody><tr>" );
+    }
+
+    /**
+     * {@inheritDoc}
+     *
+     * @see org.apache.commons.monitoring.reporting.AbstractRenderer#render(java.io.PrintWriter,
+     * org.apache.commons.monitoring.StatValue)
+     */
+    @Override
+    protected void render( PrintWriter writer, StatValue value )
+    {
+        writer.append( "<td title='" );
+        writer.append( value.getRole() );
+        writer.append( "'>" );
+        writer.append( String.valueOf( value.get() ) );
+        writer.append( "</td><td>" );
+        writer.append( String.valueOf( value.getMin() ) );
+        writer.append( "</td><td>" );
+        writer.append( String.valueOf( value.getMax() ) );
+        writer.append( "</td><td>" );
+        writer.append( String.valueOf( value.getMean() ) );
+        writer.append( "</td><td>" );
+        writer.append( String.valueOf( value.getStandardDeviation() ) );
+        if ( value instanceof Counter )
+        {
+            Counter counter = (Counter) value;
+            writer.append( "</td><td>" );
+            writer.append( String.valueOf( counter.getSum() ) );
+            writer.append( "</td><td>" );
+            writer.append( String.valueOf( counter.getHits() ) );
+        }
+        writer.append( "</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 )
+    {
+        writer.append( "<td>" );
+        writer.append( key.getName() );
+        writer.append( "</td><td>" );
+        if ( key.getCategory() != null )
+        {
+            writer.append( key.getCategory() );
+        }
+        writer.append( "</td><td>" );
+        if ( key.getSubsystem() != null )
+        {
+            writer.append( key.getSubsystem() );
+        }
+        writer.append( "</td>" );
+    }
+
+    /**
+     * {@inheritDoc}
+     *
+     * @see org.apache.commons.monitoring.reporting.AbstractRenderer#hasNext(java.io.PrintWriter,
+     * java.lang.Class)
+     */
+    @Override
+    protected void hasNext( PrintWriter writer, Class type )
+    {
+        if ( type == Monitor.class )
+        {
+            writer.append( "</tr><tr>" );
+        }
+    }
+
+    /**
+     * @param writer
+     */
+    protected void documentFoot( PrintWriter writer )
+    {
+        writer.append( "</body></html>" );
+    }
+
+}

Propchange: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/reporting/HtmlRenderer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/reporting/HtmlRenderer.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/reporting/HtmlRenderer.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message