1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kns.util.cache; |
17 | |
|
18 | |
import org.apache.commons.logging.Log; |
19 | |
import org.apache.commons.logging.LogFactory; |
20 | |
|
21 | |
import com.opensymphony.oscache.base.CacheEntry; |
22 | |
import com.opensymphony.oscache.base.events.CacheEntryEvent; |
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
@SuppressWarnings("unchecked") |
30 | |
public class MethodResultsCacheMonitor extends OSCacheMonitor { |
31 | 0 | private static final Log LOG = LogFactory.getLog(MethodResultsCacheMonitor.class); |
32 | |
|
33 | |
private int entryCount; |
34 | |
private int byteSize; |
35 | |
|
36 | |
public MethodResultsCacheMonitor() { |
37 | 0 | super("methodResultsCache"); |
38 | |
|
39 | 0 | byteSize = 0; |
40 | 0 | entryCount = 0; |
41 | 0 | } |
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
public void cacheEntryAdded(CacheEntryEvent event) { |
47 | 0 | super.cacheEntryAdded(event); |
48 | |
|
49 | 0 | CacheEntry ce = event.getEntry(); |
50 | 0 | CopiedObject co = (CopiedObject) ce.getContent(); |
51 | 0 | if ( LOG.isDebugEnabled() ) { |
52 | 0 | LOG.debug("cached entry for key '" + ce.getKey() + "', size " + co.getSize() + " bytes"); |
53 | |
} |
54 | |
|
55 | 0 | entryCount++; |
56 | 0 | byteSize += co.getSize(); |
57 | 0 | if ( LOG.isDebugEnabled() ) { |
58 | 0 | LOG.debug("cache size now " + entryCount + " entries, " + byteSize + " bytes"); |
59 | |
} |
60 | 0 | } |
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
public void cacheEntryFlushed(CacheEntryEvent event) { |
66 | 0 | super.cacheEntryFlushed(event); |
67 | |
|
68 | 0 | CacheEntry ce = event.getEntry(); |
69 | 0 | CopiedObject co = (CopiedObject) ce.getContent(); |
70 | 0 | if ( LOG.isDebugEnabled() ) { |
71 | 0 | LOG.debug("flushed entry for key '" + ce.getKey() + "', size " + co.getSize() + " bytes"); |
72 | |
} |
73 | |
|
74 | 0 | entryCount--; |
75 | 0 | byteSize -= co.getSize(); |
76 | 0 | if ( LOG.isDebugEnabled() ) { |
77 | 0 | LOG.debug("cache size now " + entryCount + " entries, " + byteSize + " bytes"); |
78 | |
} |
79 | 0 | } |
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | |
public void cacheEntryRemoved(CacheEntryEvent event) { |
85 | 0 | super.cacheEntryRemoved(event); |
86 | |
|
87 | 0 | CacheEntry ce = event.getEntry(); |
88 | 0 | CopiedObject co = (CopiedObject) ce.getContent(); |
89 | 0 | if ( LOG.isDebugEnabled() ) { |
90 | 0 | LOG.debug("removed entry for key '" + ce.getKey() + "', size " + co.getSize() + " bytes"); |
91 | |
} |
92 | |
|
93 | 0 | entryCount--; |
94 | 0 | byteSize -= co.getSize(); |
95 | 0 | if ( LOG.isDebugEnabled() ) { |
96 | 0 | LOG.debug("cache size now " + entryCount + " entries, " + byteSize + " bytes"); |
97 | |
} |
98 | 0 | } |
99 | |
|
100 | |
|
101 | |
|
102 | |
|
103 | |
public void cacheEntryUpdated(CacheEntryEvent event) { |
104 | 0 | super.cacheEntryUpdated(event); |
105 | |
|
106 | 0 | CacheEntry ce = event.getEntry(); |
107 | 0 | CopiedObject co = (CopiedObject) ce.getContent(); |
108 | 0 | if ( LOG.isDebugEnabled() ) { |
109 | 0 | LOG.debug("updated entry for key '" + ce.getKey() + "', size " + co.getSize() + " bytes"); |
110 | |
} |
111 | |
|
112 | 0 | byteSize -= co.getOldSize(); |
113 | 0 | byteSize += co.getSize(); |
114 | 0 | if ( LOG.isDebugEnabled() ) { |
115 | 0 | LOG.debug("cache size now " + entryCount + " entries, " + byteSize + " bytes"); |
116 | |
} |
117 | 0 | } |
118 | |
} |