01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tc.objectserver.impl;
05:
06: import com.tc.objectserver.api.ObjectManagerStats;
07: import com.tc.objectserver.api.ObjectManagerStatsListener;
08: import com.tc.stats.counter.sampled.SampledCounter;
09: import com.tc.stats.counter.sampled.TimeStampedCounterValue;
10:
11: /**
12: * Implements the object manager stats
13: */
14: public class ObjectManagerStatsImpl implements
15: ObjectManagerStatsListener, ObjectManagerStats {
16:
17: private long cacheHits = 0L;
18: private long cacheMisses = 0L;
19: private long objectsCreated = 0L;
20: private final SampledCounter newObjectCounter;
21: private final SampledCounter faultRateCounter;
22:
23: public ObjectManagerStatsImpl(SampledCounter newObjectCounter,
24: SampledCounter faultRateCounter) {
25: this .newObjectCounter = newObjectCounter;
26: this .faultRateCounter = faultRateCounter;
27: }
28:
29: public synchronized void cacheHit() {
30: this .cacheHits++;
31: }
32:
33: public synchronized void cacheMiss() {
34: this .cacheMisses++;
35: this .faultRateCounter.increment();
36: }
37:
38: public synchronized void newObjectCreated() {
39: this .objectsCreated++;
40: this .newObjectCounter.increment();
41: }
42:
43: public synchronized double getCacheHitRatio() {
44: return ((double) cacheHits) / ((double) getTotalRequests());
45: }
46:
47: public synchronized long getTotalRequests() {
48: return this .cacheHits + this .cacheMisses;
49: }
50:
51: public synchronized long getTotalCacheMisses() {
52: return this .cacheMisses;
53: }
54:
55: public synchronized long getTotalCacheHits() {
56: return this .cacheHits;
57: }
58:
59: public long getTotalObjectsCreated() {
60: return this .objectsCreated;
61: }
62:
63: public TimeStampedCounterValue getCacheMissRate() {
64: return this.faultRateCounter.getMostRecentSample();
65: }
66:
67: }
|