Coverage Report - org.kuali.rice.kns.util.cache.MethodResultsCacheMonitor
 
Classes in this File Line Coverage Branch Coverage Complexity
MethodResultsCacheMonitor
0%
0/45
0%
0/16
2.6
 
 1  
 /*
 2  
  * Copyright 2005-2008 The Kuali Foundation
 3  
  * 
 4  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  * 
 8  
  * http://www.opensource.org/licenses/ecl2.php
 9  
  * 
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 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  
  * MethodCacheMonitor
 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  
      * @see org.kuali.rice.kns.util.cache.OSCacheMonitor#cacheEntryAdded(com.opensymphony.oscache.base.events.CacheEntryEvent)
 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  
      * @see org.kuali.rice.kns.util.cache.OSCacheMonitor#cacheEntryFlushed(com.opensymphony.oscache.base.events.CacheEntryEvent)
 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  
      * @see org.kuali.rice.kns.util.cache.OSCacheMonitor#cacheEntryRemoved(com.opensymphony.oscache.base.events.CacheEntryEvent)
 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  
      * @see org.kuali.rice.kns.util.cache.OSCacheMonitor#cacheEntryUpdated(com.opensymphony.oscache.base.events.CacheEntryEvent)
 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  
 }