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  
 
 21  
 import com.opensymphony.oscache.base.CacheEntry;
 22  
 import com.opensymphony.oscache.base.events.CacheEntryEvent;
 23  
 
 24  
 /**
 25  
  * MethodCacheMonitor
 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  
      * @see org.kuali.rice.kns.util.cache.OSCacheMonitor#cacheEntryAdded(com.opensymphony.oscache.base.events.CacheEntryEvent)
 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  
      * @see org.kuali.rice.kns.util.cache.OSCacheMonitor#cacheEntryFlushed(com.opensymphony.oscache.base.events.CacheEntryEvent)
 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  
      * @see org.kuali.rice.kns.util.cache.OSCacheMonitor#cacheEntryRemoved(com.opensymphony.oscache.base.events.CacheEntryEvent)
 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  
      * @see org.kuali.rice.kns.util.cache.OSCacheMonitor#cacheEntryUpdated(com.opensymphony.oscache.base.events.CacheEntryEvent)
 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  
 }