1 23 24 package com.sun.ejb.base.stats; 25 26 import javax.management.j2ee.statistics.CountStatistic ; 27 import javax.management.j2ee.statistics.RangeStatistic ; 28 import javax.management.j2ee.statistics.TimeStatistic ; 29 30 import com.sun.ejb.spi.stats.MonitorableSFSBStoreManager; 31 32 import com.sun.enterprise.admin.monitor.stats.AverageRangeStatistic; 33 import com.sun.enterprise.admin.monitor.stats.BoundedRangeStatisticImpl; 34 import com.sun.enterprise.admin.monitor.stats.CountStatisticImpl; 35 import com.sun.enterprise.admin.monitor.stats.MutableAverageRangeStatisticImpl; 36 import com.sun.enterprise.admin.monitor.stats.MutableBoundedRangeStatisticImpl; 37 import com.sun.enterprise.admin.monitor.stats.MutableCountStatisticImpl; 38 import com.sun.enterprise.admin.monitor.stats.MutableTimeStatisticImpl; 39 import com.sun.enterprise.admin.monitor.stats.TimeStatisticImpl; 40 41 47 48 public class StatefulSessionStoreStatsImpl 49 extends StatsImpl 50 implements com.sun.enterprise.admin.monitor.stats.StatefulSessionStoreStats 51 { 52 53 private MonitorableSFSBStoreManager provider; 54 55 private MutableBoundedRangeStatisticImpl currentSize; 56 57 private MutableCountStatisticImpl activationCount; 58 private MutableCountStatisticImpl activationSuccessCount; 59 private MutableCountStatisticImpl activationErrorCount; 60 61 private MutableCountStatisticImpl passivationCount; 62 private MutableCountStatisticImpl passivationSuccessCount; 63 private MutableCountStatisticImpl passivationErrorCount; 64 65 private MutableCountStatisticImpl expiredSessionCount; 66 67 private MutableAverageRangeStatisticImpl activationSize; 68 private MutableAverageRangeStatisticImpl activationTime; 69 70 private MutableAverageRangeStatisticImpl passivationSize; 71 private MutableAverageRangeStatisticImpl passivationTime; 72 73 private Object currentSizeLock = new Object (); 74 75 private Object activationCountLock = new Object (); 76 private Object activationSizeLock = new Object (); 77 private Object activationTimeLock = new Object (); 78 79 private Object passivationCountLock = new Object (); 80 private Object passivationSizeLock = new Object (); 81 private Object passivationTimeLock = new Object (); 82 83 private Object expiredSessionCountLock = new Object (); 84 85 private long activationCountVal; 86 private long activationSuccessCountVal; 87 private long activationErrorCountVal; 88 89 private long passivationCountVal; 90 private long passivationSuccessCountVal; 91 private long passivationErrorCountVal; 92 93 private long expiredSessionCountVal; 94 95 public StatefulSessionStoreStatsImpl( 96 MonitorableSFSBStoreManager provider) 97 { 98 this.provider = provider; 99 super.initialize("com.sun.enterprise.admin.monitor.stats.StatefulSessionStoreStats"); 100 101 initialize(); 102 } 103 104 protected StatefulSessionStoreStatsImpl( 105 MonitorableSFSBStoreManager provider, String intfName) 106 { 107 this.provider = provider; 108 super.initialize(intfName); 109 } 110 111 protected void initialize() { 112 113 long now = System.currentTimeMillis(); 114 115 synchronized (currentSizeLock) { 116 currentSize = new MutableBoundedRangeStatisticImpl( 117 new BoundedRangeStatisticImpl(0, 0, Long.MAX_VALUE, 118 Long.MAX_VALUE, 0, "CurrentSize", 119 "bytes", "Number of sessions in store", now, now) 120 ); 121 } 122 123 synchronized (activationCountLock) { 124 activationCount = new MutableCountStatisticImpl( 125 new CountStatisticImpl("ActivationCount")); 126 activationSuccessCount = new MutableCountStatisticImpl( 127 new CountStatisticImpl("ActivationSuccessCount")); 128 activationErrorCount = new MutableCountStatisticImpl( 129 new CountStatisticImpl("ActivationErrorCount")); 130 } 131 132 synchronized (activationSizeLock) { 133 activationSize = new MutableAverageRangeStatisticImpl( 134 new BoundedRangeStatisticImpl(0, 0, Long.MAX_VALUE, 135 Long.MAX_VALUE, 0, "ActivationSize", 136 "bytes", "Number of bytes activated", now, now) 137 ); 138 } 139 140 synchronized (passivationSizeLock) { 141 passivationSize = new MutableAverageRangeStatisticImpl( 142 new BoundedRangeStatisticImpl(0, 0, Long.MAX_VALUE, 143 Long.MAX_VALUE, 0, "PassivationSize", 144 "bytes", "Number of bytes passivated", now, now) 145 ); 146 } 147 148 synchronized (passivationCountLock) { 149 passivationCount = new MutableCountStatisticImpl( 150 new CountStatisticImpl("PassivationCount")); 151 passivationSuccessCount = new MutableCountStatisticImpl( 152 new CountStatisticImpl("PassivationSuccessCount")); 153 passivationErrorCount = new MutableCountStatisticImpl( 154 new CountStatisticImpl("PassivationErrorCount")); 155 } 156 157 synchronized (expiredSessionCountLock) { 158 expiredSessionCount = new MutableCountStatisticImpl( 159 new CountStatisticImpl("ExpiredSessionCount")); 160 } 161 162 synchronized (activationTimeLock) { 163 activationTime = new MutableAverageRangeStatisticImpl( 164 new BoundedRangeStatisticImpl(0, 0, Long.MAX_VALUE, 165 Long.MAX_VALUE, 0, "ActivationTime", 166 "millis", "Time spent on activation", now, now) 167 ); 168 } 169 170 synchronized (passivationTimeLock) { 171 passivationTime = new MutableAverageRangeStatisticImpl( 172 new BoundedRangeStatisticImpl(0, 0, Long.MAX_VALUE, 173 Long.MAX_VALUE, 0, "PassivationTime", 174 "millis", "Time spent on passivation", now, now) 175 ); 176 } 177 } 178 179 182 public RangeStatistic getCurrentSize() { 183 synchronized (currentSizeLock) { 184 currentSize.setCount(provider.getCurrentStoreSize()); 185 return (RangeStatistic ) currentSize.unmodifiableView(); 186 } 187 } 188 189 192 public CountStatistic getActivationCount() { 193 synchronized (activationCountLock) { 194 activationCount.setCount(activationCountVal); 195 return (CountStatistic ) activationCount.unmodifiableView(); 196 } 197 } 198 199 202 public CountStatistic getActivationSuccessCount() { 203 synchronized (activationCountLock) { 204 activationSuccessCount.setCount(activationSuccessCountVal); 205 return (CountStatistic ) activationSuccessCount.unmodifiableView(); 206 } 207 } 208 209 212 public CountStatistic getActivationErrorCount() { 213 synchronized (activationCountLock) { 214 activationErrorCount.setCount(activationErrorCountVal); 215 return (CountStatistic ) activationErrorCount.unmodifiableView(); 216 } 217 } 218 219 222 public CountStatistic getPassivationCount() { 223 synchronized (passivationCountLock) { 224 passivationCount.setCount(passivationCountVal); 225 return (CountStatistic ) passivationSuccessCount.unmodifiableView(); 226 } 227 } 228 229 232 public CountStatistic getPassivationSuccessCount() { 233 synchronized (passivationCountLock) { 234 passivationSuccessCount.setCount(passivationSuccessCountVal); 235 return (CountStatistic ) passivationSuccessCount.unmodifiableView(); 236 } 237 } 238 239 242 public CountStatistic getPassivationErrorCount() { 243 synchronized (passivationCountLock) { 244 passivationErrorCount.setCount(passivationErrorCountVal); 245 return (CountStatistic ) passivationSuccessCount.unmodifiableView(); 246 } 247 } 248 249 252 public CountStatistic getExpiredSessionCount() { 253 synchronized (expiredSessionCountLock) { 254 expiredSessionCount.setCount(expiredSessionCountVal); 255 return (CountStatistic ) expiredSessionCount.unmodifiableView(); 256 257 } 258 } 259 260 263 public AverageRangeStatistic getActivatedBeanSize() { 264 synchronized (activationSizeLock) { 265 return (AverageRangeStatistic) activationSize.unmodifiableView(); 266 } 267 } 268 269 272 public AverageRangeStatistic getActivationTime() { 273 synchronized (activationTimeLock) { 274 return (AverageRangeStatistic) activationTime.unmodifiableView(); 275 } 276 } 277 278 281 public AverageRangeStatistic getPassivatedBeanSize() { 282 synchronized (passivationSizeLock) { 283 return (AverageRangeStatistic) passivationSize.unmodifiableView(); 284 } 285 } 286 287 290 public AverageRangeStatistic getPassivationTime() { 291 synchronized (passivationTimeLock) { 292 return (AverageRangeStatistic) passivationTime.unmodifiableView(); 293 } 294 } 295 296 void incrementActivationCount(boolean success) { 299 synchronized (activationCountLock) { 300 activationCountVal++; 301 if (success) { 302 activationSuccessCountVal++; 303 } else { 304 activationErrorCountVal++; 305 } 306 } 307 } 308 309 void incrementPassivationCount(boolean success) { 310 synchronized (passivationCountLock) { 311 passivationCountVal++; 312 if (success) { 313 passivationSuccessCountVal++; 314 } else { 315 passivationErrorCountVal++; 316 } 317 } 318 } 319 320 void setActivationSize(long val) { 321 synchronized (activationSizeLock) { 322 activationSize.setCount(val); 323 } 324 } 325 326 void setActivationTime(long val) { 327 synchronized (activationTimeLock) { 328 activationTime.setCount(val); 329 } 330 } 331 332 void setPassivationSize(long val) { 333 synchronized (passivationSizeLock) { 334 passivationSize.setCount(val); 335 } 336 } 337 338 void setPassivationTime(long val) { 339 synchronized (passivationTimeLock) { 340 passivationTime.setCount(val); 341 } 342 } 343 344 void incrementExpiredSessionCountVal(long val) { 345 synchronized (expiredSessionCountLock) { 346 expiredSessionCountVal += val; 347 } 348 } 349 350 protected void appendStats(StringBuffer sbuf) { 351 sbuf.append("currentSize=").append(provider.getCurrentStoreSize()) 352 .append("; ") 353 .append("ActivationCount=").append(activationCountVal) 354 .append("; ") 355 .append("ActivationSuccessCount=").append(activationSuccessCountVal) 356 .append("; ") 357 .append("ActivationErrorCount=").append(activationErrorCountVal) 358 .append("; ") 359 .append("PassivationCount=").append(passivationCountVal) 360 .append("; ") 361 .append("PassivationSuccessCount=").append(passivationSuccessCountVal) 362 .append("; ") 363 .append("PassivationErrorCount=").append(passivationErrorCountVal) 364 .append("; ") 365 .append("ExpiredSessionsRemoved=").append(expiredSessionCountVal) 366 .append("; "); 367 368 appendTimeStatistic(sbuf, "ActivationSize", activationSize); 369 appendTimeStatistic(sbuf, "ActivationTime", activationTime); 370 appendTimeStatistic(sbuf, "PassivationSize", passivationSize); 371 appendTimeStatistic(sbuf, "PassivationTime", passivationTime); 372 373 } 377 378 protected static void appendTimeStatistic(StringBuffer sbuf, String name, 379 MutableAverageRangeStatisticImpl stat) 380 { 381 sbuf.append(name).append("(") 382 .append("min=").append(stat.getLowWaterMark()).append(", ") 383 .append("max=").append(stat.getHighWaterMark()).append(", ") 384 .append("avg=").append(stat.getAverage()) 385 .append("); "); 386 } 387 388 389 int getNumExpiredSessionCount() { 393 synchronized (expiredSessionCountLock) { 394 return (int) expiredSessionCountVal; 395 } 396 } 397 398 int getNumPassivationCount() { 399 synchronized (passivationCountLock) { 400 return (int) passivationCountVal; 401 } 402 } 403 404 int getNumPassivationSuccessCount() { 405 synchronized (passivationCountLock) { 406 return (int) passivationSuccessCountVal; 407 } 408 } 409 410 int getNumPassivationErrorCount() { 411 synchronized (passivationCountLock) { 412 return (int) passivationErrorCountVal; 413 } 414 } 415 416 417 } 418 | Popular Tags |