1 22 package org.jboss.management.j2ee.statistics; 23 24 import javax.management.j2ee.statistics.TimeStatistic ; 25 26 33 public class TimeStatisticImpl 34 extends StatisticImpl 35 implements TimeStatistic 36 { 37 41 42 private static final long serialVersionUID = -3508391696541148001L; 43 44 48 protected long count; 49 protected long minTime; 50 protected long maxTime; 51 protected long totalTime; 52 protected double requestRate; 53 54 private long start; 55 56 60 67 public TimeStatisticImpl(String name, String units, String description) 68 { 69 super(name, units, description); 70 start = System.currentTimeMillis(); 71 } 72 73 77 80 public long getCount() 81 { 82 return count; 83 } 84 85 88 public long getMinTime() 89 { 90 return minTime; 91 } 92 93 96 public long getMaxTime() 97 { 98 return maxTime; 99 } 100 101 105 public long getTotalTime() 106 { 107 return totalTime; 108 } 109 110 114 public double getRequestRate() 115 { 116 return requestRate; 117 } 118 119 122 public String toString() 123 { 124 return "[ " + 125 "Count: " + getCount() + 126 ", Min. Time: " + getMinTime() + 127 ", Max. Time: " + getMaxTime() + 128 ", Total Time: " + getTotalTime() + 129 ", Request Rate: " + getRequestRate() + 130 ", " + super.toString() + " ]"; 131 } 132 133 137 143 public void add(long pTime) 144 { 145 count++; 146 if (pTime == 0) 147 { 148 minTime = 1; 149 } 150 if (minTime == 0) 151 { 152 minTime = pTime; 153 } 154 minTime = pTime < minTime ? pTime : minTime; 155 maxTime = pTime > maxTime ? pTime : maxTime; 156 totalTime += pTime; 157 requestRate = (System.currentTimeMillis() - start) / count; 158 } 159 160 163 public void reset() 164 { 165 count = 0; 166 minTime = 0; 167 maxTime = 0; 168 totalTime = 0; 169 requestRate = 0; 170 super.reset(); 171 } 172 173 181 public void set(long count, long minTime, long maxTime, long totalTime) 182 { 183 this.count = count; 184 this.minTime = minTime; 185 this.maxTime = maxTime; 186 this.totalTime = totalTime; 187 if (count == 0) 188 this.requestRate = Double.NaN; 189 else 190 this.requestRate = totalTime / count; 191 } 192 } 193 | Popular Tags |