1 18 19 package org.apache.jmeter.visualizers; 20 21 import java.io.Serializable ; 22 import java.util.Collections ; 23 import java.util.Iterator ; 24 import java.util.LinkedList ; 25 import java.util.List ; 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 40 41 public class GraphAccumModel implements Clearable, Serializable 42 { 43 transient private static Logger log = LoggingManager.getLoggerForClass(); 44 45 protected String name; 46 protected List samples; 47 protected List 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 60 public GraphAccumModel() 61 { 62 log.debug("Start : GraphAccumModel1"); 63 listeners = new LinkedList (); 64 samples = Collections.synchronizedList(new LinkedList ()); 65 log.debug("End : GraphAccumModel1"); 66 } 67 68 73 public void setName(String name) 74 { 75 this.name = name; 76 } 77 78 83 public int getSampleCount() 84 { 85 return samples.size(); 86 } 87 88 93 public List getList() 94 { 95 return samples; 96 } 97 98 103 public String getName() 104 { 105 return name; 106 } 107 108 113 public long getMax() 114 { 115 log.debug("getMax1 : Returning - " + max); 116 return max; 117 } 118 119 126 public void addGraphAccumListener(GraphAccumListener listener) 127 { 128 listeners.add(listener); 129 } 130 131 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 149 public void addNewSample(SampleResult res) 150 { 151 log.debug("Start : addNewSample1"); 152 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 176 protected void fireDataChanged() 177 { 178 log.debug("Start : fireDataChanged1"); 179 Iterator 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 200 protected void quickUpdate(SampleResult s) 201 { 202 Iterator iter = listeners.iterator(); 203 { 204 while (iter.hasNext()) 205 { 206 ((GraphAccumListener) iter.next()).updateGui(s); 207 } 208 } 209 } 210 } 211 212 | Popular Tags |