/* Copyright (c) 2002 by Oracle Corporation. All Rights Reserved. */

package oracle.portal.provider.v2.monitor;

import java.util.TimerTask;

/**
 * This class contains the methods and constants for provider code to log
 * performance statistics and to track the progress of a request.
 */
public abstract class PerfMonitor extends TimerTask 
{
    // Used for cache property setters
    public static final String VALIDATION_HIT = "HIT,PING";
    public static final String VALIDATION_STALE = "MISS,STALE";
    public static final String VALIDATION_NEW = "MISS,NEW";
    public static final String EXPIRES_MISS = "MISS,EXPIRES";

    // Ids for provider public timers.
    public static final int RENDER_HEADER_TIMER = 0;
    public static final int RENDER_FOOTER_TIMER = 1;
    public static final int READ_CUSTOMIZATION_ACCR = 2;
    public static final int WRITE_CUSTOMIZATION_ACCR =3;
    public static final int LAST_TIMER = WRITE_CUSTOMIZATION_ACCR;
    
    // Timer types - true = one shot timer, false = accumulator
    public static boolean[] TIMER_TYPES = {true, true, false, false};
    
    // Ids for public properties
    public static final int CACHE_TYPE = 0;
    public static final int CACHE_LEVEL = 1;
    public static final int EXPIRY_TIME = 2;
    public static final int CACHE_KEY_REQUEST = 3;
    public static final int CACHE_KEY_RESPONSE = 4;
    public static final int LAST_PROPERTY = CACHE_KEY_RESPONSE;
    
    /**
     * Starts a timer with a given id.
     *
     * @param timerId the id of the timer to be started
     *
     * @exception IllegalArgumentException thrown if the timer id is invalid
     * @exception IllegalStateException thrown if the timer is running or has 
     *           been stopped
     */    
    public abstract void startTimer(int timerId) 
        throws IllegalArgumentException, IllegalArgumentException;

    /**
     * Stops a timer with a given id.
     *
     * @param timerId the id of the timer to be stopped
     *
     * @exception IllegalArgumentException thrown if the timer id is invalid
     * @exception IllegalStateException thrown if the timer has already been 
     *           stopped or has not been started
     */
    public abstract void finishTimer(int timerId)
        throws IllegalArgumentException, IllegalArgumentException;
  
   /**
    * Sets a property with a given id to the value specified.
    *
    * @param propertyId the id of the property to be set
    * @param value a <code>String</code> value to which the property is set
    *
    * @exception IllegalArgumentException thrown if the property id is invalid
    */
    public abstract void setProperty(int propertyId, String value)
        throws IllegalArgumentException;

   /**
    * Sets a property with a given id to the value specified.
    *
    * @param propertyId the id of the property to be set
    * @param value a <code>long</code> value to which the property is set
    *
    * @exception IllegalArgumentException thrown if the property id is invalid
    */
    public abstract void setProperty(int propertyId, long value)
        throws IllegalArgumentException;

   /**
    * Used to find whether the execution time of the current request thread has
    * exceeded the provider warning timeout.
    *
    * @return a boolean indicating whether or not the timeout has elapsed.
    */
    public abstract boolean hasTimeoutElapsed();
}
