1 package org.apache.commons.jcs3.auxiliary;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.IOException;
23 import java.io.Serializable;
24 import java.util.Map;
25 import java.util.Set;
26
27 import org.apache.commons.jcs3.engine.behavior.ICacheElement;
28 import org.apache.commons.jcs3.engine.logging.behavior.ICacheEvent;
29 import org.apache.commons.jcs3.engine.logging.behavior.ICacheEventLogger;
30
31
32
33
34
35
36
37 public abstract class AbstractAuxiliaryCacheEventLogging<K, V>
38 extends AbstractAuxiliaryCache<K, V>
39 {
40
41
42
43
44
45
46 @Override
47 public void update( final ICacheElement<K, V> cacheElement )
48 throws IOException
49 {
50 updateWithEventLogging( cacheElement );
51 }
52
53
54
55
56
57
58
59 protected final void updateWithEventLogging( final ICacheElement<K, V> cacheElement )
60 throws IOException
61 {
62 final ICacheEvent<K> cacheEvent = createICacheEvent( cacheElement, ICacheEventLogger.UPDATE_EVENT );
63 try
64 {
65 processUpdate( cacheElement );
66 }
67 finally
68 {
69 logICacheEvent( cacheEvent );
70 }
71 }
72
73
74
75
76
77
78
79 protected abstract void processUpdate( ICacheElement<K, V> cacheElement )
80 throws IOException;
81
82
83
84
85
86
87
88
89 @Override
90 public ICacheElement<K, V> get( final K key )
91 throws IOException
92 {
93 return getWithEventLogging( key );
94 }
95
96
97
98
99
100
101
102
103 protected final ICacheElement<K, V> getWithEventLogging( final K key )
104 throws IOException
105 {
106 final ICacheEvent<K> cacheEvent = createICacheEvent( getCacheName(), key, ICacheEventLogger.GET_EVENT );
107 try
108 {
109 return processGet( key );
110 }
111 finally
112 {
113 logICacheEvent( cacheEvent );
114 }
115 }
116
117
118
119
120
121
122
123
124 protected abstract ICacheElement<K, V> processGet( K key )
125 throws IOException;
126
127
128
129
130
131
132
133
134
135 @Override
136 public Map<K, ICacheElement<K, V>> getMultiple(final Set<K> keys)
137 throws IOException
138 {
139 return getMultipleWithEventLogging( keys );
140 }
141
142
143
144
145
146
147
148
149
150 protected final Map<K, ICacheElement<K, V>> getMultipleWithEventLogging(final Set<K> keys )
151 throws IOException
152 {
153 final ICacheEvent<Serializable> cacheEvent = createICacheEvent( getCacheName(), (Serializable) keys,
154 ICacheEventLogger.GETMULTIPLE_EVENT );
155 try
156 {
157 return processGetMultiple( keys );
158 }
159 finally
160 {
161 logICacheEvent( cacheEvent );
162 }
163 }
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179 @Override
180 public Map<K, ICacheElement<K, V>> getMatching( final String pattern )
181 throws IOException
182 {
183 return getMatchingWithEventLogging( pattern );
184 }
185
186
187
188
189
190
191
192
193
194 protected final Map<K, ICacheElement<K, V>> getMatchingWithEventLogging( final String pattern )
195 throws IOException
196 {
197 final ICacheEvent<String> cacheEvent = createICacheEvent( getCacheName(), pattern, ICacheEventLogger.GETMATCHING_EVENT );
198 try
199 {
200 return processGetMatching( pattern );
201 }
202 finally
203 {
204 logICacheEvent( cacheEvent );
205 }
206 }
207
208
209
210
211
212
213
214
215
216 protected abstract Map<K, ICacheElement<K, V>> processGetMatching( String pattern )
217 throws IOException;
218
219
220
221
222
223
224
225
226 @Override
227 public boolean remove( final K key )
228 throws IOException
229 {
230 return removeWithEventLogging( key );
231 }
232
233
234
235
236
237
238
239
240 protected final boolean removeWithEventLogging( final K key )
241 throws IOException
242 {
243 final ICacheEvent<K> cacheEvent = createICacheEvent( getCacheName(), key, ICacheEventLogger.REMOVE_EVENT );
244 try
245 {
246 return processRemove( key );
247 }
248 finally
249 {
250 logICacheEvent( cacheEvent );
251 }
252 }
253
254
255
256
257
258
259
260
261 protected abstract boolean processRemove( K key )
262 throws IOException;
263
264
265
266
267
268
269 @Override
270 public void removeAll()
271 throws IOException
272 {
273 removeAllWithEventLogging();
274 }
275
276
277
278
279
280
281 protected final void removeAllWithEventLogging()
282 throws IOException
283 {
284 final ICacheEvent<String> cacheEvent = createICacheEvent( getCacheName(), "all", ICacheEventLogger.REMOVEALL_EVENT );
285 try
286 {
287 processRemoveAll();
288 }
289 finally
290 {
291 logICacheEvent( cacheEvent );
292 }
293 }
294
295
296
297
298
299
300 protected abstract void processRemoveAll()
301 throws IOException;
302
303
304
305
306
307
308 @Override
309 public void dispose()
310 throws IOException
311 {
312 disposeWithEventLogging();
313 }
314
315
316
317
318
319
320
321 protected final void disposeWithEventLogging()
322 throws IOException
323 {
324 final ICacheEvent<String> cacheEvent = createICacheEvent( getCacheName(), "none", ICacheEventLogger.DISPOSE_EVENT );
325 try
326 {
327 processDispose();
328 }
329 finally
330 {
331 logICacheEvent( cacheEvent );
332 }
333 }
334
335
336
337
338
339
340 protected abstract void processDispose()
341 throws IOException;
342 }