1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| package com.opensymphony.oscache.extra; |
6 |
| |
7 |
| import com.opensymphony.oscache.base.Cache; |
8 |
| import com.opensymphony.oscache.base.events.CacheEntryEvent; |
9 |
| import com.opensymphony.oscache.base.events.CacheEntryEventListener; |
10 |
| import com.opensymphony.oscache.base.events.CacheGroupEvent; |
11 |
| import com.opensymphony.oscache.base.events.CacheMapAccessEvent; |
12 |
| import com.opensymphony.oscache.base.events.CacheMapAccessEventListener; |
13 |
| import com.opensymphony.oscache.base.events.CacheMapAccessEventType; |
14 |
| import com.opensymphony.oscache.base.events.CachePatternEvent; |
15 |
| import com.opensymphony.oscache.base.events.CachewideEvent; |
16 |
| import com.opensymphony.oscache.base.events.ScopeEvent; |
17 |
| import com.opensymphony.oscache.base.events.ScopeEventListener; |
18 |
| import com.opensymphony.oscache.extra.ScopeEventListenerImpl; |
19 |
| |
20 |
| |
21 |
| |
22 |
| |
23 |
| |
24 |
| |
25 |
| |
26 |
| |
27 |
| |
28 |
| |
29 |
| public class StatisticListenerImpl implements CacheMapAccessEventListener, |
30 |
| CacheEntryEventListener, ScopeEventListener { |
31 |
| |
32 |
| |
33 |
| |
34 |
| |
35 |
| private static int hitCount = 0; |
36 |
| |
37 |
| |
38 |
| |
39 |
| |
40 |
| private static int missCount = 0; |
41 |
| |
42 |
| |
43 |
| |
44 |
| |
45 |
| private static int staleHitCount = 0; |
46 |
| |
47 |
| |
48 |
| |
49 |
| |
50 |
| private static int hitCountSum = 0; |
51 |
| |
52 |
| |
53 |
| |
54 |
| |
55 |
| private static int missCountSum = 0; |
56 |
| |
57 |
| |
58 |
| |
59 |
| |
60 |
| private static int staleHitCountSum = 0; |
61 |
| |
62 |
| |
63 |
| |
64 |
| |
65 |
| private static int flushCount = 0; |
66 |
| |
67 |
| |
68 |
| |
69 |
| |
70 |
| private static int entriesAdded = 0; |
71 |
| |
72 |
| |
73 |
| |
74 |
| |
75 |
| private static int entriesRemoved = 0; |
76 |
| |
77 |
| |
78 |
| |
79 |
| |
80 |
| private static int entriesUpdated = 0; |
81 |
| |
82 |
| |
83 |
| |
84 |
| |
85 |
34
| public StatisticListenerImpl() {
|
86 |
| |
87 |
| } |
88 |
| |
89 |
| |
90 |
| |
91 |
| |
92 |
| |
93 |
| |
94 |
| |
95 |
| |
96 |
97
| public void accessed(CacheMapAccessEvent event) {
|
97 |
| |
98 |
97
| CacheMapAccessEventType type = event.getEventType();
|
99 |
| |
100 |
| |
101 |
97
| if (type == CacheMapAccessEventType.HIT) {
|
102 |
62
| hitCount++;
|
103 |
35
| } else if (type == CacheMapAccessEventType.STALE_HIT) {
|
104 |
| |
105 |
| |
106 |
28
| staleHitCount++;
|
107 |
7
| } else if (type == CacheMapAccessEventType.MISS) {
|
108 |
| |
109 |
7
| missCount++;
|
110 |
| } |
111 |
| } |
112 |
| |
113 |
| |
114 |
| |
115 |
| |
116 |
| |
117 |
| |
118 |
51
| private void flushed(String info) {
|
119 |
51
| flushCount++;
|
120 |
| |
121 |
51
| hitCountSum += hitCount;
|
122 |
51
| staleHitCountSum += staleHitCount;
|
123 |
51
| missCountSum += missCount;
|
124 |
| |
125 |
51
| hitCount = 0;
|
126 |
51
| staleHitCount = 0;
|
127 |
51
| missCount = 0;
|
128 |
| } |
129 |
| |
130 |
| |
131 |
| |
132 |
| |
133 |
| |
134 |
| |
135 |
| |
136 |
10
| public void scopeFlushed(ScopeEvent event) {
|
137 |
10
| flushed("scope " + ScopeEventListenerImpl.SCOPE_NAMES[event.getScope()]);
|
138 |
| } |
139 |
| |
140 |
| |
141 |
| |
142 |
| |
143 |
| |
144 |
| |
145 |
| |
146 |
69
| public void cacheEntryAdded(CacheEntryEvent event) {
|
147 |
69
| entriesAdded++;
|
148 |
| } |
149 |
| |
150 |
| |
151 |
| |
152 |
| |
153 |
| |
154 |
| |
155 |
| |
156 |
21
| public void cacheEntryFlushed(CacheEntryEvent event) {
|
157 |
| |
158 |
21
| if (!Cache.NESTED_EVENT.equals(event.getOrigin())) {
|
159 |
9
| flushed("entry " + event.getKey() + " / " + event.getOrigin());
|
160 |
| } |
161 |
| } |
162 |
| |
163 |
| |
164 |
| |
165 |
| |
166 |
| |
167 |
| |
168 |
| |
169 |
5
| public void cacheEntryRemoved(CacheEntryEvent event) {
|
170 |
5
| entriesRemoved++;
|
171 |
| } |
172 |
| |
173 |
| |
174 |
| |
175 |
| |
176 |
| |
177 |
| |
178 |
| |
179 |
12
| public void cacheEntryUpdated(CacheEntryEvent event) {
|
180 |
12
| entriesUpdated++;
|
181 |
| } |
182 |
| |
183 |
| |
184 |
| |
185 |
| |
186 |
| |
187 |
| |
188 |
| |
189 |
14
| public void cacheGroupFlushed(CacheGroupEvent event) {
|
190 |
14
| flushed("group " + event.getGroup());
|
191 |
| } |
192 |
| |
193 |
| |
194 |
| |
195 |
| |
196 |
| |
197 |
| |
198 |
| |
199 |
11
| public void cachePatternFlushed(CachePatternEvent event) {
|
200 |
11
| flushed("pattern " + event.getPattern());
|
201 |
| } |
202 |
| |
203 |
| |
204 |
| |
205 |
| |
206 |
| |
207 |
| |
208 |
| |
209 |
7
| public void cacheFlushed(CachewideEvent event) {
|
210 |
7
| flushed("wide " + event.getDate());
|
211 |
| } |
212 |
| |
213 |
| |
214 |
| |
215 |
| |
216 |
| |
217 |
| |
218 |
0
| public String toString() {
|
219 |
0
| return "StatisticListenerImpl: Hit = " + hitCount + " / " + hitCountSum
|
220 |
| + ", stale hit = " + staleHitCount + " / " + staleHitCountSum |
221 |
| + ", miss = " + missCount + " / " + missCountSum + ", flush = " |
222 |
| + flushCount + ", entries (added, removed, updates) = " |
223 |
| + entriesAdded + ", " + entriesRemoved + ", " + entriesUpdated; |
224 |
| } |
225 |
| |
226 |
| |
227 |
| |
228 |
| |
229 |
10
| public int getEntriesAdded() {
|
230 |
10
| return entriesAdded;
|
231 |
| } |
232 |
| |
233 |
| |
234 |
| |
235 |
| |
236 |
10
| public int getEntriesRemoved() {
|
237 |
10
| return entriesRemoved;
|
238 |
| } |
239 |
| |
240 |
| |
241 |
| |
242 |
| |
243 |
10
| public int getEntriesUpdated() {
|
244 |
10
| return entriesUpdated;
|
245 |
| } |
246 |
| |
247 |
| |
248 |
| |
249 |
| |
250 |
10
| public int getFlushCount() {
|
251 |
10
| return flushCount;
|
252 |
| } |
253 |
| |
254 |
| |
255 |
| |
256 |
| |
257 |
5
| public int getHitCount() {
|
258 |
5
| return hitCount;
|
259 |
| } |
260 |
| |
261 |
| |
262 |
| |
263 |
| |
264 |
5
| public int getHitCountSum() {
|
265 |
5
| return hitCountSum;
|
266 |
| } |
267 |
| |
268 |
| |
269 |
| |
270 |
| |
271 |
5
| public int getMissCount() {
|
272 |
5
| return missCount;
|
273 |
| } |
274 |
| |
275 |
| |
276 |
| |
277 |
| |
278 |
5
| public int getMissCountSum() {
|
279 |
5
| return missCountSum;
|
280 |
| } |
281 |
| |
282 |
| |
283 |
| |
284 |
| |
285 |
5
| public int getStaleHitCount() {
|
286 |
5
| return staleHitCount;
|
287 |
| } |
288 |
| |
289 |
| |
290 |
| |
291 |
| |
292 |
5
| public int getStaleHitCountSum() {
|
293 |
5
| return staleHitCountSum;
|
294 |
| } |
295 |
| } |