1 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 26 public abstract class BaseSortedEvictionAlgorithm extends BaseEvictionAlgorithm implements EvictionAlgorithm 27 { 28 private static final Log log = LogFactory.getLog(BaseSortedEvictionAlgorithm.class); 29 30 public void process(Region region) throws EvictionException 31 { 32 super.process(region); 33 } 34 35 protected void processQueues(Region region) throws EvictionException 36 { 37 boolean evictionNodesModified = false; 38 39 EvictedEventNode node; 40 int count = 0; 41 while ((node = region.takeLastEventNode()) != null) 42 { 43 Fqn fqn = node.getFqn(); 44 45 count++; 46 switch (node.getEventType()) 47 { 48 case ADD_NODE_EVENT: 49 this.processAddedNodes(fqn, node.getElementDifference(), node.isResetElementCount()); 50 evictionNodesModified = true; 51 break; 52 case REMOVE_NODE_EVENT: 53 this.processRemovedNodes(fqn); 54 break; 55 case VISIT_NODE_EVENT: 56 this.processVisitedNodes(fqn); 57 evictionNodesModified = true; 58 break; 59 case ADD_ELEMENT_EVENT: 60 this.processAddedElement(fqn); 61 evictionNodesModified = true; 62 break; 63 case REMOVE_ELEMENT_EVENT: 64 this.processRemovedElement(fqn); 65 evictionNodesModified = true; 66 break; 67 default: 68 throw new RuntimeException ("Illegal Eviction Event type " + node.getEventType()); 69 } 70 } 71 72 if (log.isTraceEnabled()) 73 { 74 log.trace("Eviction nodes visited or added requires resort of queue " + evictionNodesModified); 75 } 76 77 this.resortEvictionQueue(evictionNodesModified); 78 79 80 if (log.isTraceEnabled()) 81 { 82 log.trace("processed " + count + " node events"); 83 } 84 85 } 86 87 95 protected void resortEvictionQueue(boolean evictionQueueModified) 96 { 97 if (!evictionQueueModified) 98 { 99 if (log.isDebugEnabled()) 100 { 101 log.debug("Eviction queue not modified. Resort unnecessary."); 102 } 103 return; 104 } 105 long begin = System.currentTimeMillis(); 106 ((SortedEvictionQueue) evictionQueue).resortEvictionQueue(); 107 long end = System.currentTimeMillis(); 108 109 if (log.isTraceEnabled()) 110 { 111 long diff = end - begin; 112 log.trace("Took " + diff + "ms to sort queue with " + getEvictionQueue().getNumberOfNodes() + " elements"); 113 } 114 } 115 116 } 117 | Popular Tags |