neth        01/08/29 04:52:50

  Added:       src/org/apache/jmeter/visualizers GraphAccumModel.java
  Log:
  The model which handles all the sample for the line graph displaying the
  response time of the sample and all its components.
  
  Revision  Changes    Path
  1.1                  
jakarta-jmeter/src/org/apache/jmeter/visualizers/GraphAccumModel.java
  
  Index: GraphAccumModel.java
  ===================================================================
  /*
   * ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   * notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   * notice, this list of conditions and the following disclaimer in
   * the documentation and/or other materials provided with the
   * distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   * if any, must include the following acknowledgment:
   * "This product includes software developed by the
   * Apache Software Foundation (http://www.apache.org/)."
   * Alternately, this acknowledgment may appear in the software itself,
   * if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   * "Apache JMeter" must not be used to endorse or promote products
   * derived from this software without prior written permission. For
   * written permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache",
   * "Apache JMeter", nor may "Apache" appear in their name, without
   * prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  package org.apache.jmeter.visualizers;
  
  import org.apache.jmeter.gui.*;
  import java.util.*;
  
  import org.apache.jmeter.samplers.*;
  import org.apache.jmeter.save.Saveable;
  
  import org.apache.jmeter.protocol.http.sampler.HTTPSamplerFull;
  
  import org.apache.log4j.*;
  /**
   * The model that collects the average of the set of pages to be sampled
   *
   * @author     Khor Soon Hin
   * @created    2001/08/11
   * @version    1.0
   */
  
  public class GraphAccumModel implements JMeterComponentModel,
    SampleListener, Saveable, Clearable, GraphVisualizerModel
  {
    private Category catClass = 
      Category.getInstance(GraphAccumModel.class.getName());
    protected String name;
    protected List samples;
    protected List listeners;
    protected long averageSum = 0;
    protected long variationSum = 0;
    protected long counter = 0;
    protected long previous = 0;
    protected long max = 1;
    protected boolean bigChange = false;
    protected SampleResult current;
  
    /**
     *  Constructor
     */
    public GraphAccumModel()
    {
      catClass.debug("Start : GraphAccumModel1");
      listeners = new LinkedList();
      samples = Collections.synchronizedList(new LinkedList());
      catClass.debug("End : GraphAccumModel1");
    }
  
    /**
     * Uncompile this component from sampler controller
     */
    public void uncompile()
    {
      catClass.debug("Start : uncompile1");
      catClass.debug("End : uncompile1");
    }
  
    /**
     * Returns the class handles the saving of this component
     *
     * @return  the class that handles the saving of this component
     */
    public Class getTagHandlerClass()
    {
      Class tagHandler = 
        org.apache.jmeter.save.handlers.JMeterComponentHandler.class;
      catClass.debug("getTagHandlerClass1 : Returning - " + tagHandler);
      return tagHandler;
    }
  
    /**
     * Depending on whether the graph needs to be rescale call the appropriate
     * methods
     */
    protected void fireDataChanged()
    {
      catClass.debug("Start : fireDataChanged1");
      Iterator iter = listeners.iterator();
      if(bigChange)
      {
        while (iter.hasNext())
        {
          ((ModelSupported)iter.next()).updateGui();
        }
        bigChange = false;
      }
      else
      {
        quickUpdate(current);
      }
      catClass.debug("End : fireDataChanged1");
    }
  
    /**
     * Clears all the image visualizers
     */
    protected void fireClear()
    {
      catClass.debug("Start : fireClear1");
      Iterator iter = listeners.iterator();
      while(iter.hasNext())
      {
        ((GenericGraphListener)iter.next()).clear();
      }
      catClass.debug("End : fireClear1");
    }
  
    /**
     * The sample to be added did not exceed the current set of samples so
     * do not need to rescale graph
     *
     * @param   latest sample to be added
     */
    protected void quickUpdate(SampleResult s)
    {
      Iterator iter = listeners.iterator();
      {
        while (iter.hasNext())
        {
          ((GraphAccumListener)iter.next()).updateGui(s);
        }
      }
    }
  
    public int getSampleCount()
    {
      return samples.size();
    }
  
    public void addModelListener(java.awt.Component modelListener)
    {
      listeners.add(modelListener);
    }
  
    public List getList()
    {
      return samples;
    }
  
    /**
     *  Sets the Name attribute of the GraphModel object
     *
     *@param  name  The new Name value
     */
    public void setName(String name)
    {
      this.name = name;
    }
  
    /**
     * Gets the GuiClass attribute of the GraphModel object
     *
     * @return    The GuiClass value
     */
    public Class getGuiClass()
    {
      Class guiClass = GraphAccumVisualizer.class;
      catClass.debug("getGuiClass1 : Returning - " + guiClass);
      return guiClass;
    }
  
    /**
     * Gets the Name attribute of the GraphModel object
     *
     * @return    The Name value
     */
    public String getName()
    {
      return name;
    }
  
    /**
     * Determines whether this object is editable
     *
     * @return    The Editable value
     */
    public boolean isEditable()
    {
      return false;
    }
  
    /**
     * Returns the elements which can be added to this object
     *
     * @return    The AddList value
     */
    public Collection getAddList()
    {
      return null;
    }
  
   /**
    * Gets the ClassLabel attribute of the GraphModel object
    *
    * @return    The ClassLabel value
    */
    public String getClassLabel()
    {
      return "GraphFull Results";
    }
  
    /**
     * All the things that needs to be done when a sample occurs
     *
     * @param e the sample
     */
    public void sampleOccurred(SampleEvent e)
    {
      catClass.debug("Start : sampleOccurred1");
      if(catClass.isDebugEnabled())
      {
        catClass.debug("sampleOccurred1 : sample event - " + e);
      }
      addNewSample(e.getResult());
      this.fireDataChanged();
      catClass.debug("End : sampleOccurred1");
    }
  
    public void sampleStarted(SampleEvent e)
    {
    }
  
    public long getMax()
    {
      catClass.debug("getMax1 : Returning - " + max);
      return max;
    }
  
    /**
     * Clear the results
     */
    public void clear()
    {
      catClass.debug("Start : clear1");
      samples.clear();
      max = 1;
      bigChange = true;
      this.fireDataChanged();
      this.fireClear();
      catClass.debug("End : clear1");
    }
  
    /**
     * Add the new sample to the results
     *
     * @param res               sample containing the results
     */
    private void addNewSample(SampleResult res)
    {
      catClass.debug("Start : addNewSample1");
      // set time to time taken to load this url without components (e.g. images etc)
      long totalTime = res.getTime();
      // however if there is a total time value then the url has other components
      // thus set the total time to be that value
      Long totalTimeLong = (Long)res.getValue(HTTPSamplerFull.TOTAL_TIME);
      if(totalTimeLong != null)
      {
        totalTime = totalTimeLong.longValue();
      }
      if(catClass.isDebugEnabled())
      {
        catClass.debug("addNewSample1 : time - " + totalTime);
        catClass.debug("addNewSample1 : max - " + max);
      }
      if (totalTime > max)
      {
        bigChange = true;
        max = totalTime;
      }
      current = res;
      samples.add(res);
      catClass.debug("End : addNewSample1");
    }
  
    public void sampleStopped(SampleEvent e)
    {
    }
  
    public void addJMeterComponent(JMeterComponentModel child)
    {
    }
  }
  
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to