You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by le...@apache.org on 2004/01/30 07:39:00 UTC

cvs commit: avalon-excalibur/instrument-manager/src/java/org/apache/excalibur/instrument/manager AbstractInstrumentSample.java

leif        2004/01/29 22:39:00

  Modified:    instrument-manager/src/java/org/apache/excalibur/instrument/manager
                        AbstractInstrumentSample.java
  Log:
  Make sure that the allignment of large sample periods takes the current timezone
  into account.
  
  Revision  Changes    Path
  1.2       +20 -2     avalon-excalibur/instrument-manager/src/java/org/apache/excalibur/instrument/manager/AbstractInstrumentSample.java
  
  Index: AbstractInstrumentSample.java
  ===================================================================
  RCS file: /home/cvs/avalon-excalibur/instrument-manager/src/java/org/apache/excalibur/instrument/manager/AbstractInstrumentSample.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AbstractInstrumentSample.java	9 Nov 2003 16:36:32 -0000	1.1
  +++ AbstractInstrumentSample.java	30 Jan 2004 06:39:00 -0000	1.2
  @@ -50,6 +50,7 @@
   package org.apache.excalibur.instrument.manager;
   
   import java.util.StringTokenizer;
  +import java.util.Calendar;
   
   import org.apache.avalon.framework.configuration.Configuration;
   import org.apache.avalon.framework.configuration.ConfigurationException;
  @@ -70,6 +71,9 @@
       extends AbstractLogEnabled
       implements InstrumentSample
   {
  +    /** Stores the time-zone offset for this JVM. */
  +    private static long m_zoneOffset;
  +    
       /** The InstrumentProxy which owns the InstrumentSample. */
       private InstrumentProxy m_instrumentProxy;
   
  @@ -122,6 +126,15 @@
       private int m_stateVersion;
   
       /*---------------------------------------------------------------
  +     * Static Initializer
  +     *-------------------------------------------------------------*/
  +    static
  +    {
  +        Calendar now = Calendar.getInstance();
  +        m_zoneOffset = now.get( Calendar.ZONE_OFFSET );
  +    }
  +    
  +    /*---------------------------------------------------------------
        * Constructors
        *-------------------------------------------------------------*/
       /**
  @@ -742,7 +755,12 @@
        */
       private long calculateSampleTime( long time )
       {
  -        return ( time / m_interval ) * m_interval;
  +        // We want this to round to the nearest interval.  For intervals
  +        //  over an hour, the current time zone needs to be taken into
  +        //  account so the interval will be alligned correctly.
  +        // The timezone offset is calculated once when the class is loaded.
  +        long offset = ( time + m_zoneOffset ) % m_interval;
  +        return time - offset;
       }
   
       /**
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@avalon.apache.org
For additional commands, e-mail: cvs-help@avalon.apache.org