1 23 24 28 29 34 35 package com.sun.enterprise.admin.monitor.stats; 36 import javax.management.j2ee.statistics.TimeStatistic ; 37 import javax.management.j2ee.statistics.Statistic ; 38 39 40 46 public class MutableTimeStatisticImpl implements TimeStatistic , MutableTimeStatistic { 47 48 private final TimeStatistic initial; 49 private long methodCount; 50 private long min; 51 private long max; 52 private long total; private long lastSampleTime; 54 62 public MutableTimeStatisticImpl(TimeStatistic initial) { 63 this.initial = initial; 64 methodCount = initial.getCount(); 65 min = initial.getMinTime(); 66 max = initial.getMaxTime(); 67 total = initial.getTotalTime(); 68 final boolean minMax = min == max; 69 final boolean minTot = min == total; 70 if (! (minMax && minTot)) 71 throw new IllegalArgumentException ("Invalid initial values: " + min + ", " + max + ", " + total); 72 lastSampleTime = initial.getLastSampleTime(); 73 } 74 75 84 public void incrementCount(long current) { 85 if (methodCount == 0) { 86 total = max = min = current; 87 } else { 88 total += current; 89 max = current >= max ? current : max; 90 min = current >= min ? min : current; 91 } 92 methodCount++; 93 lastSampleTime = System.currentTimeMillis(); 94 } 95 96 103 public void reset() { 104 methodCount = initial.getCount(); 105 min = initial.getMinTime(); 106 max = initial.getMaxTime(); 107 total = initial.getTotalTime(); 108 lastSampleTime = initial.getLastSampleTime(); 109 } 110 111 116 public Statistic unmodifiableView() { 117 return ( new TimeStatisticImpl( 118 this.methodCount, 119 this.max, 120 this.min, 121 this.total, 122 initial.getName(), 123 initial.getUnit(), 124 initial.getDescription(), 125 initial.getStartTime(), 126 this.lastSampleTime ) 127 ); 128 } 129 130 public Statistic modifiableView() { 131 return ( this ); 132 } 133 134 public long getCount() { 135 return ( this.methodCount); 136 } 137 138 public String getDescription() { 139 return ( initial.getDescription() ); 140 } 141 142 public long getLastSampleTime() { 143 return ( this.lastSampleTime ); 144 } 145 146 public long getMaxTime() { 147 return ( this.max ); 148 } 149 150 public long getMinTime() { 151 return ( this.min ); 152 } 153 154 public String getName() { 155 return ( initial.getName() ); 156 } 157 158 public long getStartTime() { 159 return ( initial.getStartTime() ); 160 } 161 162 public long getTotalTime() { 163 return ( this.total ); 164 } 165 166 public String getUnit() { 167 return ( initial.getUnit() ); 168 } 169 170 public void setDescription (final String s) { 171 try { 172 ((StatisticImpl)this.initial).setDescription(s); 173 } 174 catch(final Exception e) { 175 } 176 } 177 } 178 | Popular Tags |