01: //$Id: SecondLevelCacheStatistics.java 7093 2005-06-09 06:33:06Z oneovthafew $
02: package org.hibernate.stat;
03:
04: import java.util.HashMap;
05: import java.util.Iterator;
06: import java.util.Map;
07:
08: import org.hibernate.cache.Cache;
09: import org.hibernate.cache.CacheKey;
10:
11: /**
12: * Second level cache statistics of a specific region
13: *
14: * @author Gavin King
15: */
16: public class SecondLevelCacheStatistics extends CategorizedStatistics {
17:
18: private transient Cache cache;
19: long hitCount;
20: long missCount;
21: long putCount;
22:
23: SecondLevelCacheStatistics(Cache cache) {
24: super (cache.getRegionName());
25: this .cache = cache;
26: }
27:
28: public long getHitCount() {
29: return hitCount;
30: }
31:
32: public long getMissCount() {
33: return missCount;
34: }
35:
36: public long getPutCount() {
37: return putCount;
38: }
39:
40: public long getElementCountInMemory() {
41: return cache.getElementCountInMemory();
42: }
43:
44: public long getElementCountOnDisk() {
45: return cache.getElementCountOnDisk();
46: }
47:
48: public long getSizeInMemory() {
49: return cache.getSizeInMemory();
50: }
51:
52: public Map getEntries() {
53: Map map = new HashMap();
54: Iterator iter = cache.toMap().entrySet().iterator();
55: while (iter.hasNext()) {
56: Map.Entry me = (Map.Entry) iter.next();
57: map.put(((CacheKey) me.getKey()).getKey(), me.getValue());
58: }
59: return map;
60: }
61:
62: public String toString() {
63: StringBuffer buf = new StringBuffer().append(
64: "SecondLevelCacheStatistics").append("[hitCount=")
65: .append(this .hitCount).append(",missCount=").append(
66: this .missCount).append(",putCount=").append(
67: this .putCount);
68: //not sure if this would ever be null but wanted to be careful
69: if (this .cache != null) {
70: buf.append(",elementCountInMemory=").append(
71: this .getElementCountInMemory()).append(
72: ",elementCountOnDisk=").append(
73: this .getElementCountOnDisk()).append(
74: ",sizeInMemory=").append(this .getSizeInMemory());
75: }
76: buf.append(']');
77: return buf.toString();
78: }
79: }
|