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 2002/04/22 11:52:34 UTC

cvs commit: jakarta-avalon-excalibur/instrument-manager/src/java/org/apache/avalon/excalibur/instrument/manager CounterInstrumentSample.java InstrumentProxy.java

leif        02/04/22 02:52:34

  Modified:    instrument-manager/src/java/org/apache/avalon/excalibur/instrument/manager/interfaces
                        CounterInstrumentListener.java
               instrument-manager/src/java/org/apache/avalon/excalibur/instrument/manager
                        CounterInstrumentSample.java InstrumentProxy.java
  Log:
  Add the ability to increment by more than 1 on CounterInstruments.
  
  Revision  Changes    Path
  1.3       +3 -2      jakarta-avalon-excalibur/instrument-manager/src/java/org/apache/avalon/excalibur/instrument/manager/interfaces/CounterInstrumentListener.java
  
  Index: CounterInstrumentListener.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/instrument-manager/src/java/org/apache/avalon/excalibur/instrument/manager/interfaces/CounterInstrumentListener.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- CounterInstrumentListener.java	3 Apr 2002 13:18:30 -0000	1.2
  +++ CounterInstrumentListener.java	22 Apr 2002 09:52:34 -0000	1.3
  @@ -13,7 +13,7 @@
    *  it is incremented.
    *
    * @author <a href="mailto:leif@tanukisoftware.com">Leif Mortenson</a>
  - * @version CVS $Revision: 1.2 $ $Date: 2002/04/03 13:18:30 $
  + * @version CVS $Revision: 1.3 $ $Date: 2002/04/22 09:52:34 $
    * @since 4.1
    */
   public interface CounterInstrumentListener
  @@ -23,7 +23,8 @@
        * Called by a CounterInstrument whenever its value is incremented.
        *
        * @param instrumentName The name of Instrument which was incremented.
  +     * @param count A positive integer to increment the counter by.
        * @param time The time that the Instrument was incremented.
        */
  -    void increment( String instrumentName, long time );
  +    void increment( String instrumentName, int count, long time );
   }
  
  
  
  1.4       +8 -6      jakarta-avalon-excalibur/instrument-manager/src/java/org/apache/avalon/excalibur/instrument/manager/CounterInstrumentSample.java
  
  Index: CounterInstrumentSample.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/instrument-manager/src/java/org/apache/avalon/excalibur/instrument/manager/CounterInstrumentSample.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- CounterInstrumentSample.java	3 Apr 2002 13:18:29 -0000	1.3
  +++ CounterInstrumentSample.java	22 Apr 2002 09:52:34 -0000	1.4
  @@ -18,7 +18,7 @@
    *  called during the sample period.
    *
    * @author <a href="mailto:leif@tanukisoftware.com">Leif Mortenson</a>
  - * @version CVS $Revision: 1.3 $ $Date: 2002/04/03 13:18:29 $
  + * @version CVS $Revision: 1.4 $ $Date: 2002/04/22 09:52:34 $
    * @since 4.1
    */
   class CounterInstrumentSample
  @@ -123,12 +123,13 @@
        * Called by a CounterInstrument whenever its value is incremented.
        *
        * @param instrumentName The name of Instrument which was incremented.
  +     * @param count A positive integer to increment the counter by.
        * @param time The time that the Instrument was incremented.
        */
  -    public void increment( String instrumentName, long time )
  +    public void increment( String instrumentName, int count, long time )
       {
  -        //System.out.println("CounterInstrumentSample.increment(" + instrumentName + ", " + time + ") : " + getName() );
  -        increment( time );
  +        //System.out.println("CounterInstrumentSample.increment(" + instrumentName + ", " + count + ", " + time + ") : " + getName() );
  +        increment( count, time );
       }
       
       /*---------------------------------------------------------------
  @@ -138,8 +139,9 @@
        * Increments the count.
        *
        * @param time Time that the count is incremented.
  +     * @param count A positive integer to increment the counter by.
        */
  -    private void increment( long time )
  +    private void increment( int count, long time )
       {
           int sampleValue;
           long sampleTime;
  @@ -148,7 +150,7 @@
           {
               update( time );
               
  -            m_count++;
  +            m_count += count;
               
               sampleValue = m_count;
               sampleTime = m_time;
  
  
  
  1.5       +89 -78    jakarta-avalon-excalibur/instrument-manager/src/java/org/apache/avalon/excalibur/instrument/manager/InstrumentProxy.java
  
  Index: InstrumentProxy.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/instrument-manager/src/java/org/apache/avalon/excalibur/instrument/manager/InstrumentProxy.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- InstrumentProxy.java	3 Apr 2002 13:18:29 -0000	1.4
  +++ InstrumentProxy.java	22 Apr 2002 09:52:34 -0000	1.5
  @@ -38,7 +38,7 @@
    *  It is resolved when the Instrumentable actually registers the Instrument.
    *
    * @author <a href="mailto:leif@tanukisoftware.com">Leif Mortenson</a>
  - * @version CVS $Revision: 1.4 $ $Date: 2002/04/03 13:18:29 $
  + * @version CVS $Revision: 1.5 $ $Date: 2002/04/22 09:52:34 $
    * @since 4.1
    */
   public class InstrumentProxy
  @@ -166,6 +166,94 @@
       }
       
       /*---------------------------------------------------------------
  +     * InstrumentProxy Methods
  +     *-------------------------------------------------------------*/
  +    /**
  +     * Used by classes being profiles so that they can avoid unnecessary
  +     *  code when the data from a Instrument is not being used.
  +     *
  +     * @returns True if listeners are registered with the Instrument.
  +     */
  +    public boolean isActive() {
  +        return m_listeners != null;
  +    }
  +    
  +    /**
  +     * Increments the Instrument by a specified count.  This method should be
  +     *  optimized to be extremely light weight when there are no registered
  +     *  CounterInstrumentListeners.
  +     *
  +     * @param count A positive integer to increment the counter by.
  +     */
  +    public void increment( int count )
  +    {
  +        if ( m_type != InstrumentManagerClient.INSTRUMENT_TYPE_COUNTER )
  +        {
  +            // Type is not correct.
  +            throw new IllegalStateException(
  +                "The proxy is not configured to handle CounterInstruments." );
  +        }
  +        
  +        // Check the count
  +        if ( count <= 0 ) {
  +            throw new IllegalArgumentException( "Count must be a positive value." );
  +        }
  +        
  +        // Get a local reference to the listeners, so that synchronization can be avoided.
  +        InstrumentListener[] listeners = m_listeners;
  +        if ( listeners != null )
  +        {
  +            if ( m_valueLogger.isDebugEnabled() )
  +            {
  +                m_valueLogger.debug( "increment() called for Instrument, " + m_name );
  +            }
  +            
  +            long time = System.currentTimeMillis();
  +            for ( int i = 0; i < listeners.length; i++ )
  +            {
  +                CounterInstrumentListener listener =
  +                    (CounterInstrumentListener)listeners[i];
  +                listener.increment( getName(), count, time );
  +            }
  +        }
  +    }
  +    
  +    /**
  +     * Sets the current value of the Instrument.  This method is optimized
  +     *  to be extremely light weight when there are no registered
  +     *  ValueInstrumentListeners.
  +     *
  +     * @param value The new value for the Instrument.
  +     */
  +    public void setValue( int value )
  +    {
  +        if ( m_type != InstrumentManagerClient.INSTRUMENT_TYPE_VALUE )
  +        {
  +            // Type is not correct.
  +            throw new IllegalStateException(
  +                "The proxy is not configured to handle ValueInstruments." );
  +        }
  +        
  +        // Get a local reference to the listeners, so that synchronization can be avoided.
  +        InstrumentListener[] listeners = m_listeners;
  +        if ( listeners != null )
  +        {
  +            if ( m_valueLogger.isDebugEnabled() )
  +            {
  +                m_valueLogger.debug( "setValue( " + value + " ) called for Instrument, " + m_name );
  +            }
  +            
  +            long time = System.currentTimeMillis();
  +            for ( int i = 0; i < listeners.length; i++ )
  +            {
  +                ValueInstrumentListener listener =
  +                    (ValueInstrumentListener)listeners[i];
  +                listener.setValue( getName(), value, time );
  +            }
  +        }
  +    }
  +    
  +    /*---------------------------------------------------------------
        * Methods
        *-------------------------------------------------------------*/
       /**
  @@ -260,16 +348,6 @@
       }
       
       /**
  -     * Used by classes being profiles so that they can avoid unnecessary
  -     *  code when the data from a Instrument is not being used.
  -     *
  -     * @returns True if listeners are registered with the Instrument.
  -     */
  -    public boolean isActive() {
  -        return m_listeners != null;
  -    }
  -    
  -    /**
        * Adds a CounterInstrumentListener to the list of listeners which will
        *  receive updates of the value of the Instrument.
        *
  @@ -325,38 +403,6 @@
           removeInstrumentListener( listener );
       }
       
  -    /*
  -     * Increments the Instrument.  This method is optimized to be extremely
  -     *  light weight when there are no registered CounterInstrumentListeners.
  -     */
  -    public void increment()
  -    {
  -        if ( m_type != InstrumentManagerClient.INSTRUMENT_TYPE_COUNTER )
  -        {
  -            // Type is not correct.
  -            throw new IllegalStateException(
  -                "The proxy is not configured to handle CounterInstruments." );
  -        }
  -        
  -        // Get a local reference to the listeners, so that synchronization can be avoided.
  -        InstrumentListener[] listeners = m_listeners;
  -        if ( listeners != null )
  -        {
  -            if ( m_valueLogger.isDebugEnabled() )
  -            {
  -                m_valueLogger.debug( "increment() called for Instrument, " + m_name );
  -            }
  -            
  -            long time = System.currentTimeMillis();
  -            for ( int i = 0; i < listeners.length; i++ )
  -            {
  -                CounterInstrumentListener listener =
  -                    (CounterInstrumentListener)listeners[i];
  -                listener.increment( getName(), time );
  -            }
  -        }
  -    }
  -    
       /**
        * Adds a ValueInstrumentListener to the list of listeners which will
        *  receive updates of the value of the Instrument.
  @@ -411,41 +457,6 @@
           }
           
           removeInstrumentListener( listener );
  -    }
  -    
  -    /**
  -     * Sets the current value of the Instrument.  This method is optimized
  -     *  to be extremely light weight when there are no registered
  -     *  ValueInstrumentListeners.
  -     *
  -     * @param value The new value for the Instrument.
  -     */
  -    public void setValue( int value )
  -    {
  -        if ( m_type != InstrumentManagerClient.INSTRUMENT_TYPE_VALUE )
  -        {
  -            // Type is not correct.
  -            throw new IllegalStateException(
  -                "The proxy is not configured to handle ValueInstruments." );
  -        }
  -        
  -        // Get a local reference to the listeners, so that synchronization can be avoided.
  -        InstrumentListener[] listeners = m_listeners;
  -        if ( listeners != null )
  -        {
  -            if ( m_valueLogger.isDebugEnabled() )
  -            {
  -                m_valueLogger.debug( "setValue( " + value + " ) called for Instrument, " + m_name );
  -            }
  -            
  -            long time = System.currentTimeMillis();
  -            for ( int i = 0; i < listeners.length; i++ )
  -            {
  -                ValueInstrumentListener listener =
  -                    (ValueInstrumentListener)listeners[i];
  -                listener.setValue( getName(), value, time );
  -            }
  -        }
       }
       
       /**
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>