KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jmeter > visualizers > GraphAccumModel


1 // $Header: /home/cvs/jakarta-jmeter/src/components/org/apache/jmeter/visualizers/GraphAccumModel.java,v 1.9 2004/02/13 01:48:46 sebb Exp $
2
/*
3  * Copyright 2001-2004 The Apache Software Foundation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17 */

18
19 package org.apache.jmeter.visualizers;
20
21 import java.io.Serializable JavaDoc;
22 import java.util.Collections JavaDoc;
23 import java.util.Iterator JavaDoc;
24 import java.util.LinkedList JavaDoc;
25 import java.util.List JavaDoc;
26
27 import org.apache.jmeter.samplers.Clearable;
28 import org.apache.jmeter.samplers.SampleResult;
29 import org.apache.jorphan.logging.LoggingManager;
30 import org.apache.log.Logger;
31
32
33 /**
34  * The model that collects the average of the set of pages to be sampled.
35  *
36  * @author Khor Soon Hin
37  * Created 2001/08/11
38  * @version $Revision: 1.9 $ Last updated: $Date: 2004/02/13 01:48:46 $
39  */

40
41 public class GraphAccumModel implements Clearable, Serializable JavaDoc
42 {
43     transient private static Logger log = LoggingManager.getLoggerForClass();
44
45     protected String JavaDoc name;
46     protected List JavaDoc samples;
47     protected List JavaDoc listeners;
48
49     protected long averageSum = 0;
50     protected long variationSum = 0;
51     protected long counter = 0;
52     protected long previous = 0;
53     protected long max = 1;
54     protected boolean bigChange = false;
55     protected SampleResult current;
56
57     /**
58      * Constructor.
59      */

60     public GraphAccumModel()
61     {
62         log.debug("Start : GraphAccumModel1");
63         listeners = new LinkedList JavaDoc();
64         samples = Collections.synchronizedList(new LinkedList JavaDoc());
65         log.debug("End : GraphAccumModel1");
66     }
67
68     /**
69      * Sets the Name attribute of the GraphModel object.
70      *
71      * @param name the new Name value
72      */

73     public void setName(String JavaDoc name)
74     {
75         this.name = name;
76     }
77
78     /**
79      * Gets the SampleCount attribute of the GraphAccumModel object.
80      *
81      * @return the SampleCount value
82      */

83     public int getSampleCount()
84     {
85         return samples.size();
86     }
87
88     /**
89      * Gets the List attribute of the GraphAccumModel object.
90      *
91      * @return the List value
92      */

93     public List JavaDoc getList()
94     {
95         return samples;
96     }
97
98     /**
99      * Gets the Name attribute of the GraphModel object.
100      *
101      * @return the Name value
102      */

103     public String JavaDoc getName()
104     {
105         return name;
106     }
107
108     /**
109      * Gets the Max attribute of the GraphAccumModel object.
110      *
111      * @return the Max value
112      */

113     public long getMax()
114     {
115         log.debug("getMax1 : Returning - " + max);
116         return max;
117     }
118
119     /**
120      * Adds a feature to the ModelListener attribute of the GraphAccumModel
121      * object.
122      *
123      * @param listener the feature to be added to the GraphAccumListener
124      * attribute.
125      */

126     public void addGraphAccumListener(GraphAccumListener listener)
127     {
128         listeners.add(listener);
129     }
130
131     /**
132      * Clear the results.
133      */

134     public void clear()
135     {
136         log.debug("Start : clear1");
137         samples.clear();
138         max = 1;
139         bigChange = true;
140         this.fireDataChanged();
141         log.debug("End : clear1");
142     }
143
144     /**
145      * Add the new sample to the results.
146      *
147      * @param res sample containing the results
148      */

149     public void addNewSample(SampleResult res)
150     {
151         log.debug("Start : addNewSample1");
152         // Set time to time taken to load this url without components (e.g.
153
// images etc)
154
long totalTime = res.getTime();
155
156         if (log.isDebugEnabled())
157         {
158             log.debug("addNewSample1 : time - " + totalTime);
159             log.debug("addNewSample1 : max - " + max);
160         }
161         if (totalTime > max)
162         {
163             bigChange = true;
164             max = totalTime;
165         }
166         current = res;
167         samples.add(res);
168         log.debug("End : addNewSample1");
169         fireDataChanged();
170     }
171
172     /**
173      * Depending on whether the graph needs to be rescale call the appropriate
174      * methods.
175      */

176     protected void fireDataChanged()
177     {
178         log.debug("Start : fireDataChanged1");
179         Iterator JavaDoc iter = listeners.iterator();
180
181         if (bigChange)
182         {
183             while (iter.hasNext())
184             {
185                 ((GraphAccumListener) iter.next()).updateGui();
186             }
187             bigChange = false;
188         }
189         else
190         {
191             quickUpdate(current);
192         }
193         log.debug("End : fireDataChanged1");
194     }
195
196     /**
197      * The sample to be added did not exceed the current set of samples so do
198      * not need to rescale graph.
199      */

200     protected void quickUpdate(SampleResult s)
201     {
202         Iterator JavaDoc iter = listeners.iterator();
203         {
204             while (iter.hasNext())
205             {
206                 ((GraphAccumListener) iter.next()).updateGui(s);
207             }
208         }
209     }
210 }
211
212
Popular Tags