1 package org.hibernate.stat; 3 4 import java.util.HashMap ; 5 import java.util.Iterator ; 6 import java.util.Map ; 7 8 import org.hibernate.cache.Cache; 9 import org.hibernate.cache.CacheKey; 10 11 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 getEntries() { 47 Map map = new HashMap (); 48 Iterator iter = cache.toMap().entrySet().iterator(); 49 while ( iter.hasNext() ) { 50 Map.Entry me = (Map.Entry ) iter.next(); 51 map.put( ( (CacheKey) me.getKey() ).getKey(), me.getValue() ); 52 } 53 return map; 54 } 55 56 public String toString() { 57 StringBuffer buf = new StringBuffer () 58 .append("SecondLevelCacheStatistics") 59 .append("[hitCount=").append(this.hitCount) 60 .append(",missCount=").append(this.missCount) 61 .append(",putCount=").append(this.putCount); 62 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 |