|
|||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
CacheEntryEventListenerImpl.java | - | 93,3% | 93,8% | 93,5% |
|
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.*; | |
8 | ||
9 | /** | |
10 | * Implementation of a CacheEntryEventListener. It use the events to count | |
11 | * the operations performed on the cache. | |
12 | * <p> | |
13 | * We are not using any synchronized so that this does not become a bottleneck. | |
14 | * The consequence is that on retrieving values, the operations that are | |
15 | * currently being done won't be counted. | |
16 | * | |
17 | * @version $Revision: 254 $ | |
18 | * @author <a href="mailto:abergevin@pyxis-tech.com">Alain Bergevin</a> | |
19 | * @author <a href="mailto:chris@swebtec.com">Chris Miller</a> | |
20 | */ | |
21 | public class CacheEntryEventListenerImpl implements CacheEntryEventListener { | |
22 | /** | |
23 | * Counter for the cache flushes | |
24 | */ | |
25 | private int cacheFlushedCount = 0; | |
26 | ||
27 | /** | |
28 | * Counter for the added entries | |
29 | */ | |
30 | private int entryAddedCount = 0; | |
31 | ||
32 | /** | |
33 | * Counter for the flushed entries | |
34 | */ | |
35 | private int entryFlushedCount = 0; | |
36 | ||
37 | /** | |
38 | * Counter for the removed entries | |
39 | */ | |
40 | private int entryRemovedCount = 0; | |
41 | ||
42 | /** | |
43 | * Counter for the updated entries | |
44 | */ | |
45 | private int entryUpdatedCount = 0; | |
46 | ||
47 | /** | |
48 | * Counter for the flushed groups | |
49 | */ | |
50 | private int groupFlushedCount = 0; | |
51 | ||
52 | /** | |
53 | * Counter for the pattern flushes | |
54 | */ | |
55 | private int patternFlushedCount = 0; | |
56 | ||
57 | /** | |
58 | * Constructor, empty for us | |
59 | */ | |
60 | 80 | public CacheEntryEventListenerImpl() { |
61 | } | |
62 | ||
63 | /** | |
64 | * Gets the add counter | |
65 | * | |
66 | * @return The added counter | |
67 | */ | |
68 | 15 | public int getEntryAddedCount() { |
69 | 15 | return entryAddedCount; |
70 | } | |
71 | ||
72 | /** | |
73 | * Gets the flushed counter | |
74 | * | |
75 | * @return The flushed counter | |
76 | */ | |
77 | 15 | public int getEntryFlushedCount() { |
78 | 15 | return entryFlushedCount; |
79 | } | |
80 | ||
81 | /** | |
82 | * Gets the removed counter | |
83 | * | |
84 | * @return The removed counter | |
85 | */ | |
86 | 15 | public int getEntryRemovedCount() { |
87 | 15 | return entryRemovedCount; |
88 | } | |
89 | ||
90 | /** | |
91 | * Gets the updated counter | |
92 | * | |
93 | * @return The updated counter | |
94 | */ | |
95 | 15 | public int getEntryUpdatedCount() { |
96 | 15 | return entryUpdatedCount; |
97 | } | |
98 | ||
99 | /** | |
100 | * Gets the group flush counter | |
101 | * | |
102 | * @return The number of group flush calls that have occurred | |
103 | */ | |
104 | 15 | public int getGroupFlushedCount() { |
105 | 15 | return groupFlushedCount; |
106 | } | |
107 | ||
108 | /** | |
109 | * Gets the pattern flush counter | |
110 | * | |
111 | * @return The number of pattern flush calls that have occurred | |
112 | */ | |
113 | 15 | public int getPatternFlushedCount() { |
114 | 15 | return patternFlushedCount; |
115 | } | |
116 | ||
117 | /** | |
118 | * Gets the cache flush counter | |
119 | * | |
120 | * @return The number of times the entire cache has been flushed | |
121 | */ | |
122 | 5 | public int getCacheFlushedCount() { |
123 | 5 | return cacheFlushedCount; |
124 | } | |
125 | ||
126 | /** | |
127 | * Handles the event fired when an entry is added in the cache. | |
128 | * | |
129 | * @param event The event triggered when a cache entry has been added | |
130 | */ | |
131 | 105 | public void cacheEntryAdded(CacheEntryEvent event) { |
132 | 105 | entryAddedCount++; |
133 | } | |
134 | ||
135 | /** | |
136 | * Handles the event fired when an entry is flushed from the cache. | |
137 | * | |
138 | * @param event The event triggered when a cache entry has been flushed | |
139 | */ | |
140 | 84 | public void cacheEntryFlushed(CacheEntryEvent event) { |
141 | 84 | entryFlushedCount++; |
142 | } | |
143 | ||
144 | /** | |
145 | * Handles the event fired when an entry is removed from the cache. | |
146 | * | |
147 | * @param event The event triggered when a cache entry has been removed | |
148 | */ | |
149 | 5 | public void cacheEntryRemoved(CacheEntryEvent event) { |
150 | 5 | entryRemovedCount++; |
151 | } | |
152 | ||
153 | /** | |
154 | * Handles the event fired when an entry is updated in the cache. | |
155 | * | |
156 | * @param event The event triggered when a cache entry has been updated | |
157 | */ | |
158 | 65 | public void cacheEntryUpdated(CacheEntryEvent event) { |
159 | 65 | entryUpdatedCount++; |
160 | } | |
161 | ||
162 | /** | |
163 | * Handles the event fired when a group is flushed from the cache. | |
164 | * | |
165 | * @param event The event triggered when a cache group has been flushed | |
166 | */ | |
167 | 50 | public void cacheGroupFlushed(CacheGroupEvent event) { |
168 | 50 | groupFlushedCount++; |
169 | } | |
170 | ||
171 | /** | |
172 | * Handles the event fired when a pattern is flushed from the cache. | |
173 | * | |
174 | * @param event The event triggered when a cache pattern has been flushed | |
175 | */ | |
176 | 25 | public void cachePatternFlushed(CachePatternEvent event) { |
177 | 25 | patternFlushedCount++; |
178 | } | |
179 | ||
180 | /** | |
181 | * Handles the event fired when a cache flush occurs. | |
182 | * | |
183 | * @param event The event triggered when an entire cache is flushed | |
184 | */ | |
185 | 10 | public void cacheFlushed(CachewideEvent event) { |
186 | 10 | cacheFlushedCount++; |
187 | } | |
188 | ||
189 | /** | |
190 | * Returns the internal values in a string form | |
191 | */ | |
192 | 0 | public String toString() { |
193 | 0 | return ("Added " + entryAddedCount + ", Updated " + entryUpdatedCount + ", Flushed " + entryFlushedCount + ", Removed " + entryRemovedCount + ", Groups Flushed " + groupFlushedCount + ", Patterns Flushed " + patternFlushedCount + ", Cache Flushed " + cacheFlushedCount); |
194 | } | |
195 | } |
|