1 |
| |
2 |
| |
3 |
| |
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 |
| |
13 |
| |
14 |
| |
15 |
| |
16 |
| |
17 |
| |
18 |
| |
19 |
| |
20 |
| |
21 |
| |
22 |
| |
23 |
| public class CacheMapAccessEventListenerImpl implements CacheMapAccessEventListener { |
24 |
| |
25 |
| |
26 |
| |
27 |
| private int hitCount = 0; |
28 |
| |
29 |
| |
30 |
| |
31 |
| |
32 |
| private int missCount = 0; |
33 |
| |
34 |
| |
35 |
| |
36 |
| |
37 |
| private int staleHitCount = 0; |
38 |
| |
39 |
| |
40 |
| |
41 |
| |
42 |
80
| public CacheMapAccessEventListenerImpl() {
|
43 |
| } |
44 |
| |
45 |
| |
46 |
| |
47 |
| |
48 |
| |
49 |
| |
50 |
15
| public int getHitCount() {
|
51 |
15
| return hitCount;
|
52 |
| } |
53 |
| |
54 |
| |
55 |
| |
56 |
| |
57 |
| |
58 |
| |
59 |
15
| public int getMissCount() {
|
60 |
15
| return missCount;
|
61 |
| } |
62 |
| |
63 |
| |
64 |
| |
65 |
| |
66 |
15
| public int getStaleHitCount() {
|
67 |
15
| return staleHitCount;
|
68 |
| } |
69 |
| |
70 |
| |
71 |
| |
72 |
| |
73 |
| |
74 |
| |
75 |
270
| public void accessed(CacheMapAccessEvent event) {
|
76 |
| |
77 |
270
| CacheMapAccessEventType type = event.getEventType();
|
78 |
| |
79 |
| |
80 |
270
| if (type == CacheMapAccessEventType.HIT) {
|
81 |
125
| hitCount++;
|
82 |
| } |
83 |
| |
84 |
145
| else if (type == CacheMapAccessEventType.STALE_HIT) {
|
85 |
125
| staleHitCount++;
|
86 |
| } |
87 |
| |
88 |
20
| else if (type == CacheMapAccessEventType.MISS) {
|
89 |
20
| missCount++;
|
90 |
| } else { |
91 |
| |
92 |
0
| throw new IllegalArgumentException("Unknown Cache Map Access event received");
|
93 |
| } |
94 |
| } |
95 |
| |
96 |
| |
97 |
| |
98 |
| |
99 |
5
| public void reset() {
|
100 |
5
| hitCount = 0;
|
101 |
5
| staleHitCount = 0;
|
102 |
5
| missCount = 0;
|
103 |
| } |
104 |
| |
105 |
| |
106 |
| |
107 |
| |
108 |
0
| public String toString() {
|
109 |
0
| return ("Hit count = " + hitCount + ", stale hit count = " + staleHitCount + " and miss count = " + missCount);
|
110 |
| } |
111 |
| } |