You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@excalibur.apache.org by le...@apache.org on 2004/12/15 16:47:10 UTC

svn commit: r111979 - excalibur/trunk/containerkit/instrument/mgr-impl/src/java/org/apache/excalibur/instrument/manager/impl

Author: leif
Date: Wed Dec 15 07:47:08 2004
New Revision: 111979

URL: http://svn.apache.org/viewcvs?view=rev&rev=111979
Log:
Fix a problem that was causing the most recent data sample to be lost if the sample's period was old when loading a saved state file.
Modified:
   excalibur/trunk/containerkit/instrument/mgr-impl/src/java/org/apache/excalibur/instrument/manager/impl/AbstractInstrumentSample.java
   excalibur/trunk/containerkit/instrument/mgr-impl/src/java/org/apache/excalibur/instrument/manager/impl/AbstractValueInstrumentSample.java
   excalibur/trunk/containerkit/instrument/mgr-impl/src/java/org/apache/excalibur/instrument/manager/impl/CounterInstrumentSample.java
   excalibur/trunk/containerkit/instrument/mgr-impl/src/java/org/apache/excalibur/instrument/manager/impl/MaximumValueInstrumentSample.java
   excalibur/trunk/containerkit/instrument/mgr-impl/src/java/org/apache/excalibur/instrument/manager/impl/MeanValueInstrumentSample.java
   excalibur/trunk/containerkit/instrument/mgr-impl/src/java/org/apache/excalibur/instrument/manager/impl/MinimumValueInstrumentSample.java

Modified: excalibur/trunk/containerkit/instrument/mgr-impl/src/java/org/apache/excalibur/instrument/manager/impl/AbstractInstrumentSample.java
Url: http://svn.apache.org/viewcvs/excalibur/trunk/containerkit/instrument/mgr-impl/src/java/org/apache/excalibur/instrument/manager/impl/AbstractInstrumentSample.java?view=diff&rev=111979&p1=excalibur/trunk/containerkit/instrument/mgr-impl/src/java/org/apache/excalibur/instrument/manager/impl/AbstractInstrumentSample.java&r1=111978&p2=excalibur/trunk/containerkit/instrument/mgr-impl/src/java/org/apache/excalibur/instrument/manager/impl/AbstractInstrumentSample.java&r2=111979
==============================================================================
--- excalibur/trunk/containerkit/instrument/mgr-impl/src/java/org/apache/excalibur/instrument/manager/impl/AbstractInstrumentSample.java	(original)
+++ excalibur/trunk/containerkit/instrument/mgr-impl/src/java/org/apache/excalibur/instrument/manager/impl/AbstractInstrumentSample.java	Wed Dec 15 07:47:08 2004
@@ -249,7 +249,7 @@
         synchronized( this )
         {
             long now = System.currentTimeMillis();
-            update = update( now );
+            update = update( now, false );
             value = getValueInner();
             time = m_time;
         }
@@ -275,7 +275,7 @@
         synchronized( this )
         {
             long now = System.currentTimeMillis();
-            update = update( now );
+            update = update( now, false );
             value = getValueInner();
             time = m_time;
         }
@@ -344,7 +344,7 @@
     public void expire()
     {
         // Update to the time that we expire at.
-        update( m_leaseExpirationTime );
+        update( m_leaseExpirationTime, false );
 
         m_expired = true;
     }
@@ -359,7 +359,7 @@
         synchronized( this )
         {
             long time = System.currentTimeMillis();
-            update( time );
+            update( time, false );
 
             return new InstrumentSampleSnapshot(
                 m_name,
@@ -548,7 +548,7 @@
         {
             // Always update the sample so its state will be correct when saved.
             long now = System.currentTimeMillis();
-            update = update( now );
+            update = update( now, false );
             value = getValueInner();
             time = m_time;
             
@@ -594,6 +594,10 @@
      */
     public final void loadState( Configuration state ) throws ConfigurationException
     {
+        boolean update;
+        int sampleValue;
+        long sampleTime;
+        
         synchronized( this )
         {
             // Set the time
@@ -659,14 +663,12 @@
             }
 
             loadState( value, state );
-
-            if( calculateSampleTime( System.currentTimeMillis() ) > savedTime )
-            {
-                // The sample period changed since the save.
-                //  This will usually happen, but not always for long
-                //  intervals.
-                postSaveNeedsReset();
-            }
+            
+            // Always cause update to synch the sample with the current system time.
+            long now = System.currentTimeMillis();
+            update = update( now, true );
+            sampleValue = getValueInner();
+            sampleTime = m_time;
 
             if( m_leaseExpirationTime > 0 )
             {
@@ -678,6 +680,11 @@
         }
 
         stateChanged();
+        
+        if ( update )
+        {
+            updateListeners( sampleValue, sampleTime );
+        }
     }
 
     /*---------------------------------------------------------------
@@ -744,12 +751,6 @@
         throws ConfigurationException;
 
     /**
-     * Called after a state is loaded if the sample period is not the same
-     *  as the last period saved.
-     */
-    protected abstract void postSaveNeedsReset();
-
-    /**
      * Calculates the time of the sample which contains the specified time.
      *
      * @param time Time whose sample time is requested.
@@ -778,8 +779,10 @@
      *  and move on to the next.
      * <p>
      * Should only be called when synchronized.
+     *
+     * @param reset True if the next sample should be reset.
      */
-    protected abstract void advanceToNextSample();
+    protected abstract void advanceToNextSample( boolean reset );
 
     /**
      * Returns the value to use for filling in the buffer when time is skipped.
@@ -794,10 +797,11 @@
      * Should only be called when synchronized.
      *
      * @param time The time to which the InstrumentSample should be brought up to date.
+     * @param reset True if the next sample should be reset if an advance is necessary.
      *
      * @return True if listeners should be notified.
      */
-    protected boolean update( long time )
+    protected boolean update( long time, boolean reset )
     {
         //System.out.println("update(" + time + ")");
         // If the lease has already expired, then do nothing
@@ -813,7 +817,7 @@
             if( time - m_time >= m_maxAge )
             {
                 // The history is too old, reset the sample.
-                advanceToNextSample();
+                advanceToNextSample( reset );
                 init( getFillValue() );
             }
             else
@@ -826,7 +830,7 @@
 
                     // Advance to the next sample.
                     m_time += m_interval;
-                    advanceToNextSample();
+                    advanceToNextSample( reset );
                     m_historyIndex++;
 
                     if( m_historyIndex >= m_size - 1 )

Modified: excalibur/trunk/containerkit/instrument/mgr-impl/src/java/org/apache/excalibur/instrument/manager/impl/AbstractValueInstrumentSample.java
Url: http://svn.apache.org/viewcvs/excalibur/trunk/containerkit/instrument/mgr-impl/src/java/org/apache/excalibur/instrument/manager/impl/AbstractValueInstrumentSample.java?view=diff&rev=111979&p1=excalibur/trunk/containerkit/instrument/mgr-impl/src/java/org/apache/excalibur/instrument/manager/impl/AbstractValueInstrumentSample.java&r1=111978&p2=excalibur/trunk/containerkit/instrument/mgr-impl/src/java/org/apache/excalibur/instrument/manager/impl/AbstractValueInstrumentSample.java&r2=111979
==============================================================================
--- excalibur/trunk/containerkit/instrument/mgr-impl/src/java/org/apache/excalibur/instrument/manager/impl/AbstractValueInstrumentSample.java	(original)
+++ excalibur/trunk/containerkit/instrument/mgr-impl/src/java/org/apache/excalibur/instrument/manager/impl/AbstractValueInstrumentSample.java	Wed Dec 15 07:47:08 2004
@@ -42,6 +42,9 @@
     /** The number of times that the value has been changed in this sample period. */
     protected int m_valueCount;
     
+    /** Last value set to the sample for use for sample periods where no value is set. */
+    protected int m_lastValue;
+    
     /*---------------------------------------------------------------
      * Constructors
      *-------------------------------------------------------------*/
@@ -103,6 +106,35 @@
      * AbstractInstrumentSample Methods
      *-------------------------------------------------------------*/
     /**
+     * The current sample has already been stored.  Reset the current sample
+     *  and move on to the next.
+     * <p>
+     * Should only be called when synchronized.
+     *
+     * @param reset True if the next sample should be reset.
+     */
+    protected void advanceToNextSample( boolean reset )
+    {
+        // Reset the value count and set the value to the last known value.
+        if ( reset )
+        {
+            m_lastValue = 0;
+        }
+        m_value = m_lastValue;
+        m_valueCount = 0;
+    }
+
+    /**
+     * Returns the value to use for filling in the buffer when time is skipped.
+     * <p>
+     * Should only be called when synchronized.
+     */
+    protected int getFillValue()
+    {
+        return m_lastValue;
+    }
+    
+    /**
      * Allow subclasses to add information into the saved state.
      *
      * @param state State configuration.
@@ -112,6 +144,7 @@
         super.saveState( state );
         
         state.setAttribute( "value-count", Integer.toString( m_valueCount ) );
+        state.setAttribute( "last-value", Integer.toString( m_lastValue ) );
     }
     
     /**
@@ -130,16 +163,7 @@
     {
         m_value = value;
         m_valueCount = state.getAttributeAsInteger( "value-count" );
-    }
-    
-    /**
-     * Called after a state is loaded if the sample period is not the same
-     *  as the last period saved.
-     */
-    protected void postSaveNeedsReset()
-    {
-        m_value = 0;
-        m_valueCount = 0;
+        m_lastValue = state.getAttributeAsInteger( "last-value" );
     }
     
     /*---------------------------------------------------------------

Modified: excalibur/trunk/containerkit/instrument/mgr-impl/src/java/org/apache/excalibur/instrument/manager/impl/CounterInstrumentSample.java
Url: http://svn.apache.org/viewcvs/excalibur/trunk/containerkit/instrument/mgr-impl/src/java/org/apache/excalibur/instrument/manager/impl/CounterInstrumentSample.java?view=diff&rev=111979&p1=excalibur/trunk/containerkit/instrument/mgr-impl/src/java/org/apache/excalibur/instrument/manager/impl/CounterInstrumentSample.java&r1=111978&p2=excalibur/trunk/containerkit/instrument/mgr-impl/src/java/org/apache/excalibur/instrument/manager/impl/CounterInstrumentSample.java&r2=111979
==============================================================================
--- excalibur/trunk/containerkit/instrument/mgr-impl/src/java/org/apache/excalibur/instrument/manager/impl/CounterInstrumentSample.java	(original)
+++ excalibur/trunk/containerkit/instrument/mgr-impl/src/java/org/apache/excalibur/instrument/manager/impl/CounterInstrumentSample.java	Wed Dec 15 07:47:08 2004
@@ -109,8 +109,10 @@
      *  and move on to the next.
      * <p>
      * Should only be called when synchronized.
+     *
+     * @param reset True if the next sample should be reset.
      */
-    protected void advanceToNextSample()
+    protected void advanceToNextSample( boolean reset )
     {
         // Counts do not propagate, so always reset the count to 0.
         m_count = 0;
@@ -143,15 +145,6 @@
         m_count = value;
     }
     
-    /**
-     * Called after a state is loaded if the sample period is not the same
-     *  as the last period saved.
-     */
-    protected void postSaveNeedsReset()
-    {
-        m_count = 0;
-    }
-    
     /*---------------------------------------------------------------
      * CounterInstrumentListener Methods
      *-------------------------------------------------------------*/
@@ -184,7 +177,7 @@
         
         synchronized(this)
         {
-            update( time );
+            update( time, false );
             
             m_count += count;
             

Modified: excalibur/trunk/containerkit/instrument/mgr-impl/src/java/org/apache/excalibur/instrument/manager/impl/MaximumValueInstrumentSample.java
Url: http://svn.apache.org/viewcvs/excalibur/trunk/containerkit/instrument/mgr-impl/src/java/org/apache/excalibur/instrument/manager/impl/MaximumValueInstrumentSample.java?view=diff&rev=111979&p1=excalibur/trunk/containerkit/instrument/mgr-impl/src/java/org/apache/excalibur/instrument/manager/impl/MaximumValueInstrumentSample.java&r1=111978&p2=excalibur/trunk/containerkit/instrument/mgr-impl/src/java/org/apache/excalibur/instrument/manager/impl/MaximumValueInstrumentSample.java&r2=111979
==============================================================================
--- excalibur/trunk/containerkit/instrument/mgr-impl/src/java/org/apache/excalibur/instrument/manager/impl/MaximumValueInstrumentSample.java	(original)
+++ excalibur/trunk/containerkit/instrument/mgr-impl/src/java/org/apache/excalibur/instrument/manager/impl/MaximumValueInstrumentSample.java	Wed Dec 15 07:47:08 2004
@@ -32,9 +32,6 @@
 class MaximumValueInstrumentSample
     extends AbstractValueInstrumentSample
 {
-    /** Last value set to the sample for use for sample periods where no value is set. */
-    private int m_lastValue;
-    
     /*---------------------------------------------------------------
      * Constructors
      *-------------------------------------------------------------*/
@@ -73,74 +70,6 @@
     }
     
     /*---------------------------------------------------------------
-     * AbstractInstrumentSample Methods
-     *-------------------------------------------------------------*/
-    /**
-     * The current sample has already been stored.  Reset the current sample
-     *  and move on to the next.
-     * <p>
-     * Should only be called when synchronized.
-     */
-    protected void advanceToNextSample()
-    {
-        // Reset the value count and set the value to the last known value.
-        m_value = m_lastValue;
-        m_valueCount = 0;
-    }
-
-    /**
-     * Returns the value to use for filling in the buffer when time is skipped.
-     * <p>
-     * Should only be called when synchronized.
-     */
-    protected int getFillValue()
-    {
-        return m_lastValue;
-    }
-    
-    /**
-     * Allow subclasses to add information into the saved state.
-     *
-     * @param state State configuration.
-     */
-    protected void saveState( DefaultConfiguration state )
-    {
-        super.saveState( state );
-        
-        state.setAttribute( "last-value", Integer.toString( m_lastValue ) );
-    }
-    
-    /**
-     * Used to load the state, called from AbstractInstrumentSample.loadState();
-     * <p>
-     * Should only be called when synchronized.
-     *
-     * @param value Current value loaded from the state.
-     * @param state Configuration object to load state from.
-     *
-     * @throws ConfigurationException If there were any problems loading the
-     *                                state.
-     */
-    protected void loadState( int value, Configuration state )
-        throws ConfigurationException
-    {
-        super.loadState( value, state );
-        
-        m_lastValue = state.getAttributeAsInteger( "last-value" );
-    }
-    
-    /**
-     * Called after a state is loaded if the sample period is not the same
-     *  as the last period saved.
-     */
-    protected void postSaveNeedsReset()
-    {
-        super.postSaveNeedsReset();
-        
-        m_lastValue = 0;
-    }
-    
-    /*---------------------------------------------------------------
      * AbstractValueInstrumentSample Methods
      *-------------------------------------------------------------*/
     /**
@@ -158,7 +87,7 @@
         
         synchronized(this)
         {
-            update = update( time );
+            update = update( time, false );
             
             // Always store the last value to use for samples where a value is not set.
             m_lastValue = value;

Modified: excalibur/trunk/containerkit/instrument/mgr-impl/src/java/org/apache/excalibur/instrument/manager/impl/MeanValueInstrumentSample.java
Url: http://svn.apache.org/viewcvs/excalibur/trunk/containerkit/instrument/mgr-impl/src/java/org/apache/excalibur/instrument/manager/impl/MeanValueInstrumentSample.java?view=diff&rev=111979&p1=excalibur/trunk/containerkit/instrument/mgr-impl/src/java/org/apache/excalibur/instrument/manager/impl/MeanValueInstrumentSample.java&r1=111978&p2=excalibur/trunk/containerkit/instrument/mgr-impl/src/java/org/apache/excalibur/instrument/manager/impl/MeanValueInstrumentSample.java&r2=111979
==============================================================================
--- excalibur/trunk/containerkit/instrument/mgr-impl/src/java/org/apache/excalibur/instrument/manager/impl/MeanValueInstrumentSample.java	(original)
+++ excalibur/trunk/containerkit/instrument/mgr-impl/src/java/org/apache/excalibur/instrument/manager/impl/MeanValueInstrumentSample.java	Wed Dec 15 07:47:08 2004
@@ -80,23 +80,14 @@
      *  and move on to the next.
      * <p>
      * Should only be called when synchronized.
+     *
+     * @param reset True if the next sample should be reset.
      */
-    protected void advanceToNextSample()
-    {
-        // Leave the value as is so that it will propagate to the next sample
-        //  if needed.  But reset the value count so that new values will not
-        //  be affected by the old.
-        m_valueCount = 0;
-    }
-
-    /**
-     * Returns the value to use for filling in the buffer when time is skipped.
-     * <p>
-     * Should only be called when synchronized.
-     */
-    protected int getFillValue()
+    protected void advanceToNextSample( boolean reset )
     {
-        return m_value;
+        super.advanceToNextSample( reset );
+        
+        m_valueTotal = 0;
     }
     
     /**
@@ -130,17 +121,6 @@
         m_valueTotal = state.getAttributeAsLong( "value-total" );
     }
     
-    /**
-     * Called after a state is loaded if the sample period is not the same
-     *  as the last period saved.
-     */
-    protected void postSaveNeedsReset()
-    {
-        super.postSaveNeedsReset();
-        
-        m_valueTotal = 0;
-    }
-    
     /*---------------------------------------------------------------
      * AbstractValueInstrumentSample Methods
      *-------------------------------------------------------------*/
@@ -158,7 +138,10 @@
         
         synchronized(this)
         {
-            update( time );
+            update( time, false );
+            
+            // Always store the last value to use for samples where a value is not set.
+            m_lastValue = value;
             
             if ( m_valueCount > 0 )
             {

Modified: excalibur/trunk/containerkit/instrument/mgr-impl/src/java/org/apache/excalibur/instrument/manager/impl/MinimumValueInstrumentSample.java
Url: http://svn.apache.org/viewcvs/excalibur/trunk/containerkit/instrument/mgr-impl/src/java/org/apache/excalibur/instrument/manager/impl/MinimumValueInstrumentSample.java?view=diff&rev=111979&p1=excalibur/trunk/containerkit/instrument/mgr-impl/src/java/org/apache/excalibur/instrument/manager/impl/MinimumValueInstrumentSample.java&r1=111978&p2=excalibur/trunk/containerkit/instrument/mgr-impl/src/java/org/apache/excalibur/instrument/manager/impl/MinimumValueInstrumentSample.java&r2=111979
==============================================================================
--- excalibur/trunk/containerkit/instrument/mgr-impl/src/java/org/apache/excalibur/instrument/manager/impl/MinimumValueInstrumentSample.java	(original)
+++ excalibur/trunk/containerkit/instrument/mgr-impl/src/java/org/apache/excalibur/instrument/manager/impl/MinimumValueInstrumentSample.java	Wed Dec 15 07:47:08 2004
@@ -32,9 +32,6 @@
 class MinimumValueInstrumentSample
     extends AbstractValueInstrumentSample
 {
-    /** Last value set to the sample for use for sample periods where no value is set. */
-    private int m_lastValue;
-    
     /*---------------------------------------------------------------
      * Constructors
      *-------------------------------------------------------------*/
@@ -73,74 +70,6 @@
     }
     
     /*---------------------------------------------------------------
-     * AbstractInstrumentSample Methods
-     *-------------------------------------------------------------*/
-    /**
-     * The current sample has already been stored.  Reset the current sample
-     *  and move on to the next.
-     * <p>
-     * Should only be called when synchronized.
-     */
-    protected void advanceToNextSample()
-    {
-        // Reset the value count and set the value to the last known value.
-        m_value = m_lastValue;
-        m_valueCount = 0;
-    }
-
-    /**
-     * Returns the value to use for filling in the buffer when time is skipped.
-     * <p>
-     * Should only be called when synchronized.
-     */
-    protected int getFillValue()
-    {
-        return m_lastValue;
-    }
-    
-    /**
-     * Allow subclasses to add information into the saved state.
-     *
-     * @param state State configuration.
-     */
-    protected void saveState( DefaultConfiguration state )
-    {
-        super.saveState( state );
-        
-        state.setAttribute( "last-value", Integer.toString( m_lastValue ) );
-    }
-    
-    /**
-     * Used to load the state, called from AbstractInstrumentSample.loadState();
-     * <p>
-     * Should only be called when synchronized.
-     *
-     * @param value Current value loaded from the state.
-     * @param state Configuration object to load state from.
-     *
-     * @throws ConfigurationException If there were any problems loading the
-     *                                state.
-     */
-    protected void loadState( int value, Configuration state )
-        throws ConfigurationException
-    {
-        super.loadState( value, state );
-        
-        m_lastValue = state.getAttributeAsInteger( "last-value" );
-    }
-    
-    /**
-     * Called after a state is loaded if the sample period is not the same
-     *  as the last period saved.
-     */
-    protected void postSaveNeedsReset()
-    {
-        super.postSaveNeedsReset();
-        
-        m_lastValue = 0;
-    }
-    
-    /*---------------------------------------------------------------
      * AbstractValueInstrumentSample Methods
      *-------------------------------------------------------------*/
     /**
@@ -158,7 +87,7 @@
         
         synchronized(this)
         {
-            update( time );
+            update = update( time, false );
             
             // Always store the last value to use for samples where a value is not set.
             m_lastValue = value;

---------------------------------------------------------------------
To unsubscribe, e-mail: scm-unsubscribe@excalibur.apache.org
For additional commands, e-mail: scm-help@excalibur.apache.org