1 28 29 30 package com.caucho.management.j2ee; 31 32 import com.caucho.util.Alarm; 33 34 import javax.management.j2ee.statistics.*; 35 import java.lang.reflect.InvocationTargetException ; 36 import java.lang.reflect.Method ; 37 import java.util.ArrayList ; 38 import java.util.TreeSet ; 39 40 public class StatsSupport 41 implements Stats 42 { 43 private final J2EEManagedObject _j2eeManagedObject; 44 45 public StatsSupport(J2EEManagedObject j2eeManagedObject) 46 { 47 _j2eeManagedObject = j2eeManagedObject; 48 } 49 50 public String []getStatisticNames() 51 { 52 TreeSet <String > names = new TreeSet <String >(); 53 54 for (Method method : getClass().getMethods()) { 55 if (Statistic.class.isAssignableFrom(method.getReturnType())) { 56 String name = method.getName(); 57 58 if (name.startsWith("get")) 59 names.add(name.substring(3)); 60 } 61 } 62 63 return names.toArray(new String [names.size()]); 64 } 65 66 public Statistic getStatistic(String name) 67 { 68 try { 69 Method method = getClass().getMethod("get" + name); 70 71 return (Statistic) method.invoke(this, (Object []) null); 72 } 73 catch (NoSuchMethodException e) { 74 return null; 75 } 76 catch (IllegalAccessException e) { 77 return null; 78 } 79 catch (InvocationTargetException e) { 80 return null; 81 } 82 } 83 84 public Statistic []getStatistics() 85 { 86 ArrayList <Statistic> statistics = new ArrayList <Statistic>(); 87 88 for (Method method : getClass().getMethods()) { 89 if (Statistic.class.isAssignableFrom(method.getReturnType())) { 90 try { 91 statistics.add((Statistic) method.invoke(this, (Object []) null)); 92 } 93 catch (IllegalAccessException e) { 94 continue; 95 } 96 catch (InvocationTargetException e) { 97 continue; 98 } 99 } 100 } 101 102 return statistics.toArray(new Statistic[statistics.size()]); 103 } 104 105 class StatisticSupport 106 implements Statistic 107 { 108 public final String _name; 109 110 public StatisticSupport(String name) 111 { 112 _name = name; 113 } 114 115 public String getName() 116 { 117 return _name; 118 } 119 120 public String getUnit() 121 { 122 return "UNKNOWN"; 123 } 124 125 public String getDescription() 126 { 127 return ""; 128 } 129 130 public long getStartTime() 131 { 132 return _j2eeManagedObject.getStartTime(); 133 } 134 135 public long getLastSampleTime() 136 { 137 return Alarm.getCurrentTime(); 138 } 139 } 140 141 class TimeStatisticImpl 142 extends StatisticSupport 143 implements TimeStatistic 144 { 145 private long _count; 146 private long _maxTime; 147 private long _minTime; 148 private long _totalTime; 149 150 public TimeStatisticImpl(String name, 151 long count, 152 long maxTime, 153 long minTime, 154 long totalTime) 155 { 156 super(name); 157 158 _count = count; 159 _maxTime = maxTime; 160 _minTime = minTime; 161 _totalTime = totalTime; 162 } 163 164 public String getUnit() 165 { 166 return "MILLISECOND"; 167 } 168 169 public long getCount() 170 { 171 return _count; 172 } 173 174 public long getMaxTime() 175 { 176 return _maxTime; 177 } 178 179 public long getMinTime() 180 { 181 return _minTime; 182 } 183 184 public long getTotalTime() 185 { 186 return _totalTime; 187 } 188 } 189 190 class RangeStatisticImpl 191 extends StatisticSupport 192 implements RangeStatistic 193 { 194 private long _highWaterMark; 195 private long _lowWaterMark; 196 private long _current; 197 198 public RangeStatisticImpl(String name, 199 long highWaterMark, 200 long lowWaterMark, 201 long current) 202 { 203 super(name); 204 205 _highWaterMark = highWaterMark; 206 _lowWaterMark = lowWaterMark; 207 _current = current; 208 } 209 210 public long getHighWaterMark() 211 { 212 return _highWaterMark; 213 } 214 215 public long getLowWaterMark() 216 { 217 return _lowWaterMark; 218 } 219 220 public long getCurrent() 221 { 222 return _current; 223 } 224 } 225 226 class BoundaryStatisticImpl 227 extends StatisticSupport 228 implements BoundaryStatistic 229 { 230 private long _upperBound; 231 private long _lowerBound; 232 233 public BoundaryStatisticImpl(String name, long upperBound, long lowerBound) 234 { 235 super(name); 236 _upperBound = upperBound; 237 _lowerBound = lowerBound; 238 } 239 240 public long getUpperBound() 241 { 242 return _upperBound; 243 } 244 245 public long getLowerBound() 246 { 247 return _lowerBound; 248 } 249 } 250 251 class CountStatisticImpl 252 extends StatisticSupport 253 implements CountStatistic 254 { 255 private long _count; 256 257 public CountStatisticImpl(String name, long count) 258 { 259 super(name); 260 _count = count; 261 } 262 263 public long getCount() 264 { 265 return _count; 266 } 267 } 268 269 class BoundedRangeStatisticImpl 270 extends StatisticSupport 271 implements BoundedRangeStatistic 272 { 273 private long _upperBound; 274 private long _lowerBound; 275 private long _highWaterMark; 276 private long _lowWaterMark; 277 private long _current; 278 279 public BoundedRangeStatisticImpl(String name, 280 long upperBound, 281 long lowerBound, 282 long highWaterMark, 283 long lowWaterMark, 284 long current) 285 { 286 super(name); 287 288 _upperBound = upperBound; 289 _lowerBound = lowerBound; 290 _highWaterMark = highWaterMark; 291 _lowWaterMark = lowWaterMark; 292 _current = current; 293 } 294 295 public long getUpperBound() 296 { 297 return _upperBound; 298 } 299 300 public long getLowerBound() 301 { 302 return _lowerBound; 303 } 304 305 public long getHighWaterMark() 306 { 307 return _highWaterMark; 308 } 309 310 public long getLowWaterMark() 311 { 312 return _lowWaterMark; 313 } 314 315 public long getCurrent() 316 { 317 return _current; 318 } 319 } 320 321 class UnimplementedTimeStatistic 322 extends TimeStatisticImpl 323 { 324 public UnimplementedTimeStatistic(String name) 325 { 326 super(name, -1, -1, -1, -1); 327 } 328 } 329 330 class UnimplementedRangeStatistic 331 extends RangeStatisticImpl 332 { 333 public UnimplementedRangeStatistic(String name) 334 { 335 super(name, -1, -1, -1); 336 } 337 } 338 339 class UnimplementedBoundaryStatistic 340 extends BoundaryStatisticImpl 341 { 342 public UnimplementedBoundaryStatistic(String name) 343 { 344 super(name, -1, -1); 345 } 346 } 347 348 class UnimplementedCountStatistic 349 extends CountStatisticImpl 350 { 351 public UnimplementedCountStatistic(String name) 352 { 353 super(name, -1); 354 } 355 } 356 357 class UnimplementedBoundedRangeStatistic 358 extends BoundedRangeStatisticImpl 359 { 360 public UnimplementedBoundedRangeStatistic(String name) 361 { 362 super(name, -1, -1, -1, -1, -1); 363 } 364 } 365 } 366 | Popular Tags |