KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > stat > SecondLevelCacheStatistics


1 //$Id: SecondLevelCacheStatistics.java,v 1.12 2005/06/09 06:33:06 oneovthafew Exp $
2
package org.hibernate.stat;
3
4 import java.util.HashMap JavaDoc;
5 import java.util.Iterator JavaDoc;
6 import java.util.Map JavaDoc;
7
8 import org.hibernate.cache.Cache;
9 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     public long getHitCount() {
28         return hitCount;
29     }
30     public long getMissCount() {
31         return missCount;
32     }
33     public long getPutCount() {
34         return putCount;
35     }
36     public long getElementCountInMemory() {
37         return cache.getElementCountInMemory();
38     }
39     public long getElementCountOnDisk() {
40         return cache.getElementCountOnDisk();
41     }
42     public long getSizeInMemory() {
43         return cache.getSizeInMemory();
44     }
45     
46     public Map JavaDoc getEntries() {
47         Map JavaDoc map = new HashMap JavaDoc();
48         Iterator JavaDoc iter = cache.toMap().entrySet().iterator();
49         while ( iter.hasNext() ) {
50             Map.Entry JavaDoc me = (Map.Entry JavaDoc) iter.next();
51             map.put( ( (CacheKey) me.getKey() ).getKey(), me.getValue() );
52         }
53         return map;
54     }
55
56     public String JavaDoc toString() {
57         StringBuffer JavaDoc buf = new StringBuffer JavaDoc()
58             .append("SecondLevelCacheStatistics")
59             .append("[hitCount=").append(this.hitCount)
60             .append(",missCount=").append(this.missCount)
61             .append(",putCount=").append(this.putCount);
62         //not sure if this would ever be null but wanted to be careful
63
if (this.cache != null) {
64             buf.append(",elementCountInMemory=").append(this.getElementCountInMemory())
65                 .append(",elementCountOnDisk=").append(this.getElementCountOnDisk())
66                 .append(",sizeInMemory=").append(this.getSizeInMemory());
67         }
68         buf.append(']');
69         return buf.toString();
70     }
71 }
72
Popular Tags