1 4 package com.tc.objectserver.impl; 5 6 import com.tc.objectserver.api.ObjectManagerStats; 7 import com.tc.objectserver.api.ObjectManagerStatsListener; 8 import com.tc.stats.counter.sampled.SampledCounter; 9 import com.tc.stats.counter.sampled.TimeStampedCounterValue; 10 11 14 public class ObjectManagerStatsImpl implements ObjectManagerStatsListener, ObjectManagerStats { 15 16 private long cacheHits = 0L; 17 private long cacheMisses = 0L; 18 private long objectsCreated = 0L; 19 private final SampledCounter newObjectCounter; 20 private final SampledCounter faultRateCounter; 21 22 public ObjectManagerStatsImpl(SampledCounter newObjectCounter, SampledCounter faultRateCounter) { 23 this.newObjectCounter = newObjectCounter; 24 this.faultRateCounter = faultRateCounter; 25 } 26 27 public synchronized void cacheHit() { 28 this.cacheHits++; 29 } 30 31 public synchronized void cacheMiss() { 32 this.cacheMisses++; 33 this.faultRateCounter.increment(); 34 } 35 36 public synchronized void newObjectCreated() { 37 this.objectsCreated++; 38 this.newObjectCounter.increment(); 39 } 40 41 public synchronized double getCacheHitRatio() { 42 return ((double) cacheHits) / ((double) getTotalRequests()); 43 } 44 45 public synchronized long getTotalRequests() { 46 return this.cacheHits + this.cacheMisses; 47 } 48 49 public synchronized long getTotalCacheMisses() { 50 return this.cacheMisses; 51 } 52 53 public synchronized long getTotalCacheHits() { 54 return this.cacheHits; 55 } 56 57 public long getTotalObjectsCreated() { 58 return this.objectsCreated; 59 } 60 61 public TimeStampedCounterValue getCacheMissRate() { 62 return this.faultRateCounter.getMostRecentSample(); 63 } 64 65 } 66 | Popular Tags |