1 18 package org.apache.activemq.management; 19 20 21 26 public class TimeStatisticImpl extends StatisticImpl { 27 private long count; 28 private long maxTime; 29 private long minTime; 30 private long totalTime; 31 private TimeStatisticImpl parent; 32 33 public TimeStatisticImpl(String name, String description) { 34 this(name, "millis", description); 35 } 36 37 public TimeStatisticImpl(TimeStatisticImpl parent, String name, String description) { 38 this(name, description); 39 this.parent = parent; 40 } 41 42 public TimeStatisticImpl(String name, String unit, String description) { 43 super(name, unit, description); 44 } 45 46 public synchronized void reset() { 47 super.reset(); 48 count = 0; 49 maxTime = 0; 50 minTime = 0; 51 totalTime = 0; 52 } 53 54 public synchronized long getCount() { 55 return count; 56 } 57 58 public synchronized void addTime(long time) { 59 count++; 60 totalTime += time; 61 if (time > maxTime) { 62 maxTime = time; 63 } 64 if (time < minTime || minTime == 0) { 65 minTime = time; 66 } 67 updateSampleTime(); 68 if (parent != null) { 69 parent.addTime(time); 70 } 71 } 72 73 76 public long getMaxTime() { 77 return maxTime; 78 } 79 80 83 public synchronized long getMinTime() { 84 return minTime; 85 } 86 87 90 public synchronized long getTotalTime() { 91 return totalTime; 92 } 93 94 98 public synchronized double getAverageTime() { 99 if (count == 0) { 100 return 0; 101 } 102 double d = totalTime; 103 return d / count; 104 } 105 106 107 112 public synchronized double getAverageTimeExcludingMinMax() { 113 if (count <= 2) { 114 return 0; 115 } 116 double d = totalTime - minTime - maxTime; 117 return d / (count - 2); 118 } 119 120 121 124 public double getAveragePerSecond() { 125 double d = 1000; 126 double averageTime = getAverageTime(); 127 if (averageTime == 0) { 128 return 0; 129 } 130 return d / averageTime; 131 } 132 133 136 public double getAveragePerSecondExcludingMinMax() { 137 double d = 1000; 138 double average = getAverageTimeExcludingMinMax(); 139 if (average == 0) { 140 return 0; 141 } 142 return d / average; 143 } 144 145 public TimeStatisticImpl getParent() { 146 return parent; 147 } 148 149 public void setParent(TimeStatisticImpl parent) { 150 this.parent = parent; 151 } 152 153 protected synchronized void appendFieldDescription(StringBuffer buffer) { 154 buffer.append(" count: "); 155 buffer.append(Long.toString(count)); 156 buffer.append(" maxTime: "); 157 buffer.append(Long.toString(maxTime)); 158 buffer.append(" minTime: "); 159 buffer.append(Long.toString(minTime)); 160 buffer.append(" totalTime: "); 161 buffer.append(Long.toString(totalTime)); 162 buffer.append(" averageTime: "); 163 buffer.append(Double.toString(getAverageTime())); 164 buffer.append(" averageTimeExMinMax: "); 165 buffer.append(Double.toString(getAverageTimeExcludingMinMax())); 166 buffer.append(" averagePerSecond: "); 167 buffer.append(Double.toString(getAveragePerSecond())); 168 buffer.append(" averagePerSecondExMinMax: "); 169 buffer.append(Double.toString(getAveragePerSecondExcludingMinMax())); 170 super.appendFieldDescription(buffer); 171 } 172 173 } 174 | Popular Tags |