2
* Copyright (c) 2002-2003 by OpenSymphony
5
package com.opensymphony.oscache.extra;
7
import com.opensymphony.oscache.base.events.CacheMapAccessEvent;
8
import com.opensymphony.oscache.base.events.CacheMapAccessEventListener;
9
import com.opensymphony.oscache.base.events.CacheMapAccessEventType;
12
* Implementation of a CacheMapAccessEventListener. It uses the events to count
13
* the cache hit and misses.
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.
19
* @version $Revision: 1.1 $
20
* @author <a href="mailto:abergevin@pyxis-tech.com">Alain Bergevin</a>
21
* @author <a href="mailto:chris@swebtec.com">Chris Miller</a>
23
public class CacheMapAccessEventListenerImpl implements CacheMapAccessEventListener {
27
private int hitCount = 0;
32
private int missCount = 0;
37
private int staleHitCount = 0;
40
* Constructor, empty for us
42
public CacheMapAccessEventListenerImpl() {
46
* Returns the cache's current hit count
48
* @return The hit count
50
public int getHitCount() {
55
* Returns the cache's current miss count
57
* @return The miss count
59
public int getMissCount() {
64
* Returns the cache's current stale hit count
66
public int getStaleHitCount() {
71
* This method handles an event each time the cache is accessed
73
* @param event The event triggered when the cache was accessed
75
public void accessed(CacheMapAccessEvent event) {
76
// Retrieve the event type and update the counters
77
CacheMapAccessEventType type = event.getEventType();
79
// Handles a hit event
80
if (type == CacheMapAccessEventType.HIT) {
83
// Handles a stale hit event
84
else if (type == CacheMapAccessEventType.STALE_HIT) {
87
// Handles a miss event
88
else if (type == CacheMapAccessEventType.MISS) {
92
throw new IllegalArgumentException("Unknown Cache Map Access event received");
97
* Resets all of the totals to zero
106
* Return the counters in a string form
108
public String toString() {
109
return ("Hit count = " + hitCount + ", stale hit count = " + staleHitCount + " and miss count = " + missCount);