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