01: package junit;
02:
03: import org.apache.commons.logging.Log;
04: import org.apache.commons.logging.LogFactory;
05:
06: import javax.cache.CacheListener;
07:
08: public class TestListener implements CacheListener {
09:
10: private Log log = LogFactory.getLog(TestListener.class);
11:
12: public int loads;
13: public int puts;
14: public int evicts;
15: public int removes;
16: public int clears;
17: public int updates;
18: public int expiries;
19:
20: public void onLoad(Object key) {
21: loads++;
22: if (log.isInfoEnabled())
23: log.info("Key " + key + " loaded");
24: }
25:
26: public void onPut(Object key) {
27: puts++;
28: if (log.isInfoEnabled())
29: log.info("Key " + key + " put in cache");
30: }
31:
32: public void onEvict(Object key) {
33: evicts++;
34: if (log.isInfoEnabled())
35: log.info("Key " + key + " evicted");
36: }
37:
38: public void onRemove(Object key) {
39: removes++;
40: if (log.isInfoEnabled())
41: log.info("Key " + key + " removed");
42: }
43:
44: public void onClear() {
45: clears++;
46: if (log.isInfoEnabled())
47: log.info("Cache cleared");
48: }
49:
50: public void onUpdate(Object key) {
51: updates++;
52: if (log.isInfoEnabled())
53: log.info("Key " + key + " updated");
54: }
55:
56: public void onExpiry(Object key) {
57: expiries++;
58: if (log.isInfoEnabled())
59: log.info("Key " + key + " expired");
60: }
61:
62: public void onShutdown() {
63: // Do nothing
64: if (log.isInfoEnabled())
65: log.info("Cache shutting down");
66: }
67:
68: public void onLoadException(Object key, Exception e) {
69: // dump exception details to logger
70: log.error("Caught load exception when attempting to load key "
71: + key, e);
72:
73: }
74: }
|