| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.rice.krad.util.cache; |
| 17 | |
|
| 18 | |
import java.util.HashSet; |
| 19 | |
import java.util.Set; |
| 20 | |
|
| 21 | |
import org.apache.commons.logging.Log; |
| 22 | |
import org.apache.commons.logging.LogFactory; |
| 23 | |
|
| 24 | |
import com.opensymphony.oscache.base.events.CacheEntryEvent; |
| 25 | |
import com.opensymphony.oscache.base.events.CacheEntryEventListener; |
| 26 | |
import com.opensymphony.oscache.base.events.CacheGroupEvent; |
| 27 | |
import com.opensymphony.oscache.base.events.CachePatternEvent; |
| 28 | |
import com.opensymphony.oscache.base.events.CachewideEvent; |
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
@SuppressWarnings("unchecked") |
| 35 | |
abstract public class OSCacheMonitor implements CacheEntryEventListener { |
| 36 | 0 | private static final Log LOG = LogFactory.getLog(OSCacheMonitor.class); |
| 37 | |
|
| 38 | |
private final String purpose; |
| 39 | |
private final Set entries; |
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | 0 | public OSCacheMonitor(String purpose) { |
| 47 | 0 | this.purpose = purpose; |
| 48 | 0 | entries = new HashSet(); |
| 49 | |
|
| 50 | 0 | if ( LOG.isInfoEnabled() ) { |
| 51 | 0 | LOG.info("created " + purpose + " CacheMonitor "); |
| 52 | |
} |
| 53 | 0 | } |
| 54 | |
|
| 55 | |
|
| 56 | |
public void cacheEntryAdded(CacheEntryEvent event) { |
| 57 | 0 | entries.add(event.getKey()); |
| 58 | 0 | if ( LOG.isDebugEnabled() ) { |
| 59 | 0 | logEntryEvent("added", event); |
| 60 | |
} |
| 61 | 0 | } |
| 62 | |
|
| 63 | |
public void cacheEntryUpdated(CacheEntryEvent event) { |
| 64 | 0 | if ( LOG.isDebugEnabled() ) { |
| 65 | 0 | logEntryEvent("updated", event); |
| 66 | |
} |
| 67 | 0 | } |
| 68 | |
|
| 69 | |
public void cacheEntryFlushed(CacheEntryEvent event) { |
| 70 | 0 | entries.remove(event.getKey()); |
| 71 | 0 | if ( LOG.isDebugEnabled() ) { |
| 72 | 0 | logEntryEvent("flushed", event); |
| 73 | |
} |
| 74 | 0 | } |
| 75 | |
|
| 76 | |
public void cacheEntryRemoved(CacheEntryEvent event) { |
| 77 | 0 | entries.remove(event.getKey()); |
| 78 | 0 | if ( LOG.isDebugEnabled() ) { |
| 79 | 0 | logEntryEvent("removed", event); |
| 80 | |
} |
| 81 | 0 | } |
| 82 | |
|
| 83 | |
public void cacheFlushed(CachewideEvent event) { |
| 84 | 0 | entries.clear(); |
| 85 | 0 | if ( LOG.isDebugEnabled() ) { |
| 86 | 0 | LOG.debug(purpose + " flushed cache (" + entries.size() + " entries)"); |
| 87 | |
} |
| 88 | 0 | } |
| 89 | |
|
| 90 | |
|
| 91 | |
public void cacheGroupFlushed(CacheGroupEvent event) { |
| 92 | |
|
| 93 | 0 | if ( LOG.isInfoEnabled() ) { |
| 94 | 0 | LOG.info(purpose + " flushed cache group '" + event.getGroup() + "'"); |
| 95 | |
} |
| 96 | 0 | } |
| 97 | |
|
| 98 | |
public void cachePatternFlushed(CachePatternEvent event) { |
| 99 | |
|
| 100 | 0 | if ( LOG.isInfoEnabled() ) { |
| 101 | 0 | LOG.info(purpose + " flushed cache pattern '" + event.getPattern() + "'"); |
| 102 | |
} |
| 103 | 0 | } |
| 104 | |
|
| 105 | |
private void logEntryEvent(String verb, CacheEntryEvent event) { |
| 106 | 0 | LOG.debug(purpose + " " + verb + " entry '" + event.getKey() + "' (" + entries.size() + " entries)"); |
| 107 | 0 | } |
| 108 | |
} |