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.io.Serializable;
022: import java.text.Format;
023: import java.util.Date;
024:
025: /**
026: * @author Michael Stover
027: * @version 1.0
028: */
029:
030: public class Sample implements Serializable, Comparable {
031: private final long data; // = elapsed
032:
033: private final long average;
034:
035: private final long median;
036:
037: private final long distributionLine; // TODO: what is this for?
038:
039: private final long deviation;
040:
041: private final double throughput;
042:
043: private final long errorCount;
044:
045: private final boolean success;
046:
047: private final String label;
048:
049: private final String threadName;
050:
051: private final long count;
052:
053: private final long endTime;
054:
055: private final int bytes;
056:
057: // TODO - is this used?
058: public Sample(long data, long average, long deviation,
059: double throughput, long median, boolean success) {
060: this (null, data, average, deviation, median, 0, throughput, 0,
061: success, 0, 0);
062: }
063:
064: // TODO - is this used?
065: public Sample(long data) {
066: this (null, data, 0, 0, 0, 0, 0, 0, false, 0, 0);
067: }
068:
069: public Sample(String name, long data, long average, long deviation,
070: long median, long distributionLine, double throughput,
071: long errorCount, boolean success, long num, long endTime) {
072: this .data = data;
073: this .average = average;
074: this .deviation = deviation;
075: this .throughput = throughput;
076: this .success = success;
077: this .median = median;
078: this .distributionLine = distributionLine;
079: this .label = name;
080: this .errorCount = errorCount;
081: this .count = num;
082: this .endTime = endTime;
083: this .bytes = 0;
084: this .threadName = "";
085: }
086:
087: public Sample(String name, long data, long average, long deviation,
088: long median, long distributionLine, double throughput,
089: long errorCount, boolean success, long num, long endTime,
090: int bytes) {
091: this .data = data;
092: this .average = average;
093: this .deviation = deviation;
094: this .throughput = throughput;
095: this .success = success;
096: this .median = median;
097: this .distributionLine = distributionLine;
098: this .label = name;
099: this .errorCount = errorCount;
100: this .count = num;
101: this .endTime = endTime;
102: this .bytes = bytes;
103: this .threadName = "";
104: }
105:
106: public Sample(String name, long data, long average, long deviation,
107: long median, long distributionLine, double throughput,
108: long errorCount, boolean success, long num, long endTime,
109: int bytes, String threadName) {
110: this .data = data;
111: this .average = average;
112: this .deviation = deviation;
113: this .throughput = throughput;
114: this .success = success;
115: this .median = median;
116: this .distributionLine = distributionLine;
117: this .label = name;
118: this .errorCount = errorCount;
119: this .count = num;
120: this .endTime = endTime;
121: this .bytes = bytes;
122: this .threadName = threadName;
123: }
124:
125: public Sample() {
126: this (null, 0, 0, 0, 0, 0, 0, 0, true, 0, 0);
127: }
128:
129: // Appears not to be used - however it is invoked via the Functor class
130: public int getBytes() {
131: return bytes;
132: }
133:
134: /**
135: * @return Returns the average.
136: */
137: public long getAverage() {
138: return average;
139: }
140:
141: /**
142: * @return Returns the count.
143: */
144: public long getCount() {
145: return count;
146: }
147:
148: /**
149: * @return Returns the data (usually elapsed time)
150: */
151: public long getData() {
152: return data;
153: }
154:
155: /**
156: * @return Returns the deviation.
157: */
158: public long getDeviation() {
159: return deviation;
160: }
161:
162: /**
163: * @return Returns the distributionLine.
164: */
165: public long getDistributionLine() {
166: return distributionLine;
167: }
168:
169: /**
170: * @return Returns the error.
171: */
172: public boolean isSuccess() {
173: return success;
174: }
175:
176: /**
177: * @return Returns the errorRate.
178: */
179: public long getErrorCount() {
180: return errorCount;
181: }
182:
183: /**
184: * @return Returns the label.
185: */
186: public String getLabel() {
187: return label;
188: }
189:
190: /**
191: * @return Returns the threadName.
192: */
193: public String getThreadName() {
194: return threadName;
195: }
196:
197: /**
198: * @return Returns the median.
199: */
200: public long getMedian() {
201: return median;
202: }
203:
204: /**
205: * @return Returns the throughput.
206: */
207: public double getThroughput() {
208: return throughput;
209: }
210:
211: /*
212: * (non-Javadoc)
213: *
214: * @see java.lang.Comparable#compareTo(java.lang.Object)
215: */
216: public int compareTo(Object o) {
217: Sample oo = (Sample) o;
218: return ((count - oo.count) < 0 ? -1 : (count == oo.count ? 0
219: : 1));
220: }
221:
222: /**
223: * @return Returns the endTime.
224: */
225: public long getEndTime() {
226: return endTime;
227: }
228:
229: /**
230: * @return Returns the (calculated) startTime, assuming Data is the elapsed time.
231: */
232: public long getStartTime() {
233: return endTime - data;
234: }
235:
236: /**
237: * @return the start time using the specified format
238: * Intended for use from Functors
239: */
240: public String getStartTimeFormatted(Format format) {
241: return format.format(new Date(getStartTime()));
242: }
243: }
|