Clover coverage report -
Coverage timestamp: Thu Jul 5 2007 20:02:32 EDT
file stats: LOC: 116   Methods: 3
NCLOC: 76   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
BaseSortedEvictionAlgorithm.java 50% 75% 100% 71.2%
coverage coverage
 1    /*
 2    * JBoss, the OpenSource J2EE webOS
 3    *
 4    * Distributable under LGPL license.
 5    * See terms of license at gnu.org.
 6    */
 7    package org.jboss.cache.eviction;
 8   
 9    import org.apache.commons.logging.Log;
 10    import org.apache.commons.logging.LogFactory;
 11    import org.jboss.cache.Fqn;
 12    import org.jboss.cache.Region;
 13   
 14   
 15    /**
 16    * An abstract SortedEvictionAlgorithm.
 17    * <p/>
 18    * This class supports early termination of the eviction queue processing. Because the eviction
 19    * queue is sorted by first to evict to last to evict, when iterating the eviction queue, the first time
 20    * a node is encountered that does not require eviction will terminate the loop early. This way we don't incur
 21    * the full breadth of the O(n) = n operation everytime we need to check for eviction (defined by eviction poll time
 22    * interval).
 23    *
 24    * @author Daniel Huang - dhuang@jboss.org - 10/2005
 25    */
 26    public abstract class BaseSortedEvictionAlgorithm extends BaseEvictionAlgorithm implements EvictionAlgorithm
 27    {
 28    private static final Log log = LogFactory.getLog(BaseSortedEvictionAlgorithm.class);
 29   
 30  73 public void process(Region region) throws EvictionException
 31    {
 32  73 super.process(region);
 33    }
 34   
 35  73 protected void processQueues(Region region) throws EvictionException
 36    {
 37  73 boolean evictionNodesModified = false;
 38   
 39  73 EvictedEventNode node;
 40  73 int count = 0;
 41  ? while ((node = region.takeLastEventNode()) != null)
 42    {
 43  61274 Fqn fqn = node.getFqn();
 44   
 45  61274 count++;
 46  61274 switch (node.getEventType())
 47    {
 48  10055 case ADD_NODE_EVENT:
 49  10055 this.processAddedNodes(fqn, node.getElementDifference(), node.isResetElementCount());
 50  10055 evictionNodesModified = true;
 51  10055 break;
 52  2005 case REMOVE_NODE_EVENT:
 53  2005 this.processRemovedNodes(fqn);
 54  2005 break;
 55  13150 case VISIT_NODE_EVENT:
 56  13150 this.processVisitedNodes(fqn);
 57  13150 evictionNodesModified = true;
 58  13150 break;
 59  36064 case ADD_ELEMENT_EVENT:
 60  36064 this.processAddedElement(fqn);
 61  36064 evictionNodesModified = true;
 62  36064 break;
 63  0 case REMOVE_ELEMENT_EVENT:
 64  0 this.processRemovedElement(fqn);
 65  0 evictionNodesModified = true;
 66  0 break;
 67  0 default:
 68  0 throw new RuntimeException("Illegal Eviction Event type " + node.getEventType());
 69    }
 70    }
 71   
 72  73 if (log.isTraceEnabled())
 73    {
 74  0 log.trace("Eviction nodes visited or added requires resort of queue " + evictionNodesModified);
 75    }
 76   
 77  73 this.resortEvictionQueue(evictionNodesModified);
 78   
 79   
 80  73 if (log.isTraceEnabled())
 81    {
 82  0 log.trace("processed " + count + " node events");
 83    }
 84   
 85    }
 86   
 87    /**
 88    * This method is called to resort the queue after add or visit events have occurred.
 89    * <p/>
 90    * If the parameter is true, the queue needs to be resorted. If it is false, the queue does not
 91    * need resorting.
 92    *
 93    * @param evictionQueueModified True if the queue was added to or visisted during event processing.
 94    */
 95  73 protected void resortEvictionQueue(boolean evictionQueueModified)
 96    {
 97  73 if (!evictionQueueModified)
 98    {
 99  42 if (log.isDebugEnabled())
 100    {
 101  0 log.debug("Eviction queue not modified. Resort unnecessary.");
 102    }
 103  42 return;
 104    }
 105  31 long begin = System.currentTimeMillis();
 106  31 ((SortedEvictionQueue) evictionQueue).resortEvictionQueue();
 107  31 long end = System.currentTimeMillis();
 108   
 109  31 if (log.isTraceEnabled())
 110    {
 111  0 long diff = end - begin;
 112  0 log.trace("Took " + diff + "ms to sort queue with " + getEvictionQueue().getNumberOfNodes() + " elements");
 113    }
 114    }
 115   
 116    }