commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nico...@apache.org
Subject svn commit: r618221 - in /commons/sandbox/monitoring/trunk/src: main/java/org/apache/commons/monitoring/ main/java/org/apache/commons/monitoring/impl/ main/java/org/apache/commons/monitoring/listeners/ site/resources/ site/resources/images/ test/java/o...
Date Mon, 04 Feb 2008 10:03:34 GMT
Author: nicolas
Date: Mon Feb  4 02:03:23 2008
New Revision: 618221

URL: http://svn.apache.org/viewvc?rev=618221&view=rev
Log:
secondary monitors : attach to live monitors, watch monitored activity and detach
(base for history graphs and other time-based features)

Added:
    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   (with props)
    commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/ListenableMonitor.java
      - copied, changed from r616771, 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/listeners/Detachable.java   (with props)
    commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/listeners/SecondaryMonitor.java   (with props)
    commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/listeners/SecondaryRepository.java   (with props)
    commons/sandbox/monitoring/trunk/src/site/resources/
    commons/sandbox/monitoring/trunk/src/site/resources/images/
    commons/sandbox/monitoring/trunk/src/site/resources/images/monitoring-logo-white.png   (with props)
    commons/sandbox/monitoring/trunk/src/site/resources/images/monitoring-logo-white.xcf   (with props)
    commons/sandbox/monitoring/trunk/src/test/java/org/apache/commons/monitoring/listener/SecondaryReposioryTest.java   (with props)
Modified:
    commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/Composite.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/StopWatch.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/ThreadSafeCounter.java
    commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/ThreadSafeGauge.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/ThreadSafeCounterTest.java
    commons/sandbox/monitoring/trunk/src/test/java/org/apache/commons/monitoring/impl/ThreadSafeGaugeTest.java

Modified: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/Composite.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/Composite.java?rev=618221&r1=618220&r2=618221&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/Composite.java (original)
+++ commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/Composite.java Mon Feb  4 02:03:23 2008
@@ -33,13 +33,15 @@
     Collection<T> getSecondary();
 
     /**
-     * Register a secondary instance
+     * Create a secondary instance
+     *
      * @param secondary
      */
-    public void addSecondary( T secondary );
+    public T createSecondary();
 
     /**
      * Deregister a secondary instance
+     *
      * @param secondary
      */
     public void removeSecondary( T secondary );

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=618221&r1=618220&r2=618221&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 Mon Feb  4 02:03:23 2008
@@ -17,6 +17,9 @@
 
 package org.apache.commons.monitoring;
 
+import java.util.Collection;
+
+
 /**
  * A <code>Monitor</code> is an abstraction of some application resource that
  * is instrumented with a set of indicators (Gauges or Counters).
@@ -85,6 +88,18 @@
     StatValue getValue( String role );
 
     /**
+     *
+     * @return an unmodifiable collection of registered statValues roles
+     */
+    Collection<String> getRoles();
+
+    /**
+     *
+     * @return an unmodifiable collection of registered statValues
+     */
+    Collection<StatValue> getValues();
+
+    /**
      * Reset all StatValues (don't remove them)
      */
     void reset();
@@ -205,5 +220,14 @@
             return subsystem;
         }
 
+    }
+
+    void addListener( Listener listener );
+
+    void removeListener( Listener listener );
+
+    public static interface Listener
+    {
+        void onStatValueRegistered( StatValue value );
     }
 }

Modified: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/StopWatch.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/StopWatch.java?rev=618221&r1=618220&r2=618221&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/StopWatch.java (original)
+++ commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/StopWatch.java Mon Feb  4 02:03:23 2008
@@ -57,7 +57,7 @@
     {
         super();
         this.monitor = monitor;
-        startedAt = nanotime();
+        startedAt = time();
         if ( monitor != null )
         {
             monitor.getGauge( Monitor.CONCURRENCY ).increment();
@@ -81,7 +81,7 @@
         else
         {
             // Still running !
-            delay = nanotime() - startedAt - pauseDelay;
+            delay = time() - startedAt - pauseDelay;
         }
         return delay;
     }
@@ -94,7 +94,7 @@
     {
         if ( !paused && !stoped )
         {
-            stopedAt = nanotime();
+            stopedAt = time();
             paused = true;
         }
     }
@@ -106,7 +106,7 @@
     {
         if ( paused && !stoped )
         {
-            pauseDelay = nanotime() - stopedAt;
+            pauseDelay = time() - stopedAt;
             paused = false;
             stopedAt = 0;
         }
@@ -120,7 +120,7 @@
     {
         if ( !stoped )
         {
-            long t = nanotime();
+            long t = time();
             if ( paused )
             {
                 pauseDelay = t - stopedAt;
@@ -210,17 +210,16 @@
     }
 
     /**
-     * Returns the current value of the most precise available system timer, in
-     * nanoseconds. The real precision depends on the JVM and the underlying
-     * system. On JRE before java5, <tt>backport-util-concurrent</tt> provides
-     * some limited support for equivalent timer.
+     * Simple benchmark demonstrates that java5 System.currentTimeMillis is FAR
+     * quicker than System.nanoTime. The lack of precision for using ms as time
+     * unit is not blocking for a monitoring toolkit (it may be for a profiler)
      *
-     * @see System#nanoTime()
-     * @return time in nanosecond
+     * @return time with ms precision
+     * @see org.apache.commons.monitoring.bench.CurrentTimeMillisVsNanoTime
      */
-    protected long nanotime()
+    protected long time()
     {
-        return System.nanoTime();
+        return System.currentTimeMillis();
     }
 
     /**

Added: 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/AbstractMonitor.java?rev=618221&view=auto
==============================================================================
--- commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/AbstractMonitor.java (added)
+++ commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/AbstractMonitor.java Mon Feb  4 02:03:23 2008
@@ -0,0 +1,108 @@
+/*
+ * 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;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
+import org.apache.commons.monitoring.Counter;
+import org.apache.commons.monitoring.Gauge;
+import org.apache.commons.monitoring.Monitor;
+import org.apache.commons.monitoring.StatValue;
+
+/**
+ * Abstract {@link Monitor} implementation with implementation for base methods
+ *
+ * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
+ */
+public abstract class AbstractMonitor implements Monitor
+{
+
+    private final ConcurrentMap<String, StatValue> values;
+    private final Key key;
+
+    public AbstractMonitor( Key key )
+    {
+        super();
+        this.key = key;
+        this.values = new ConcurrentHashMap<String, StatValue>();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public final Key getKey()
+    {
+        return key;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public final StatValue getValue( String role )
+    {
+        return values.get( role );
+    }
+
+    public final Collection<String> getRoles()
+    {
+        return Collections.unmodifiableCollection( values.keySet() );
+    }
+
+    public final Collection<StatValue> getValues()
+    {
+        return Collections.unmodifiableCollection( values.values() );
+    }
+
+    /**
+     * Register a new StatValue in the monitor
+     *
+     * @param value StatValue instance to get registered
+     * @return a previously registered StatValue if existed, or <code>null</code>
+     * if value has been successfully registered
+     */
+    protected <T extends StatValue> T register( T value )
+    {
+        value.setMonitor( this );
+        return (T) values.putIfAbsent( value.getRole(), value );
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void reset()
+    {
+        for ( StatValue value : values.values() )
+        {
+            value.reset();
+        }
+    }
+
+    public Counter getCounter( String role )
+    {
+        return (Counter) getValue( role );
+    }
+
+    public Gauge getGauge( String role )
+    {
+        return (Gauge) getValue( role );
+    }
+
+}
\ No newline at end of file

Added: 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/AbstractRepository.java?rev=618221&view=auto
==============================================================================
--- commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/AbstractRepository.java (added)
+++ commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/AbstractRepository.java Mon Feb  4 02:03:23 2008
@@ -0,0 +1,139 @@
+/*
+ * 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;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
+import org.apache.commons.monitoring.Monitor;
+import org.apache.commons.monitoring.Repository;
+import org.apache.commons.monitoring.Monitor.Key;
+
+/**
+ * Abstract implementation of {@link Repository} with support for base methods
+ *
+ * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
+ */
+public abstract class AbstractRepository
+    implements Repository
+{
+    private final ConcurrentMap<Monitor.Key, Monitor> monitors;
+
+    public AbstractRepository()
+    {
+        super();
+        this.monitors = new ConcurrentHashMap<Monitor.Key, Monitor>( 50 );
+    }
+
+    public Monitor getMonitor( String name )
+    {
+        return getMonitor( name, null, null );
+    }
+
+    public Monitor getMonitor( String name, String category )
+    {
+        return getMonitor( name, category, null );
+    }
+
+    public Monitor getMonitor( String name, String category, String subsystem )
+    {
+        return getMonitor( new Monitor.Key( name, category, subsystem ) );
+    }
+
+    protected Monitor getMonitor( Key key )
+    {
+        return monitors.get( key );
+    }
+
+    /**
+     * Register a new monitor in the repository
+     *
+     * @param monitor Monitor instance to get registered
+     * @return a previously registered monitor if existed, or <code>null</code>
+     * if monitor has been successfully registered
+     */
+    protected Monitor register( Monitor monitor )
+    {
+        return monitors.putIfAbsent( monitor.getKey(), monitor );
+    }
+
+    public Set<String> getCategories()
+    {
+        Set<String> categories = new HashSet<String>();
+        for ( Key key : monitors.keySet() )
+        {
+            categories.add( key.getCategory() );
+        }
+        return categories;
+    }
+
+    public Set<String> getSubSystems()
+    {
+        Set<String> subsystems = new HashSet<String>();
+        for ( Key key : monitors.keySet() )
+        {
+            subsystems.add( key.getSubsystem() );
+        }
+        return subsystems;
+    }
+
+    public Collection<Monitor> getMonitors()
+    {
+        return Collections.unmodifiableCollection( monitors.values() );
+    }
+
+    public Collection<Monitor> getMonitorsFromCategory( String category )
+    {
+        Collection<Monitor> filtered = new LinkedList<Monitor>();
+        for ( Monitor monitor : monitors.values() )
+        {
+            if ( category.equals( monitor.getKey().getCategory() ) )
+            {
+                filtered.add( monitor );
+            }
+        }
+        return filtered;
+    }
+
+    public Collection<Monitor> getMonitorsFromSubSystem( String subsystem )
+    {
+        Collection<Monitor> filtered = new LinkedList<Monitor>();
+        for ( Monitor monitor : monitors.values() )
+        {
+            if ( subsystem.equals( monitor.getKey().getSubsystem() ) )
+            {
+                filtered.add( monitor );
+            }
+        }
+        return filtered;
+    }
+
+    public void reset()
+    {
+        for ( Monitor monitor : monitors.values() )
+        {
+            monitor.reset();
+        }
+    }
+
+}
\ No newline at end of file

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

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

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

Modified: 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/AbstractStatValue.java?rev=618221&r1=618220&r2=618221&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/AbstractStatValue.java Mon Feb  4 02:03:23 2008
@@ -46,6 +46,12 @@
 
     private List<Listener> listeners = new CopyOnWriteArrayList<Listener>();
 
+    public AbstractStatValue( String role )
+    {
+        super();
+        this.role = role;
+    }
+
     public void addListener( Listener listener )
     {
         listeners.add( listener );

Modified: 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/CompositeCounter.java?rev=618221&r1=618220&r2=618221&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/CompositeCounter.java Mon Feb  4 02:03:23 2008
@@ -43,15 +43,17 @@
         return Collections.unmodifiableCollection( secondary );
     }
 
-    public CompositeCounter()
+    public CompositeCounter( String role )
     {
-        super();
+        super( role );
         this.secondary = new CopyOnWriteArrayList<Counter>();
     }
 
-    public void addSecondary( Counter counter )
+    public Counter createSecondary()
     {
+        Counter counter = new ThreadSafeCounter( getRole() );
         secondary.add( counter );
+        return counter;
     }
 
     public void removeSecondary( Counter counter )

Modified: 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/CompositeGauge.java?rev=618221&r1=618220&r2=618221&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/CompositeGauge.java Mon Feb  4 02:03:23 2008
@@ -43,16 +43,19 @@
         return Collections.unmodifiableCollection( secondary );
     }
 
-    public CompositeGauge()
+    public CompositeGauge( String role )
     {
-        super();
+        super( role );
         this.secondary = new LinkedList<Gauge>();
     }
 
-    public synchronized void addSecondary( Gauge gauge )
+    public synchronized Gauge createSecondary()
     {
+        // Must be synchronized to ensure the new gauge shares the primary initial value
+        Gauge gauge = new ThreadSafeGauge( getRole() );
         gauge.set( get() );
         secondary.add( gauge );
+        return gauge;
     }
 
     public synchronized void removeSecondary( Gauge gauge )

Modified: 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/CompositeValuesMonitor.java?rev=618221&r1=618220&r2=618221&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/CompositeValuesMonitor.java Mon Feb  4 02:03:23 2008
@@ -34,15 +34,15 @@
     }
 
     @Override
-    protected Counter newCounterInstance()
+    protected Counter newCounterInstance( String role )
     {
-        return new CompositeCounter();
+        return new CompositeCounter( role );
     }
 
     @Override
-    protected Gauge newGaugeInstance()
+    protected Gauge newGaugeInstance( String role )
     {
-        return new CompositeGauge();
+        return new CompositeGauge( role );
     }
 
 }

Modified: 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/CreateValuesOnDemandMonitor.java?rev=618221&r1=618220&r2=618221&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/CreateValuesOnDemandMonitor.java Mon Feb  4 02:03:23 2008
@@ -28,7 +28,7 @@
  * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
  */
 public class CreateValuesOnDemandMonitor
-    extends AbstractMonitor
+    extends ListenableMonitor
 {
 
     public CreateValuesOnDemandMonitor( Key key )
@@ -39,6 +39,7 @@
     /**
      * Retrieve a Counter or create a new one for the role
      */
+    @Override
     public Counter getCounter( String role )
     {
         Counter counter = (Counter) getValue( role );
@@ -46,20 +47,24 @@
         {
             return counter;
         }
-        return register( newCounterInstance(), role );
+        counter = newCounterInstance( role );
+        Counter previous = register( counter );
+        return previous != null ? previous : counter;
     }
 
     /**
      * Create a new Counter instance
      */
-    protected Counter newCounterInstance()
+    protected Counter newCounterInstance( String role )
     {
-        return new ThreadSafeCounter();
+        return new ThreadSafeCounter( role );
+
     }
 
     /**
      * Retrieve a Gauge or create a new one for the role
      */
+    @Override
     public Gauge getGauge( String role )
     {
         Gauge gauge = (Gauge) getValue( role );
@@ -67,15 +72,17 @@
         {
             return gauge;
         }
-        return register( newGaugeInstance(), role );
+        gauge = newGaugeInstance( role );
+        Gauge previous = register( gauge );
+        return previous != null ? previous : gauge;
     }
 
     /**
      * Create a new Gauge instance
      */
-    protected Gauge newGaugeInstance()
+    protected Gauge newGaugeInstance( String role )
     {
-        return new ThreadSafeGauge();
+        return  new ThreadSafeGauge( role );
     }
 
 }

Modified: 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/DefaultRepository.java?rev=618221&r1=618220&r2=618221&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/DefaultRepository.java Mon Feb  4 02:03:23 2008
@@ -17,32 +17,19 @@
 
 package org.apache.commons.monitoring.impl;
 
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.LinkedList;
 import java.util.List;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
 import java.util.concurrent.CopyOnWriteArrayList;
 
 import org.apache.commons.monitoring.Monitor;
-import org.apache.commons.monitoring.Repository;
-import org.apache.commons.monitoring.Monitor.Key;
 
-public class DefaultRepository
-    implements Repository
+public class DefaultRepository extends AbstractRepository
 {
 
-    public final ConcurrentMap<Monitor.Key, Monitor> monitors;
-
     private List<Listener> listeners = new CopyOnWriteArrayList<Listener>();
 
     public DefaultRepository()
     {
         super();
-        this.monitors = new ConcurrentHashMap<Monitor.Key, Monitor>( 50 );
     }
 
     public void addListener( Listener listener )
@@ -55,97 +42,27 @@
         listeners.remove( listener );
     }
 
-    public Monitor getMonitor( String name )
-    {
-        return getMonitor( name, null, null );
-    }
-
-    public Monitor getMonitor( String name, String category )
-    {
-        return getMonitor( name, category, null );
-    }
-
-    public Set<String> getCategories()
-    {
-        Set<String> categories = new HashSet<String>();
-        for ( Key key : monitors.keySet() )
-        {
-            categories.add( key.getCategory() );
-        }
-        return categories;
-    }
-
-    public Set<String> getSubSystems()
-    {
-        Set<String> subsystems = new HashSet<String>();
-        for ( Key key : monitors.keySet() )
-        {
-            subsystems.add( key.getSubsystem() );
-        }
-        return subsystems;
-    }
-
-    public Monitor getMonitor( String name, String category, String subsystem )
+    public Monitor getMonitor( Monitor.Key key )
     {
-        Monitor.Key key = new Monitor.Key( name, null, null );
-        Monitor monitor = monitors.get( key );
+        Monitor monitor = super.getMonitor( key );
         if ( monitor == null )
         {
             monitor = newMonitorInstance( key );
-
-            Monitor previous = monitors.putIfAbsent( key, monitor );
+            Monitor previous = register( monitor );
             if ( previous != null )
             {
-                monitor = previous;
-            }
-        }
-        return monitor;
-    }
-
-    protected Monitor newMonitorInstance( Monitor.Key key )
-    {
-        Monitor monitor;
-        monitor = new CompositeValuesMonitor( key );
-        return monitor;
-    }
-
-    public Collection<Monitor> getMonitors()
-    {
-        return Collections.unmodifiableCollection( monitors.values() );
-    }
-
-    public Collection<Monitor> getMonitorsFromCategory( String category )
-    {
-        Collection<Monitor> filtered = new LinkedList<Monitor>();
-        for ( Monitor monitor : monitors.values() )
-        {
-            if ( category.equals( monitor.getKey().getCategory() ) )
-            {
-                filtered.add( monitor );
+                return  previous;
             }
-        }
-        return filtered;
-    }
-
-    public Collection<Monitor> getMonitorsFromSubSystem( String subsystem )
-    {
-        Collection<Monitor> filtered = new LinkedList<Monitor>();
-        for ( Monitor monitor : monitors.values() )
-        {
-            if ( subsystem.equals( monitor.getKey().getSubsystem() ) )
+            for ( Listener listener : listeners )
             {
-                filtered.add( monitor );
+                listener.newMonitorInstance( monitor );
             }
         }
-        return filtered;
+        return monitor;
     }
 
-
-    public void reset()
+    protected Monitor newMonitorInstance( Monitor.Key key )
     {
-        for ( Monitor monitor : monitors.values() )
-        {
-            monitor.reset();
-        }
+        return new CompositeValuesMonitor( key );
     }
 }

Copied: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/ListenableMonitor.java (from r616771, 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/ListenableMonitor.java?p2=commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/ListenableMonitor.java&p1=commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/AbstractMonitor.java&r1=616771&r2=618221&rev=618221&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/ListenableMonitor.java Mon Feb  4 02:03:23 2008
@@ -17,74 +17,62 @@
 
 package org.apache.commons.monitoring.impl;
 
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
 
 import org.apache.commons.monitoring.Monitor;
 import org.apache.commons.monitoring.StatValue;
 
 /**
- * Abstract {@link Monitor} implementation with implementation fo base methods
+ * <code>Monitor</code> implementation with support for listeners
  *
  * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
  */
-public abstract class AbstractMonitor implements Monitor
+public abstract class ListenableMonitor extends AbstractMonitor implements Monitor
 {
 
-    protected final ConcurrentMap<String, StatValue> values;
-    protected final Key key;
+    private List<Listener> listeners;
 
     /**
      * Constructor
      * @param key the monitor identifier
      */
-    public AbstractMonitor( Key key )
+    public ListenableMonitor( Key key )
     {
-        super();
-        this.key = key;
-        this.values = new ConcurrentHashMap<String, StatValue>();
+        super( key );
+        this.listeners = new CopyOnWriteArrayList<Listener>();
     }
 
 
     /**
-     * {@inheritDoc}
-     */
-    public Key getKey()
-    {
-        return key;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public StatValue getValue( String role )
-    {
-        return values.get( role );
-    }
-
-    /**
      * Register the StatValue for the role, if none was registered before
      * @param value
      * @param role
      * @return the value registered, or a previously existing one
      */
-    public <T extends StatValue> T register( T value, String role )
+    @Override
+    protected <T extends StatValue> T register( T value )
     {
-        value.setMonitor( this );
-        value.setRole( role );
-        T previous = (T) values.putIfAbsent( role, value );
-        return previous != null ? previous : value;
+        T previous = (T) super.register( value );
+        if (previous != null)
+        {
+            return previous;
+        }
+        for ( Listener listener : listeners )
+        {
+            listener.onStatValueRegistered( value );
+        }
+        return null;
     }
 
-    /**
-     * {@inheritDoc}
-     */
-    public void reset()
+
+    public void addListener( Listener listener )
     {
-        for ( StatValue value : values.values() )
-        {
-            value.reset();
-        }
+        listeners.add( listener );
     }
 
+    public void removeListener( Listener listener )
+    {
+        listeners.remove( listener );
+    }
 }

Modified: 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/ThreadSafeCounter.java?rev=618221&r1=618220&r2=618221&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/ThreadSafeCounter.java Mon Feb  4 02:03:23 2008
@@ -29,11 +29,17 @@
     extends AbstractStatValue
     implements Counter
 {
+
     private long value;
 
     private long sum;
 
     private long sumOfSquares;
+
+    public ThreadSafeCounter( String role )
+    {
+        super( role );
+    }
 
     /**
      * {@inheritDoc}

Modified: 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/ThreadSafeGauge.java?rev=618221&r1=618220&r2=618221&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/ThreadSafeGauge.java Mon Feb  4 02:03:23 2008
@@ -43,6 +43,11 @@
     // Use a double so that unset can be detected as "Not a Number"
     private double firstUse = Double.NaN;
 
+    public ThreadSafeGauge( String role )
+    {
+        super( role );
+    }
+
     public synchronized void reset()
     {
         // Don't reset value !
@@ -100,7 +105,7 @@
 
     protected void computeSums()
     {
-        long now = nanoTime();
+        long now = time();
         if ( Double.isNaN( firstUse ) )
         {
             firstUse = now;
@@ -115,15 +120,15 @@
         lastUse = now;
     }
 
-    protected long nanoTime()
+    protected long time()
     {
-        return System.nanoTime();
+        return System.currentTimeMillis();
     }
 
     @Override
     public synchronized double getMean()
     {
-        return ( (double) sum ) / ( nanoTime() - firstUse );
+        return ( (double) sum ) / ( time() - firstUse );
     }
 
     @Override

Added: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/listeners/Detachable.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/listeners/Detachable.java?rev=618221&view=auto
==============================================================================
--- commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/listeners/Detachable.java (added)
+++ commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/listeners/Detachable.java Mon Feb  4 02:03:23 2008
@@ -0,0 +1,30 @@
+/*
+ * 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.listeners;
+
+/**
+ * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
+ */
+public interface Detachable
+{
+    /**
+     * Detach the instance from live monitoring beackbone. Any new monitoring
+     * event will not affect datas in this component.
+     */
+    void detach();
+}

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

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

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

Added: 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=618221&view=auto
==============================================================================
--- commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/listeners/SecondaryMonitor.java (added)
+++ commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/listeners/SecondaryMonitor.java Mon Feb  4 02:03:23 2008
@@ -0,0 +1,87 @@
+/*
+ * 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.listeners;
+
+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;
+
+/**
+ * A Monitor implementation that maintains a set of secondary StatValues in sync
+ * with the primary monitor. Register itself as a monitor listener to get notified
+ * on new StatValues and automatically create the required secondary.
+ * <p>
+ * When detached, deregister itself as Monitor.Listener and detaches all secondary
+ * from the primary StatValues.
+ *
+ * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
+ */
+public class SecondaryMonitor
+    extends AbstractMonitor
+    implements Monitor.Listener, Detachable
+{
+
+    /** The primary monitor */
+    private Monitor monitor;
+
+    private boolean detached;
+
+    public SecondaryMonitor( Monitor monitor )
+    {
+        super( monitor.getKey() );
+        this.monitor = monitor;
+        this.detached = false;
+        for ( StatValue value : monitor.getValues() )
+        {
+            onStatValueRegistered(  value );
+        }
+        monitor.addListener( this );
+    }
+
+    public void detach()
+    {
+        this.detached = true;
+        for ( StatValue value : monitor.getValues() )
+        {
+            if ( value instanceof Composite )
+            {
+                ( (Composite<StatValue>) value ).removeSecondary( getValue( value.getRole() ) );
+            }
+        }
+    }
+
+    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" );
+    }
+
+}

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

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

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

Added: 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=618221&view=auto
==============================================================================
--- commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/listeners/SecondaryRepository.java (added)
+++ commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/listeners/SecondaryRepository.java Mon Feb  4 02:03:23 2008
@@ -0,0 +1,86 @@
+/*
+ * 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.listeners;
+
+import java.util.Collection;
+
+import org.apache.commons.monitoring.Monitor;
+import org.apache.commons.monitoring.Repository;
+import org.apache.commons.monitoring.impl.AbstractRepository;
+
+/**
+ *
+ * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
+ */
+public class SecondaryRepository
+    extends AbstractRepository implements Repository.Listener, Detachable
+{
+    private Repository repository;
+
+    private boolean detached;
+
+    public SecondaryRepository( Repository repository )
+    {
+        super();
+        this.repository = repository;
+        this.detached = false;
+        for ( Monitor monitor : repository.getMonitors() )
+        {
+            register( new SecondaryMonitor( monitor ) );
+        }
+        repository.addListener( this );
+    }
+
+    public void detach()
+    {
+        detached = true;
+        repository.removeListener( this );
+        for ( Monitor monitor : getMonitors() )
+        {
+            ((Detachable) monitor).detach();
+        }
+    }
+
+    /**
+     * @see org.apache.commons.monitoring.Repository.Listener#newMonitorInstance(org.apache.commons.monitoring.Monitor)
+     */
+    public void newMonitorInstance( Monitor monitor )
+    {
+        if ( ! detached )
+        {
+            register( new SecondaryMonitor( monitor ) );
+        }
+    }
+
+    /**
+     * @see org.apache.commons.monitoring.Repository#addListener(org.apache.commons.monitoring.Repository.Listener)
+     */
+    public void addListener( Listener listener )
+    {
+        throw new UnsupportedOperationException( "Only primary Repository accepts listeners" );
+    }
+
+    /**
+     * @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" );
+    }
+
+}

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

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

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

Added: commons/sandbox/monitoring/trunk/src/site/resources/images/monitoring-logo-white.png
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/src/site/resources/images/monitoring-logo-white.png?rev=618221&view=auto
==============================================================================
Binary file - no diff available.

Propchange: commons/sandbox/monitoring/trunk/src/site/resources/images/monitoring-logo-white.png
------------------------------------------------------------------------------
    svn:mime-type = image/png

Added: commons/sandbox/monitoring/trunk/src/site/resources/images/monitoring-logo-white.xcf
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/src/site/resources/images/monitoring-logo-white.xcf?rev=618221&view=auto
==============================================================================
Binary file - no diff available.

Propchange: commons/sandbox/monitoring/trunk/src/site/resources/images/monitoring-logo-white.xcf
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Modified: commons/sandbox/monitoring/trunk/src/test/java/org/apache/commons/monitoring/StopWatchTest.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/src/test/java/org/apache/commons/monitoring/StopWatchTest.java?rev=618221&r1=618220&r2=618221&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/src/test/java/org/apache/commons/monitoring/StopWatchTest.java (original)
+++ commons/sandbox/monitoring/trunk/src/test/java/org/apache/commons/monitoring/StopWatchTest.java Mon Feb  4 02:03:23 2008
@@ -104,7 +104,7 @@
             super( monitor );
         }
 
-        protected long nanotime()
+        protected long time()
         {
             return time;
         }

Modified: commons/sandbox/monitoring/trunk/src/test/java/org/apache/commons/monitoring/impl/CompositeValuesMonitorTest.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/src/test/java/org/apache/commons/monitoring/impl/CompositeValuesMonitorTest.java?rev=618221&r1=618220&r2=618221&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/src/test/java/org/apache/commons/monitoring/impl/CompositeValuesMonitorTest.java (original)
+++ commons/sandbox/monitoring/trunk/src/test/java/org/apache/commons/monitoring/impl/CompositeValuesMonitorTest.java Mon Feb  4 02:03:23 2008
@@ -51,14 +51,14 @@
     {
         Monitor monitor = new CompositeValuesMonitor( new Monitor.Key( "MonitorTest.testComposite", "test", "utils" ) );
         Counter counter = monitor.getCounter( "COUNTER" );
-        Counter secondary = new ThreadSafeCounter();
         Composite<Counter> composite = (Composite<Counter>) counter;
 
         counter.add( 1 );
         assertEquals( 1, counter.get() );
+
+        Counter secondary = composite.createSecondary();
         assertEquals( 0, secondary.get() );
 
-        composite.addSecondary( secondary );
         counter.add( 1 );
         assertEquals( 2, counter.get() );
         assertEquals( 1, secondary.get() );
@@ -78,14 +78,13 @@
     {
         Monitor monitor = new CompositeValuesMonitor( new Monitor.Key( "MonitorTest.testComposite", "test", "utils" ) );
         Gauge gauge = monitor.getGauge( "GAUGE" );
-        Gauge secondary = new ThreadSafeGauge();
         Composite<Gauge> composite = (Composite<Gauge>) gauge;
 
         gauge.increment();
         assertEquals( 1, gauge.get() );
+        Gauge secondary = composite.createSecondary();
         assertEquals( 0, secondary.get() );
 
-        composite.addSecondary( secondary );
         gauge.increment();
         assertEquals( 2, gauge.get() );
         assertEquals( 2, secondary.get() );

Modified: commons/sandbox/monitoring/trunk/src/test/java/org/apache/commons/monitoring/impl/ThreadSafeCounterTest.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/src/test/java/org/apache/commons/monitoring/impl/ThreadSafeCounterTest.java?rev=618221&r1=618220&r2=618221&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/src/test/java/org/apache/commons/monitoring/impl/ThreadSafeCounterTest.java (original)
+++ commons/sandbox/monitoring/trunk/src/test/java/org/apache/commons/monitoring/impl/ThreadSafeCounterTest.java Mon Feb  4 02:03:23 2008
@@ -28,7 +28,7 @@
     public void testValue()
         throws Exception
     {
-        Counter counter = new ThreadSafeCounter();
+        Counter counter = new ThreadSafeCounter( "test" );
 
         counter.set( 1 );
         assertEquals( 1, counter.getMin() );

Modified: commons/sandbox/monitoring/trunk/src/test/java/org/apache/commons/monitoring/impl/ThreadSafeGaugeTest.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/src/test/java/org/apache/commons/monitoring/impl/ThreadSafeGaugeTest.java?rev=618221&r1=618220&r2=618221&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/src/test/java/org/apache/commons/monitoring/impl/ThreadSafeGaugeTest.java (original)
+++ commons/sandbox/monitoring/trunk/src/test/java/org/apache/commons/monitoring/impl/ThreadSafeGaugeTest.java Mon Feb  4 02:03:23 2008
@@ -29,7 +29,7 @@
     public void testValue()
         throws Exception
     {
-        Gauge gauge = new ThreadSafeGauge();
+        Gauge gauge = new ThreadSafeGauge( "test" );
 
         gauge.set( 1 );
         assertEquals( 1, gauge.getMin() );
@@ -68,7 +68,7 @@
     public void testCompteMean()
         throws Exception
     {
-        Gauge gauge = new MockTimeGauge();
+        Gauge gauge = new MockTimeGauge( "test" );
 
         time = 0;
         gauge.increment();
@@ -84,11 +84,23 @@
         assertEquals( 1.5D, gauge.getMean(), 0D );
     }
 
+    /**
+     * A custom ThreadSafeGauge that use a mock nanoTime implementation to make
+     * timing predictable during unit test execution.
+     *
+     * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
+     */
     private class MockTimeGauge
         extends ThreadSafeGauge
     {
+
+        public MockTimeGauge( String role )
+        {
+            super( role );
+        }
+
         @Override
-        protected long nanoTime()
+        protected long time()
         {
             return time;
         }

Added: commons/sandbox/monitoring/trunk/src/test/java/org/apache/commons/monitoring/listener/SecondaryReposioryTest.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/src/test/java/org/apache/commons/monitoring/listener/SecondaryReposioryTest.java?rev=618221&view=auto
==============================================================================
--- commons/sandbox/monitoring/trunk/src/test/java/org/apache/commons/monitoring/listener/SecondaryReposioryTest.java (added)
+++ commons/sandbox/monitoring/trunk/src/test/java/org/apache/commons/monitoring/listener/SecondaryReposioryTest.java Mon Feb  4 02:03:23 2008
@@ -0,0 +1,66 @@
+/*
+ * 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.listener;
+
+import org.apache.commons.monitoring.Repository;
+import org.apache.commons.monitoring.impl.DefaultRepository;
+import org.apache.commons.monitoring.listeners.SecondaryRepository;
+
+import junit.framework.TestCase;
+
+/**
+ *
+ * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
+ */
+public class SecondaryReposioryTest
+    extends TestCase
+{
+    public void testSecondaryRepository()
+        throws Exception
+    {
+        Repository primary = new DefaultRepository();
+        primary.getMonitor( "test" ).getCounter( "COUNTER" ).add( 10 );
+        primary.getMonitor( "test" ).getGauge( "GAUGE" ).set( 5 );
+
+        SecondaryRepository secondary = new SecondaryRepository( primary );
+        assertNotNull( secondary.getMonitor( "test" ) );
+        assertNotNull( secondary.getMonitor( "test" ).getCounter( "COUNTER" ) );
+        assertNotNull( secondary.getMonitor( "test" ).getGauge( "GAUGE" ) );
+        assertEquals( 0, secondary.getMonitor( "test" ).getCounter( "COUNTER" ).get() );
+        assertEquals( 5, secondary.getMonitor( "test" ).getGauge( "GAUGE" ).get() );
+
+        primary.getMonitor( "test" ).getCounter( "COUNTER" ).add( 10 );
+        primary.getMonitor( "test" ).getGauge( "GAUGE" ).increment();
+        assertEquals( 10, secondary.getMonitor( "test" ).getCounter( "COUNTER" ).get() );
+        assertEquals( 6, secondary.getMonitor( "test" ).getGauge( "GAUGE" ).get() );
+
+        primary.getMonitor( "new" ).getCounter( "COUNTER" ).add( 10 );
+        assertEquals( 10, secondary.getMonitor( "new" ).getCounter( "COUNTER" ).get() );
+
+        secondary.detach();
+
+        primary.getMonitor( "anotherone" ).getCounter( "COUNTER" ).add( 10 );
+        primary.getMonitor( "test" ).getCounter( "COUNTER" ).add( 10 );
+        primary.getMonitor( "test" ).getGauge( "GAUGE" ).increment();
+        assertNull( secondary.getMonitor( "anotherone" ) );
+        assertEquals( 30, primary.getMonitor( "test" ).getCounter( "COUNTER" ).get() );
+        assertEquals( 10, secondary.getMonitor( "test" ).getCounter( "COUNTER" ).get() );
+        assertEquals( 7, primary.getMonitor( "test" ).getGauge( "GAUGE" ).get() );
+        assertEquals( 6, secondary.getMonitor( "test" ).getGauge( "GAUGE" ).get() );
+    }
+}

Propchange: commons/sandbox/monitoring/trunk/src/test/java/org/apache/commons/monitoring/listener/SecondaryReposioryTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/sandbox/monitoring/trunk/src/test/java/org/apache/commons/monitoring/listener/SecondaryReposioryTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: commons/sandbox/monitoring/trunk/src/test/java/org/apache/commons/monitoring/listener/SecondaryReposioryTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message