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/28 19:05:42 UTC

cvs commit: jakarta-avalon-excalibur/instrument-manager/src/java/org/apache/avalon/excalibur/instrument/manager/interfaces InstrumentDescriptor.java InstrumentManagerClient.java InstrumentSampleDescriptor.java

leif        02/04/28 10:05:42

  Modified:    instrument-manager/src/java/org/apache/avalon/excalibur/instrument/manager
                        AbstractInstrumentSample.java
                        AbstractValueInstrumentSample.java
                        CounterInstrumentSample.java
                        DefaultInstrumentManager.java
                        InstrumentDescriptorImpl.java InstrumentProxy.java
                        InstrumentSample.java
                        InstrumentSampleDescriptorImpl.java
                        InstrumentSampleFactory.java
                        MaximumValueInstrumentSample.java
                        MeanValueInstrumentSample.java
                        MinimumValueInstrumentSample.java
               instrument-manager/src/java/org/apache/avalon/excalibur/instrument/manager/interfaces
                        InstrumentDescriptor.java
                        InstrumentManagerClient.java
                        InstrumentSampleDescriptor.java
  Log:
  Add the ability to add instrument samples at runtime.
  
  Revision  Changes    Path
  1.4       +48 -2     jakarta-avalon-excalibur/instrument-manager/src/java/org/apache/avalon/excalibur/instrument/manager/AbstractInstrumentSample.java
  
  Index: AbstractInstrumentSample.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/instrument-manager/src/java/org/apache/avalon/excalibur/instrument/manager/AbstractInstrumentSample.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- AbstractInstrumentSample.java	3 Apr 2002 13:18:29 -0000	1.3
  +++ AbstractInstrumentSample.java	28 Apr 2002 17:05:41 -0000	1.4
  @@ -25,7 +25,7 @@
    *  InstrumentSamples.
    *
    * @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/28 17:05:41 $
    * @since 4.1
    */
   abstract class AbstractInstrumentSample
  @@ -56,6 +56,9 @@
       /** The UNIX time of the beginning of the sample. */
       protected long m_time;
       
  +    /** The time that the current lease expires. */
  +    private long m_leaseExpirationTime;
  +    
       /** The Index into the history arrays. */
       private int m_historyIndex;
       
  @@ -78,8 +81,13 @@
        * @param interval The sample interval of the new InstrumentSample.
        * @param size The number of samples to store as history.  Assumes that size is at least 1.
        * @param description The description of the new InstrumentSample.
  +     * @param lease The length of the lease in milliseconds.
        */
  -    protected AbstractInstrumentSample( String name, long interval, int size, String description )
  +    protected AbstractInstrumentSample( String name,
  +                                        long interval,
  +                                        int size,
  +                                        String description,
  +                                        long lease )
       {
           if ( interval < 1 )
           {
  @@ -94,6 +102,15 @@
           m_interval = interval;
           m_size = size;
           m_description = description;
  +        if ( lease > 0 )
  +        {
  +            m_leaseExpirationTime = System.currentTimeMillis() + lease;
  +        }
  +        else
  +        {
  +            // Permanent lease.
  +            m_leaseExpirationTime = 0;
  +        }
           
           // Calculate the maxAge
           m_maxAge = m_size * m_interval;
  @@ -221,6 +238,35 @@
               updateListeners( value, time );
           }
           return time;
  +    }
  +    
  +    /**
  +     * Returns the time that the current lease expires.  Permanent samples will
  +     *  return a value of 0.
  +     *
  +     * @return The time that the current lease expires.
  +     */
  +    public long getLeaseExpirationTime()
  +    {
  +        return m_leaseExpirationTime;
  +    }
  +    
  +    /**
  +     * Extends the lease to be lease milliseconds from the current time.
  +     *
  +     * @param lease The length of the lease in milliseconds.
  +     */
  +    public void extendLease( long lease )
  +    {
  +        synchronized(this)
  +        {
  +            // Only extend the lease if it is not permanent.
  +            if ( m_leaseExpirationTime > 0 )
  +            {
  +                long newLeaseExpirationTime = System.currentTimeMillis() + lease;
  +                m_leaseExpirationTime = Math.max( m_leaseExpirationTime, newLeaseExpirationTime );
  +            }
  +        }
       }
       
       /**
  
  
  
  1.4       +8 -3      jakarta-avalon-excalibur/instrument-manager/src/java/org/apache/avalon/excalibur/instrument/manager/AbstractValueInstrumentSample.java
  
  Index: AbstractValueInstrumentSample.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/instrument-manager/src/java/org/apache/avalon/excalibur/instrument/manager/AbstractValueInstrumentSample.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- AbstractValueInstrumentSample.java	3 Apr 2002 13:18:29 -0000	1.3
  +++ AbstractValueInstrumentSample.java	28 Apr 2002 17:05:41 -0000	1.4
  @@ -19,7 +19,7 @@
    *  to all InstrumentSamples which represent a fixed value.
    *
    * @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/28 17:05:41 $
    * @since 4.1
    */
   abstract class AbstractValueInstrumentSample
  @@ -42,10 +42,15 @@
        * @param interval The sample interval of the new InstrumentSample.
        * @param size The number of samples to store as history.  Assumes that size is at least 1.
        * @param description The description of the new InstrumentSample.
  +     * @param lease The length of the lease in milliseconds.
        */
  -    protected AbstractValueInstrumentSample( String name, long interval, int size, String description )
  +    protected AbstractValueInstrumentSample( String name,
  +                                             long interval,
  +                                             int size,
  +                                             String description,
  +                                             long lease )
       {
  -        super( name, interval, size, description );
  +        super( name, interval, size, description, lease );
           
           // Set the current value to 0 initially.
           m_value = 0;
  
  
  
  1.5       +8 -3      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.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- CounterInstrumentSample.java	22 Apr 2002 09:52:34 -0000	1.4
  +++ CounterInstrumentSample.java	28 Apr 2002 17:05:41 -0000	1.5
  @@ -18,7 +18,7 @@
    *  called during the sample period.
    *
    * @author <a href="mailto:leif@tanukisoftware.com">Leif Mortenson</a>
  - * @version CVS $Revision: 1.4 $ $Date: 2002/04/22 09:52:34 $
  + * @version CVS $Revision: 1.5 $ $Date: 2002/04/28 17:05:41 $
    * @since 4.1
    */
   class CounterInstrumentSample
  @@ -38,10 +38,15 @@
        * @param interval The sample interval of the new InstrumentSample.
        * @param size The number of samples to store as history.  Assumes that size is at least 1.
        * @param description The description of the new InstrumentSample.
  +     * @param lease The length of the lease in milliseconds.
        */
  -    CounterInstrumentSample( String name, long interval, int size, String description )
  +    CounterInstrumentSample( String name,
  +                             long interval,
  +                             int size,
  +                             String description,
  +                             long lease )
       {
  -        super( name, interval, size, description );
  +        super( name, interval, size, description, lease );
           
           // Set the current value to 0 initially.
           m_count = 0;
  
  
  
  1.6       +2 -1      jakarta-avalon-excalibur/instrument-manager/src/java/org/apache/avalon/excalibur/instrument/manager/DefaultInstrumentManager.java
  
  Index: DefaultInstrumentManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/instrument-manager/src/java/org/apache/avalon/excalibur/instrument/manager/DefaultInstrumentManager.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- DefaultInstrumentManager.java	3 Apr 2002 13:18:29 -0000	1.5
  +++ DefaultInstrumentManager.java	28 Apr 2002 17:05:41 -0000	1.6
  @@ -40,7 +40,7 @@
   /**
    *
    * @author <a href="mailto:leif@tanukisoftware.com">Leif Mortenson</a>
  - * @version CVS $Revision: 1.5 $ $Date: 2002/04/03 13:18:29 $
  + * @version CVS $Revision: 1.6 $ $Date: 2002/04/28 17:05:41 $
    * @since 4.1
    */
   public class DefaultInstrumentManager
  @@ -852,6 +852,7 @@
               if( proxy == null )
               {
                   proxy = new InstrumentProxy( profilePointName );
  +                proxy.enableLogging( getLogger() );
   
                   // Set the type of the new InstrumentProxy depending on the
                   //  class of the actual Instrument.
  
  
  
  1.4       +33 -1     jakarta-avalon-excalibur/instrument-manager/src/java/org/apache/avalon/excalibur/instrument/manager/InstrumentDescriptorImpl.java
  
  Index: InstrumentDescriptorImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/instrument-manager/src/java/org/apache/avalon/excalibur/instrument/manager/InstrumentDescriptorImpl.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- InstrumentDescriptorImpl.java	3 Apr 2002 13:18:29 -0000	1.3
  +++ InstrumentDescriptorImpl.java	28 Apr 2002 17:05:41 -0000	1.4
  @@ -18,7 +18,7 @@
    *  Instrument.
    *
    * @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/28 17:05:41 $
    * @since 4.1
    */
   public class InstrumentDescriptorImpl
  @@ -169,6 +169,38 @@
           }
           
           return InstrumentSample.getDescriptor();
  +    }
  +    
  +    /**
  +     * Returns a InstrumentSampleDescriptor based on its name.  If the requested
  +     *  sample is invalid in any way, then an expired Descriptor will be
  +     *  returned.
  +     *
  +     * @param sampleDescription Description to assign to the new Sample.
  +     * @param sampleInterval Sample interval to use in the new Sample.
  +     * @param sampleLease Requested lease time for the new Sample in
  +     *                    milliseconds.  The InstrumentManager may grant a
  +     *                    lease which is shorter or longer than the requested
  +     *                    period.
  +     * @param sampleType Type of sample to request.  Must be one of the
  +     *                   following:  InstrumentManagerClient.INSTRUMENT_SAMPLE_TYPE_COUNTER,
  +     *                   InstrumentManagerClient.INSTRUMENT_SAMPLE_TYPE_MINIMUM,
  +     *                   InstrumentManagerClient.INSTRUMENT_SAMPLE_TYPE_MAXIMUM,
  +     *                   InstrumentManagerClient.INSTRUMENT_SAMPLE_TYPE_MEAN.
  +     *
  +     * @return A Descriptor of the requested InstrumentSample.
  +     *
  +     * @throws NoSuchInstrumentSampleException If the specified InstrumentSample
  +     *                                      does not exist.
  +     */
  +    public InstrumentSampleDescriptor createInstrumentSample( String sampleDescription,
  +                                                              long sampleInterval,
  +                                                              int sampleSize,
  +                                                              long sampleLease,
  +                                                              int sampleType )
  +    {
  +        return m_instrumentProxy.createInstrumentSample(
  +            sampleDescription, sampleInterval, sampleSize, sampleLease, sampleType );
       }
       
       /**
  
  
  
  1.6       +88 -14    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.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- InstrumentProxy.java	22 Apr 2002 09:52:34 -0000	1.5
  +++ InstrumentProxy.java	28 Apr 2002 17:05:41 -0000	1.6
  @@ -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.5 $ $Date: 2002/04/22 09:52:34 $
  + * @version CVS $Revision: 1.6 $ $Date: 2002/04/28 17:05:41 $
    * @since 4.1
    */
   public class InstrumentProxy
  @@ -139,14 +139,15 @@
               {
                   Configuration sampleConf = sampleConfs[i];
                   
  -                String sampleType = sampleConf.getAttribute( "type" );
  +                int sampleType = InstrumentSampleFactory.resolveInstrumentSampleType(
  +                    sampleConf.getAttribute( "type" ) );
                   long sampleInterval = sampleConf.getAttributeAsLong( "interval" );
                   int sampleSize = sampleConf.getAttributeAsInteger( "size", 1 );
                   
                   // Build the sample name from its attributes.  This makes it
                   //  possible to avoid forcing the user to maintain a name as well.
  -                String sampleName = m_name + "." + sampleType + "." + 
  -                    sampleInterval + "." + sampleSize;
  +                String sampleName = 
  +                    generateSampleName( m_name, sampleType, sampleInterval, sampleSize );
                   
                   String sampleDescription = sampleConf.getAttribute( "description", sampleName );
                   
  @@ -156,11 +157,11 @@
                           " as \"" + sampleDescription + "\"" );
                   }
                   
  -                InstrumentSample InstrumentSample = InstrumentSampleFactory.getInstrumentSample(
  -                    sampleType, sampleName, sampleInterval, sampleSize, sampleDescription );
  -                InstrumentSample.enableLogging( getLogger() );
  +                InstrumentSample instrumentSample = InstrumentSampleFactory.getInstrumentSample(
  +                    sampleType, sampleName, sampleInterval, sampleSize, sampleDescription, 0 );
  +                instrumentSample.enableLogging( getLogger() );
                   
  -                addInstrumentSample( InstrumentSample );
  +                addInstrumentSample( instrumentSample );
               }
           }
       }
  @@ -463,12 +464,8 @@
        * Add a InstrumentSample to the Instrument.
        *
        * @param InstrumentSample InstrumentSample to be added.
  -     *
  -     * @throws ConfigurationException If there are any configuration problems
  -     *                                with the InstrumentSample.
        */
       public void addInstrumentSample( InstrumentSample InstrumentSample )
  -        throws ConfigurationException
       {
           synchronized(this)
           {
  @@ -481,7 +478,7 @@
               else if ( m_type != InstrumentSample.getInstrumentType() )
               {
                   // The type is different.
  -                throw new ConfigurationException( "The sample '" + InstrumentSample.getName() + 
  +                throw new IllegalStateException( "The sample '" + InstrumentSample.getName() + 
                       "' had its type set to " + getTypeName( m_type ) + 
                       " by another sample.  This sample has a type of " + 
                       getTypeName( InstrumentSample.getInstrumentType() ) + " and is not compatible." );
  @@ -491,7 +488,7 @@
               String sampleName = InstrumentSample.getName();
               if ( m_samples.get( sampleName ) != null )
               {
  -                throw new ConfigurationException( "More than one sample with the same name, '" +
  +                throw new IllegalStateException( "More than one sample with the same name, '" +
                       sampleName + "', can not be configured." );
               }
           
  @@ -551,6 +548,68 @@
       }
       
       /**
  +     * Returns a InstrumentSampleDescriptor based on its name.  If the requested
  +     *  sample is invalid in any way, then an expired Descriptor will be
  +     *  returned.
  +     *
  +     * @param sampleDescription Description to assign to the new Sample.
  +     * @param sampleInterval Sample interval to use in the new Sample.
  +     * @param sampleLease Requested lease time for the new Sample in
  +     *                    milliseconds.  The InstrumentManager may grant a
  +     *                    lease which is shorter or longer than the requested
  +     *                    period.
  +     * @param sampleType Type of sample to request.  Must be one of the
  +     *                   following:  InstrumentManagerClient.INSTRUMENT_SAMPLE_TYPE_COUNTER,
  +     *                   InstrumentManagerClient.INSTRUMENT_SAMPLE_TYPE_MINIMUM,
  +     *                   InstrumentManagerClient.INSTRUMENT_SAMPLE_TYPE_MAXIMUM,
  +     *                   InstrumentManagerClient.INSTRUMENT_SAMPLE_TYPE_MEAN.
  +     *
  +     * @return A Descriptor of the requested InstrumentSample.
  +     *
  +     * @throws NoSuchInstrumentSampleException If the specified InstrumentSample
  +     *                                      does not exist.
  +     */
  +    InstrumentSampleDescriptor createInstrumentSample( String sampleDescription,
  +                                                       long sampleInterval,
  +                                                       int sampleSize,
  +                                                       long sampleLease,
  +                                                       int sampleType )
  +    {
  +        getLogger().info("Create new sample for " + m_name + ": interval=" + sampleInterval +
  +            ", size=" + sampleSize + ", lease=" + sampleLease + ", type=" +
  +            InstrumentSampleFactory.getInstrumentSampleTypeName( sampleType ) );
  +        
  +        // Validate the parameters
  +        long now = System.currentTimeMillis();
  +        
  +        // Generate a name for the new sample
  +        String sampleName = generateSampleName( m_name, sampleType, sampleInterval, sampleSize );
  +        
  +        synchronized( this )
  +        {
  +            // It is possible that the requested sample already exists.
  +            InstrumentSample instrumentSample = getInstrumentSample( sampleName );
  +            if ( instrumentSample != null )
  +            {
  +                // The requested sample already exists.
  +                instrumentSample.extendLease( sampleLease );
  +            }
  +            else
  +            {
  +                // The new sample needs to be created.
  +                instrumentSample = InstrumentSampleFactory.getInstrumentSample(
  +                    sampleType, sampleName, sampleInterval, sampleSize,
  +                    sampleDescription, sampleLease );
  +                instrumentSample.enableLogging( getLogger() );
  +                
  +                addInstrumentSample( instrumentSample );
  +            }
  +            
  +            return instrumentSample.getDescriptor();
  +        }
  +    }
  +    
  +    /**
        * Returns an array of Descriptors for the InstrumentSamples in the
        *  Instrument.
        *
  @@ -808,5 +867,20 @@
           default:
               throw new IllegalArgumentException( type + " is not a known Instrument type." );
           }
  +    }
  +    
  +    /**
  +     * Generates a sample name given its parameters.
  +     *
  +     * @param instrumentName Name of the instrument which owns the sample.
  +     */
  +    private String generateSampleName( String instrumentName,
  +                                       int sampleType,
  +                                       long sampleInterval,
  +                                       int sampleSize )
  +    {
  +        return instrumentName + "." +
  +            InstrumentSampleFactory.getInstrumentSampleTypeName( sampleType ) + "." + 
  +            sampleInterval + "." + sampleSize;
       }
   }
  
  
  
  1.4       +16 -1     jakarta-avalon-excalibur/instrument-manager/src/java/org/apache/avalon/excalibur/instrument/manager/InstrumentSample.java
  
  Index: InstrumentSample.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/instrument-manager/src/java/org/apache/avalon/excalibur/instrument/manager/InstrumentSample.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- InstrumentSample.java	3 Apr 2002 13:18:29 -0000	1.3
  +++ InstrumentSample.java	28 Apr 2002 17:05:41 -0000	1.4
  @@ -24,7 +24,7 @@
    *  InstrumentClient.
    *
    * @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/28 17:05:41 $
    * @since 4.1
    */
   public interface InstrumentSample
  @@ -99,6 +99,21 @@
        * @return The Type of the Instrument which can use the sample.
        */
       int getInstrumentType();
  +    
  +    /**
  +     * Returns the time that the current lease expires.  Permanent samples will
  +     *  return a value of 0.
  +     *
  +     * @return The time that the current lease expires.
  +     */
  +    long getLeaseExpirationTime();
  +    
  +    /**
  +     * Extends the lease to be lease milliseconds from the current time.
  +     *
  +     * @param lease The length of the lease in milliseconds.
  +     */
  +    void extendLease( long lease );
       
       /**
        * Obtains a static snapshot of the InstrumentSample.
  
  
  
  1.4       +12 -1     jakarta-avalon-excalibur/instrument-manager/src/java/org/apache/avalon/excalibur/instrument/manager/InstrumentSampleDescriptorImpl.java
  
  Index: InstrumentSampleDescriptorImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/instrument-manager/src/java/org/apache/avalon/excalibur/instrument/manager/InstrumentSampleDescriptorImpl.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- InstrumentSampleDescriptorImpl.java	3 Apr 2002 13:18:29 -0000	1.3
  +++ InstrumentSampleDescriptorImpl.java	28 Apr 2002 17:05:41 -0000	1.4
  @@ -16,7 +16,7 @@
    *  InstrumentSample object.
    *
    * @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/28 17:05:41 $
    * @since 4.1
    */
   public class InstrumentSampleDescriptorImpl
  @@ -126,6 +126,17 @@
       public int getInstrumentType()
       {
           return m_instrumentSample.getInstrumentType();
  +    }
  +    
  +    /**
  +     * Returns the time that the current lease expires.  Permanent samples will
  +     *  return a value of 0.
  +     *
  +     * @return The time that the current lease expires.
  +     */
  +    public long getLeaseExpirationTime()
  +    {
  +        return m_instrumentSample.getLeaseExpirationTime();
       }
       
       /**
  
  
  
  1.4       +67 -14    jakarta-avalon-excalibur/instrument-manager/src/java/org/apache/avalon/excalibur/instrument/manager/InstrumentSampleFactory.java
  
  Index: InstrumentSampleFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/instrument-manager/src/java/org/apache/avalon/excalibur/instrument/manager/InstrumentSampleFactory.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- InstrumentSampleFactory.java	22 Apr 2002 07:06:43 -0000	1.3
  +++ InstrumentSampleFactory.java	28 Apr 2002 17:05:41 -0000	1.4
  @@ -7,6 +7,7 @@
    */
   package org.apache.avalon.excalibur.instrument.manager;
   
  +import org.apache.avalon.excalibur.instrument.manager.interfaces.InstrumentManagerClient;
   import org.apache.avalon.framework.configuration.ConfigurationException;
   
   /**
  @@ -14,7 +15,7 @@
    * Access to InstrumentSamples are synchronized through the ProfileDataSet.
    *
    * @author <a href="mailto:leif@tanukisoftware.com">Leif Mortenson</a>
  - * @version CVS $Revision: 1.3 $ $Date: 2002/04/22 07:06:43 $
  + * @version CVS $Revision: 1.4 $ $Date: 2002/04/28 17:05:41 $
    * @since 4.1
    */
   class InstrumentSampleFactory
  @@ -22,40 +23,92 @@
       /**
        * A Profile Sample Type loaded in from a Configuration.
        *
  -     * @param type Type of the InstrumentSample to create.  Accepted values are:
  -     *              "max", "maximum", "min", "minimum", "mean", 
  -     *              "ctr", and "counter".
  +     * @param type Type of the InstrumentSample to create.
        * @param name The name of the new InstrumentSample.
        * @param interval The sample interval of the new InstrumentSample.
        * @param size The number of samples to store as history.
        * @param description The description of the new InstrumentSample.
  +     * @param lease Requested lease time in milliseconds.  A value of 0 implies
  +     *              that the lease will never expire.
        */
  -    static InstrumentSample getInstrumentSample( String type,
  -                                           String name,
  -                                           long interval,
  -                                           int size,
  -                                           String description )
  -        throws ConfigurationException
  +    static InstrumentSample getInstrumentSample( int type,
  +                                                 String name,
  +                                                 long interval,
  +                                                 int size,
  +                                                 String description,
  +                                                 long lease )
       {
  +        switch ( type )
  +        {
  +        case InstrumentManagerClient.INSTRUMENT_SAMPLE_TYPE_MAXIMUM:
  +            return new MaximumValueInstrumentSample( name, interval, size, description, lease );
  +            
  +        case InstrumentManagerClient.INSTRUMENT_SAMPLE_TYPE_MINIMUM:
  +            return new MinimumValueInstrumentSample( name, interval, size, description, lease );
  +        
  +        case InstrumentManagerClient.INSTRUMENT_SAMPLE_TYPE_MEAN:
  +            return new MeanValueInstrumentSample( name, interval, size, description, lease );
  +            
  +        case InstrumentManagerClient.INSTRUMENT_SAMPLE_TYPE_COUNTER:
  +            return new CounterInstrumentSample( name, interval, size, description, lease );
  +            
  +        default:
  +            throw new IllegalArgumentException( "'" + type + "' is not a valid sample type." );
  +        }
  +    }
  +    
  +    /**
  +     * Resolves an instrument sample type based on a name.
  +     *
  +     * @param type Type of the InstrumentSample to resolve.  Accepted values are:
  +     *              "max", "maximum", "min", "minimum", "mean", 
  +     *              "ctr", and "counter".
  +     *
  +     * @throws ConfigurationException if the specified sample type is unknown.
  +     */
  +    static int resolveInstrumentSampleType( String type )
  +        throws ConfigurationException {
  +        
           if ( type.equalsIgnoreCase( "max" ) || type.equalsIgnoreCase( "maximum" ) )
           {
  -            return new MaximumValueInstrumentSample( name, interval, size, description );
  +            return InstrumentManagerClient.INSTRUMENT_SAMPLE_TYPE_MAXIMUM;
           }
           else if ( type.equalsIgnoreCase( "min" ) || type.equalsIgnoreCase( "minimum" ) )
           {
  -            return new MinimumValueInstrumentSample( name, interval, size, description );
  +            return InstrumentManagerClient.INSTRUMENT_SAMPLE_TYPE_MINIMUM;
           }
           else if ( type.equalsIgnoreCase( "mean" ) )
           {
  -            return new MeanValueInstrumentSample( name, interval, size, description );
  +            return InstrumentManagerClient.INSTRUMENT_SAMPLE_TYPE_MEAN;
           }
           else if ( type.equalsIgnoreCase( "ctr" ) || type.equalsIgnoreCase( "counter" ) )
           {
  -            return new CounterInstrumentSample( name, interval, size, description );
  +            return InstrumentManagerClient.INSTRUMENT_SAMPLE_TYPE_COUNTER;
           }
           else
           {
               throw new ConfigurationException( "'" + type + "' is not a valid sample type." );
  +        }
  +    }
  +    
  +    static String getInstrumentSampleTypeName( int type )
  +    {
  +        switch ( type )
  +        {
  +        case InstrumentManagerClient.INSTRUMENT_SAMPLE_TYPE_MAXIMUM:
  +            return "maximum";
  +            
  +        case InstrumentManagerClient.INSTRUMENT_SAMPLE_TYPE_MINIMUM:
  +            return "minimum";
  +        
  +        case InstrumentManagerClient.INSTRUMENT_SAMPLE_TYPE_MEAN:
  +            return "mean";
  +            
  +        case InstrumentManagerClient.INSTRUMENT_SAMPLE_TYPE_COUNTER:
  +            return "counter";
  +            
  +        default:
  +            return "unknown-" + type;
           }
       }
   }
  
  
  
  1.3       +8 -3      jakarta-avalon-excalibur/instrument-manager/src/java/org/apache/avalon/excalibur/instrument/manager/MaximumValueInstrumentSample.java
  
  Index: MaximumValueInstrumentSample.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/instrument-manager/src/java/org/apache/avalon/excalibur/instrument/manager/MaximumValueInstrumentSample.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- MaximumValueInstrumentSample.java	3 Apr 2002 13:18:29 -0000	1.2
  +++ MaximumValueInstrumentSample.java	28 Apr 2002 17:05:41 -0000	1.3
  @@ -16,7 +16,7 @@
    *  period.
    *
    * @author <a href="mailto:leif@tanukisoftware.com">Leif Mortenson</a>
  - * @version CVS $Revision: 1.2 $ $Date: 2002/04/03 13:18:29 $
  + * @version CVS $Revision: 1.3 $ $Date: 2002/04/28 17:05:41 $
    * @since 4.1
    */
   class MaximumValueInstrumentSample
  @@ -35,10 +35,15 @@
        * @param interval The sample interval of the new InstrumentSample.
        * @param size The number of samples to store as history.  Assumes that size is at least 1.
        * @param description The description of the new InstrumentSample.
  +     * @param lease The length of the lease in milliseconds.
        */
  -    MaximumValueInstrumentSample( String name, long interval, int size, String description )
  +    MaximumValueInstrumentSample( String name,
  +                                  long interval,
  +                                  int size,
  +                                  String description,
  +                                  long lease )
       {
  -        super( name, interval, size, description );
  +        super( name, interval, size, description, lease );
       }
       
       /*---------------------------------------------------------------
  
  
  
  1.2       +8 -3      jakarta-avalon-excalibur/instrument-manager/src/java/org/apache/avalon/excalibur/instrument/manager/MeanValueInstrumentSample.java
  
  Index: MeanValueInstrumentSample.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/instrument-manager/src/java/org/apache/avalon/excalibur/instrument/manager/MeanValueInstrumentSample.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- MeanValueInstrumentSample.java	22 Apr 2002 07:06:43 -0000	1.1
  +++ MeanValueInstrumentSample.java	28 Apr 2002 17:05:41 -0000	1.2
  @@ -16,7 +16,7 @@
    *  period.
    *
    * @author <a href="mailto:leif@tanukisoftware.com">Leif Mortenson</a>
  - * @version CVS $Revision: 1.1 $ $Date: 2002/04/22 07:06:43 $
  + * @version CVS $Revision: 1.2 $ $Date: 2002/04/28 17:05:41 $
    * @since 4.1
    */
   class MeanValueInstrumentSample
  @@ -35,10 +35,15 @@
        * @param interval The sample interval of the new InstrumentSample.
        * @param size The number of samples to store as history.  Assumes that size is at least 1.
        * @param description The description of the new InstrumentSample.
  +     * @param lease The length of the lease in milliseconds.
        */
  -    MeanValueInstrumentSample( String name, long interval, int size, String description )
  +    MeanValueInstrumentSample( String name,
  +                               long interval,
  +                               int size,
  +                               String description,
  +                               long lease )
       {
  -        super( name, interval, size, description );
  +        super( name, interval, size, description, lease );
       }
       
       /*---------------------------------------------------------------
  
  
  
  1.3       +8 -3      jakarta-avalon-excalibur/instrument-manager/src/java/org/apache/avalon/excalibur/instrument/manager/MinimumValueInstrumentSample.java
  
  Index: MinimumValueInstrumentSample.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/instrument-manager/src/java/org/apache/avalon/excalibur/instrument/manager/MinimumValueInstrumentSample.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- MinimumValueInstrumentSample.java	3 Apr 2002 13:18:29 -0000	1.2
  +++ MinimumValueInstrumentSample.java	28 Apr 2002 17:05:41 -0000	1.3
  @@ -16,7 +16,7 @@
    *  period.
    *
    * @author <a href="mailto:leif@tanukisoftware.com">Leif Mortenson</a>
  - * @version CVS $Revision: 1.2 $ $Date: 2002/04/03 13:18:29 $
  + * @version CVS $Revision: 1.3 $ $Date: 2002/04/28 17:05:41 $
    * @since 4.1
    */
   class MinimumValueInstrumentSample
  @@ -35,10 +35,15 @@
        * @param interval The sample interval of the new InstrumentSample.
        * @param size The number of samples to store as history.  Assumes that size is at least 1.
        * @param description The description of the new InstrumentSample.
  +     * @param lease The length of the lease in milliseconds.
        */
  -    MinimumValueInstrumentSample( String name, long interval, int size, String description )
  +    MinimumValueInstrumentSample( String name,
  +                                  long interval,
  +                                  int size,
  +                                  String description,
  +                                  long lease )
       {
  -        super( name, interval, size, description );
  +        super( name, interval, size, description, lease );
       }
       
       /*---------------------------------------------------------------
  
  
  
  1.3       +31 -3     jakarta-avalon-excalibur/instrument-manager/src/java/org/apache/avalon/excalibur/instrument/manager/interfaces/InstrumentDescriptor.java
  
  Index: InstrumentDescriptor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/instrument-manager/src/java/org/apache/avalon/excalibur/instrument/manager/interfaces/InstrumentDescriptor.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- InstrumentDescriptor.java	3 Apr 2002 13:18:30 -0000	1.2
  +++ InstrumentDescriptor.java	28 Apr 2002 17:05:42 -0000	1.3
  @@ -12,7 +12,7 @@
    *  Instrument.
    *
    * @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/28 17:05:42 $
    * @since 4.1
    */
   public interface InstrumentDescriptor
  @@ -100,15 +100,43 @@
       /**
        * Returns a InstrumentSampleDescriptor based on its name.
        *
  -     * @param InstrumentSampleName Name of the InstrumentSample being requested.
  +     * @param instrumentSampleName Name of the InstrumentSample being requested.
        *
        * @return A Descriptor of the requested InstrumentSample.
        *
        * @throws NoSuchInstrumentSampleException If the specified InstrumentSample
        *                                      does not exist.
        */
  -    InstrumentSampleDescriptor getInstrumentSampleDescriptor( String InstrumentSampleName )
  +    InstrumentSampleDescriptor getInstrumentSampleDescriptor( String instrumentSampleName )
           throws NoSuchInstrumentSampleException;
  +    
  +    /**
  +     * Returns a InstrumentSampleDescriptor based on its name.  If the requested
  +     *  sample is invalid in any way, then an expired Descriptor will be
  +     *  returned.
  +     *
  +     * @param sampleDescription Description to assign to the new Sample.
  +     * @param sampleInterval Sample interval to use in the new Sample.
  +     * @param sampleLease Requested lease time for the new Sample in
  +     *                    milliseconds.  The InstrumentManager may grant a
  +     *                    lease which is shorter or longer than the requested
  +     *                    period.
  +     * @param sampleType Type of sample to request.  Must be one of the
  +     *                   following:  InstrumentManagerClient.INSTRUMENT_SAMPLE_TYPE_COUNTER,
  +     *                   InstrumentManagerClient.INSTRUMENT_SAMPLE_TYPE_MINIMUM,
  +     *                   InstrumentManagerClient.INSTRUMENT_SAMPLE_TYPE_MAXIMUM,
  +     *                   InstrumentManagerClient.INSTRUMENT_SAMPLE_TYPE_MEAN.
  +     *
  +     * @return A Descriptor of the requested InstrumentSample.
  +     *
  +     * @throws NoSuchInstrumentSampleException If the specified InstrumentSample
  +     *                                      does not exist.
  +     */
  +    InstrumentSampleDescriptor createInstrumentSample( String sampleDescription,
  +                                                       long sampleInterval,
  +                                                       int sampleSize,
  +                                                       long sampleLease,
  +                                                       int sampleType );
       
       /**
        * Returns an array of Descriptors for the InstrumentSamples configured for this
  
  
  
  1.3       +13 -1     jakarta-avalon-excalibur/instrument-manager/src/java/org/apache/avalon/excalibur/instrument/manager/interfaces/InstrumentManagerClient.java
  
  Index: InstrumentManagerClient.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/instrument-manager/src/java/org/apache/avalon/excalibur/instrument/manager/interfaces/InstrumentManagerClient.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- InstrumentManagerClient.java	3 Apr 2002 13:18:30 -0000	1.2
  +++ InstrumentManagerClient.java	28 Apr 2002 17:05:42 -0000	1.3
  @@ -14,7 +14,7 @@
   /**
    *
    * @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/28 17:05:42 $
    * @since 4.1
    */
   public interface InstrumentManagerClient
  @@ -27,6 +27,18 @@
       
       /** Type which identifies ValueInstruments. */
       int INSTRUMENT_TYPE_VALUE   = 2;
  +    
  +    /** Type which identifies CounterInstrumentSamples. */
  +    int INSTRUMENT_SAMPLE_TYPE_COUNTER = 101;
  +    
  +    /** Type which identifies MinimumInstrumentSamples. */
  +    int INSTRUMENT_SAMPLE_TYPE_MINIMUM = 102;
  +    
  +    /** Type which identifies MaximumInstrumentSamples. */
  +    int INSTRUMENT_SAMPLE_TYPE_MAXIMUM = 103;
  +    
  +    /** Type which identifies MeanInstrumentSamples. */
  +    int INSTRUMENT_SAMPLE_TYPE_MEAN = 104;
       
       /**
        * Returns the name used to identify this InstrumentManager.
  
  
  
  1.3       +9 -1      jakarta-avalon-excalibur/instrument-manager/src/java/org/apache/avalon/excalibur/instrument/manager/interfaces/InstrumentSampleDescriptor.java
  
  Index: InstrumentSampleDescriptor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/instrument-manager/src/java/org/apache/avalon/excalibur/instrument/manager/interfaces/InstrumentSampleDescriptor.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- InstrumentSampleDescriptor.java	3 Apr 2002 13:18:30 -0000	1.2
  +++ InstrumentSampleDescriptor.java	28 Apr 2002 17:05:42 -0000	1.3
  @@ -12,7 +12,7 @@
    *  InstrumentSample object.
    *
    * @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/28 17:05:42 $
    * @since 4.1
    */
   public interface InstrumentSampleDescriptor
  @@ -79,6 +79,14 @@
        * @return The Type of the Instrument which can use the sample.
        */
       int getInstrumentType();
  +    
  +    /**
  +     * Returns the time that the current lease expires.  Permanent samples will
  +     *  return a value of 0.
  +     *
  +     * @return The time that the current lease expires.
  +     */
  +    long getLeaseExpirationTime();
       
       /**
        * Obtains a static snapshot of the InstrumentSample.
  
  
  

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