1 23 24 28 29 34 35 package com.sun.enterprise.admin.monitor.stats; 36 37 import javax.management.j2ee.statistics.Statistic ; 38 import javax.management.j2ee.statistics.BoundedRangeStatistic ; 39 40 50 51 55 public class MutableAverageRangeStatisticImpl implements AverageRangeStatistic, MutableCountStatistic { 56 57 58 public static final long DEFAULT_MAX_BOUND = java.lang.Long.MAX_VALUE; 59 60 private MutableBoundedRangeStatisticImpl mutableBoundedRangeStat = null; 61 private long numberOfSamples; 62 private long runningTotal; 63 private String description = null; 64 65 71 public MutableAverageRangeStatisticImpl(BoundedRangeStatistic initial) { 72 mutableBoundedRangeStat = new MutableBoundedRangeStatisticImpl(initial); 73 numberOfSamples = 0L; 74 runningTotal = 0L; 75 description = initial.getDescription(); 76 } 77 78 public Statistic modifiableView() { 79 return this; 80 } 81 82 public Statistic unmodifiableView() { 83 return ( new AverageRangeStatisticImpl( 84 this.getCurrent(), this.getHighWaterMark(), this.getLowWaterMark(), mutableBoundedRangeStat.getUpperBound(), mutableBoundedRangeStat.getLowerBound(), mutableBoundedRangeStat.getName(), mutableBoundedRangeStat.getUnit(), mutableBoundedRangeStat.getDescription(), this.getLastSampleTime(), this.getStartTime(), this.numberOfSamples, this.runningTotal )); 97 } 98 99 public void reset() { 100 mutableBoundedRangeStat.reset(); 101 this.resetAverageStats(); 102 } 103 104 private void resetAverageStats() { 105 numberOfSamples = 0L; 106 runningTotal = 0L; 107 } 108 109 public void setCount(long current) { 110 mutableBoundedRangeStat.setCount(current); 111 if(DEFAULT_MAX_BOUND - runningTotal < current) { 112 this.resetAverageStats(); 113 } 114 numberOfSamples++; 115 runningTotal += current; 116 } 117 118 public long getAverage() { 119 if(numberOfSamples == 0) { 120 return -1; 121 } else { 122 return runningTotal / numberOfSamples; 123 } 124 } 125 126 public long getCurrent() { 127 return mutableBoundedRangeStat.getCurrent(); 128 } 129 130 public String getDescription() { 131 return description; 132 } 134 135 public long getHighWaterMark() { 136 return mutableBoundedRangeStat.getHighWaterMark(); 137 } 138 139 public long getLastSampleTime() { 140 return mutableBoundedRangeStat.getLastSampleTime(); 141 } 142 143 public long getLowWaterMark() { 144 long result = mutableBoundedRangeStat.getLowWaterMark(); 145 if(result == DEFAULT_MAX_BOUND) { 146 result = 0L; 147 } 148 return result; 149 } 150 151 public String getName() { 152 return mutableBoundedRangeStat.getName(); 153 } 154 155 public long getStartTime() { 156 return mutableBoundedRangeStat.getStartTime(); 157 } 158 159 public String getUnit() { 160 return mutableBoundedRangeStat.getUnit(); 161 } 162 163 } 164 | Popular Tags |