1 package org.apache.commons.jcs.auxiliary;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.commons.jcs.engine.behavior.ICacheElement;
23 import org.apache.commons.jcs.engine.logging.behavior.ICacheEvent;
24 import org.apache.commons.jcs.engine.logging.behavior.ICacheEventLogger;
25
26 import java.io.IOException;
27 import java.io.Serializable;
28 import java.util.Map;
29 import java.util.Set;
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( ICacheElement<K, V> cacheElement )
48 throws IOException
49 {
50 updateWithEventLogging( cacheElement );
51 }
52
53
54
55
56
57
58
59 protected final void updateWithEventLogging( ICacheElement<K, V> cacheElement )
60 throws IOException
61 {
62 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( 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( K key )
104 throws IOException
105 {
106 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(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(Set<K> keys )
151 throws IOException
152 {
153 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 protected abstract Map<K, ICacheElement<K, V>> processGetMultiple(Set<K> keys)
174 throws IOException;
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190 @Override
191 public Map<K, ICacheElement<K, V>> getMatching( String pattern )
192 throws IOException
193 {
194 return getMatchingWithEventLogging( pattern );
195 }
196
197
198
199
200
201
202
203
204
205 protected final Map<K, ICacheElement<K, V>> getMatchingWithEventLogging( String pattern )
206 throws IOException
207 {
208 ICacheEvent<String> cacheEvent = createICacheEvent( getCacheName(), pattern, ICacheEventLogger.GETMATCHING_EVENT );
209 try
210 {
211 return processGetMatching( pattern );
212 }
213 finally
214 {
215 logICacheEvent( cacheEvent );
216 }
217 }
218
219
220
221
222
223
224
225
226
227 protected abstract Map<K, ICacheElement<K, V>> processGetMatching( String pattern )
228 throws IOException;
229
230
231
232
233
234
235
236
237 @Override
238 public boolean remove( K key )
239 throws IOException
240 {
241 return removeWithEventLogging( key );
242 }
243
244
245
246
247
248
249
250
251 protected final boolean removeWithEventLogging( K key )
252 throws IOException
253 {
254 ICacheEvent<K> cacheEvent = createICacheEvent( getCacheName(), key, ICacheEventLogger.REMOVE_EVENT );
255 try
256 {
257 return processRemove( key );
258 }
259 finally
260 {
261 logICacheEvent( cacheEvent );
262 }
263 }
264
265
266
267
268
269
270
271
272 protected abstract boolean processRemove( K key )
273 throws IOException;
274
275
276
277
278
279
280 @Override
281 public void removeAll()
282 throws IOException
283 {
284 removeAllWithEventLogging();
285 }
286
287
288
289
290
291
292 protected final void removeAllWithEventLogging()
293 throws IOException
294 {
295 ICacheEvent<String> cacheEvent = createICacheEvent( getCacheName(), "all", ICacheEventLogger.REMOVEALL_EVENT );
296 try
297 {
298 processRemoveAll();
299 }
300 finally
301 {
302 logICacheEvent( cacheEvent );
303 }
304 }
305
306
307
308
309
310
311 protected abstract void processRemoveAll()
312 throws IOException;
313
314
315
316
317
318
319 @Override
320 public void dispose()
321 throws IOException
322 {
323 disposeWithEventLogging();
324 }
325
326
327
328
329
330
331
332 protected final void disposeWithEventLogging()
333 throws IOException
334 {
335 ICacheEvent<String> cacheEvent = createICacheEvent( getCacheName(), "none", ICacheEventLogger.DISPOSE_EVENT );
336 try
337 {
338 processDispose();
339 }
340 finally
341 {
342 logICacheEvent( cacheEvent );
343 }
344 }
345
346
347
348
349
350
351 protected abstract void processDispose()
352 throws IOException;
353 }