You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ni...@apache.org on 2008/04/07 12:35:51 UTC

svn commit: r645449 - /commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/reporting/AbstractPeriodicLogger.java

Author: nicolas
Date: Mon Apr  7 03:35:50 2008
New Revision: 645449

URL: http://svn.apache.org/viewvc?rev=645449&view=rev
Log: (empty)

Modified:
    commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/reporting/AbstractPeriodicLogger.java

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=645449&r1=645448&r2=645449&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 Mon Apr  7 03:35:50 2008
@@ -45,7 +45,6 @@
     /** The observed repository */
     private SecondaryRepository secondary;
 
-
     /**
      * @param period the period (in ms) to log the monitoring state
      * @param repository the target monitoring repository
@@ -53,11 +52,23 @@
     public AbstractPeriodicLogger( long period, Repository.Observable repository )
     {
         super();
-        this.secondary = new SecondaryRepository( repository );
+        this.repository = repository;
+        observeRepositoryForPeriod();
         timer = new Timer();
         timer.scheduleAtFixedRate( this, period, period );
     }
 
+    private SecondaryRepository observeRepositoryForPeriod()
+    {
+        SecondaryRepository previous = this.secondary;
+        this.secondary = new SecondaryRepository( repository );
+        if (previous != null)
+        {
+            previous.detach();
+        }
+        return previous;
+    }
+
     /**
      *
      */
@@ -76,15 +87,11 @@
     {
         try
         {
-            // Create a new observer for the next period
-            SecondaryRepository period = secondary;
-            period.detach();
-            secondary = new SecondaryRepository( repository );
-
-            log( period );
+            log( observeRepositoryForPeriod() );
         }
         catch (Exception exception)
         {
+            System.err.print( exception );
             // catch any exception, as throwing it will stop the timer
         }
     }