Clover coverage report - Coverage timestamp: do jan 22 2004 21:12:32 CET FRAMES NO FRAMES |
file stats: | LOC: | 112 |  | Methods: | 7
| NCLOC: | 42 |  | Classes: | 1
Source file | Conditionals | Statements | Methods | TOTAL
CacheMapAccessEventListenerImpl.java | 83,3% | 86,7% | 85,7% | 85,7% |

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: 1.1 $
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 | 39 |
         public CacheMapAccessEventListenerImpl() {
43 |  |
         }
44 |  |
45 |  |
         /**
46 |  |
          * Returns the cache's current hit count
47 |  |
          *
48 |  |
          * @return The hit count
49 |  |
          */
50 | 9 |
         public int getHitCount() {
51 | 9 |
             return hitCount;
52 |  |
         }
53 |  |
54 |  |
         /**
55 |  |
          * Returns the cache's current miss count
56 |  |
          *
57 |  |
          * @return The miss count
58 |  |
          */
59 | 9 |
         public int getMissCount() {
60 | 9 |
             return missCount;
61 |  |
         }
62 |  |
63 |  |
         /**
64 |  |
          * Returns the cache's current stale hit count
65 |  |
          */
66 | 9 |
         public int getStaleHitCount() {
67 | 9 |
             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 | 147 |
         public void accessed(CacheMapAccessEvent event) {
76 |  |
             // Retrieve the event type and update the counters
77 | 147 |
             CacheMapAccessEventType type = event.getEventType();
78 |  |
79 |  |
             // Handles a hit event
80 | 147 |
             if (type == CacheMapAccessEventType.HIT) {
81 | 69 |
                 hitCount++;
82 |  |
             }
83 |  |
             // Handles a stale hit event
84 | 78 |
             else if (type == CacheMapAccessEventType.STALE_HIT) {
85 | 66 |
                 staleHitCount++;
86 |  |
             }
87 |  |
             // Handles a miss event
88 | 12 |
             else if (type == CacheMapAccessEventType.MISS) {
89 | 12 |
                 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 | 3 |
         public void reset() {
100 | 3 |
             hitCount = 0;
101 | 3 |
             staleHitCount = 0;
102 | 3 |
             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 |  |
     }
112 |  |