Clover coverage report -
Coverage timestamp: Sa Jul 7 2007 09:11:40 CEST
file stats: LOC: 111   Methods: 7
NCLOC: 42   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
CacheMapAccessEventListenerImpl.java 83,3% 86,7% 85,7% 85,7%
coverage coverage
 1    /*
 2    * Copyright (c) 2002-2003 by OpenSymphony
 3    * All rights reserved.
 4    */
 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    /**
 12    * Implementation of a CacheMapAccessEventListener. It uses the events to count
 13    * the cache hit and misses.
 14    * <p>
 15    * We are not using any synchronized so that this does not become a bottleneck.
 16    * The consequence is that on retrieving values, the operations that are
 17    * currently being done won't be counted.
 18    *
 19    * @version $Revision: 254 $
 20    * @author <a href="mailto:abergevin@pyxis-tech.com">Alain Bergevin</a>
 21    * @author <a href="&#109;a&#105;&#108;&#116;&#111;:chris&#64;swebtec.&#99;&#111;&#109;">Chris Miller</a>
 22    */
 23    public class CacheMapAccessEventListenerImpl implements CacheMapAccessEventListener {
 24    /**
 25    * Hit counter
 26    */
 27    private int hitCount = 0;
 28   
 29    /**
 30    * Miss counter
 31    */
 32    private int missCount = 0;
 33   
 34    /**
 35    * Stale hit counter
 36    */
 37    private int staleHitCount = 0;
 38   
 39    /**
 40    * Constructor, empty for us
 41    */
 42  80 public CacheMapAccessEventListenerImpl() {
 43    }
 44   
 45    /**
 46    * Returns the cache's current hit count
 47    *
 48    * @return The hit count
 49    */
 50  15 public int getHitCount() {
 51  15 return hitCount;
 52    }
 53   
 54    /**
 55    * Returns the cache's current miss count
 56    *
 57    * @return The miss count
 58    */
 59  15 public int getMissCount() {
 60  15 return missCount;
 61    }
 62   
 63    /**
 64    * Returns the cache's current stale hit count
 65    */
 66  15 public int getStaleHitCount() {
 67  15 return staleHitCount;
 68    }
 69   
 70    /**
 71    * This method handles an event each time the cache is accessed
 72    *
 73    * @param event The event triggered when the cache was accessed
 74    */
 75  270 public void accessed(CacheMapAccessEvent event) {
 76    // Retrieve the event type and update the counters
 77  270 CacheMapAccessEventType type = event.getEventType();
 78   
 79    // Handles a hit event
 80  270 if (type == CacheMapAccessEventType.HIT) {
 81  125 hitCount++;
 82    }
 83    // Handles a stale hit event
 84  145 else if (type == CacheMapAccessEventType.STALE_HIT) {
 85  125 staleHitCount++;
 86    }
 87    // Handles a miss event
 88  20 else if (type == CacheMapAccessEventType.MISS) {
 89  20 missCount++;
 90    } else {
 91    // Unknown event!
 92  0 throw new IllegalArgumentException("Unknown Cache Map Access event received");
 93    }
 94    }
 95   
 96    /**
 97    * Resets all of the totals to zero
 98    */
 99  5 public void reset() {
 100  5 hitCount = 0;
 101  5 staleHitCount = 0;
 102  5 missCount = 0;
 103    }
 104   
 105    /**
 106    * Return the counters in a string form
 107    */
 108  0 public String toString() {
 109  0 return ("Hit count = " + hitCount + ", stale hit count = " + staleHitCount + " and miss count = " + missCount);
 110    }
 111    }