1 5 package com.opensymphony.oscache.extra; 6 7 import com.opensymphony.oscache.base.events.CacheMapAccessEvent; 8 import com.opensymphony.oscache.base.events.CacheMapAccessEventListener; 9 import com.opensymphony.oscache.base.events.CacheMapAccessEventType; 10 11 23 public class CacheMapAccessEventListenerImpl implements CacheMapAccessEventListener { 24 27 private int hitCount = 0; 28 29 32 private int missCount = 0; 33 34 37 private int staleHitCount = 0; 38 39 42 public CacheMapAccessEventListenerImpl() { 43 } 44 45 50 public int getHitCount() { 51 return hitCount; 52 } 53 54 59 public int getMissCount() { 60 return missCount; 61 } 62 63 66 public int getStaleHitCount() { 67 return staleHitCount; 68 } 69 70 75 public void accessed(CacheMapAccessEvent event) { 76 CacheMapAccessEventType type = event.getEventType(); 78 79 if (type == CacheMapAccessEventType.HIT) { 81 hitCount++; 82 } 83 else if (type == CacheMapAccessEventType.STALE_HIT) { 85 staleHitCount++; 86 } 87 else if (type == CacheMapAccessEventType.MISS) { 89 missCount++; 90 } else { 91 throw new IllegalArgumentException ("Unknown Cache Map Access event received"); 93 } 94 } 95 96 99 public void reset() { 100 hitCount = 0; 101 staleHitCount = 0; 102 missCount = 0; 103 } 104 105 108 public String toString() { 109 return ("Hit count = " + hitCount + ", stale hit count = " + staleHitCount + " and miss count = " + missCount); 110 } 111 } 112 | Popular Tags |