Coverage Report - org.kuali.rice.krad.util.cache.OSCacheMonitor
 
Classes in this File Line Coverage Branch Coverage Complexity
OSCacheMonitor
0%
0/34
0%
0/16
1.889
 
 1  
 /*
 2  
  * Copyright 2005-2007 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.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  
  * Monitor entry-related events for a cache.
 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  
      * Constructs a OSCacheMonitor with the given purpose
 43  
      * 
 44  
      * @param purpose
 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  
         // if I read the code correctly, each entry gets its own cacheEntryFlused event
 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  
         // if I read the code correctly, each entry gets its own cacheEntryFlused event
 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  
 }