001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018:
019: package org.apache.jmeter.visualizers;
020:
021: import java.util.Collection;
022:
023: import org.apache.jmeter.samplers.Clearable;
024: import org.apache.jmeter.samplers.SampleResult;
025: import org.apache.jmeter.util.JMeterUtils;
026:
027: public class SplineModel implements Clearable {
028: public final int DEFAULT_NUMBER_OF_NODES = 10;
029:
030: public final int DEFAULT_REFRESH_PERIOD = 1;
031:
032: protected final boolean SHOW_INCOMING_SAMPLES = true;
033:
034: protected int numberOfNodes = DEFAULT_NUMBER_OF_NODES;
035:
036: protected int refreshPeriod = DEFAULT_REFRESH_PERIOD;
037:
038: /** Current Spline curve. */
039: protected Spline3 dataCurve = null;
040:
041: SamplingStatCalculator samples;
042:
043: private GraphListener listener;
044:
045: private String name;
046:
047: public SplineModel() {
048: samples = new SamplingStatCalculator("Spline");
049: }
050:
051: public void setListener(GraphListener vis) {
052: listener = vis;
053: }
054:
055: public void setName(String newName) {
056: name = newName;
057: }
058:
059: public boolean isEditable() {
060: return true;
061: }
062:
063: public Spline3 getDataCurve() {
064: return dataCurve;
065: }
066:
067: public Class getGuiClass() {
068: return org.apache.jmeter.visualizers.SplineVisualizer.class;
069: }
070:
071: public Collection getAddList() {
072: return null;
073: }
074:
075: public String getClassLabel() {
076: return JMeterUtils.getResString("spline_visualizer_title");// $NON-NLS-1$
077: }
078:
079: public long getMinimum() {
080: return samples.getMin().longValue();
081: }
082:
083: public long getMaximum() {
084: return samples.getMax().longValue();
085: }
086:
087: public long getAverage() {
088: return (long) samples.getMean();
089: }
090:
091: public long getCurrent() {
092: return samples.getCurrentSample().getData();
093: }
094:
095: public long getSample(int i) {
096: return samples.getSample(i).getData();
097: }
098:
099: public long getNumberOfCollectedSamples() {
100: return samples.getCount();
101: }
102:
103: public String getName() {
104: return name;
105: }
106:
107: public void uncompile() {
108: clearData();
109: }
110:
111: public synchronized void clearData() {
112: // this.graph.clear();
113: samples.clear();
114:
115: this .dataCurve = null;
116:
117: if (listener != null) {
118: listener.updateGui();
119: }
120: }
121:
122: public synchronized void add(SampleResult sampleResult) {
123: samples.addSample(sampleResult);
124: long n = samples.getCount();
125:
126: if ((n % (numberOfNodes * refreshPeriod)) == 0) {
127: float[] floatNode = new float[numberOfNodes];
128: // NOTUSED: long[] longSample = getSamples();
129: // load each node
130: long loadFactor = n / numberOfNodes;
131:
132: for (int i = 0; i < numberOfNodes; i++) {
133: for (int j = 0; j < loadFactor; j++) {
134: floatNode[i] += samples.getSample(
135: (int) ((i * loadFactor) + j)).getData();
136: }
137: floatNode[i] = floatNode[i] / loadFactor;
138: }
139: // compute the new Spline curve
140: dataCurve = new Spline3(floatNode);
141: if (listener != null) {
142: listener.updateGui();
143: }
144: } else {// do nothing, wait for the next pile to complete
145: }
146: }
147: }
|