1 8 package org.jboss.cache.eviction; 9 import org.jboss.cache.Fqn; 10 import org.jboss.cache.aop.AOPInstance; 11 import org.jboss.cache.aop.TreeCacheAop; 12 13 import java.util.Iterator ; 14 import java.util.Set ; 15 16 17 22 public class AopLRUPolicy extends LRUPolicy implements AopEvictionPolicy 23 { 24 public AopLRUPolicy() { 25 super(); 26 } 27 28 33 public void nodeVisited(Fqn fqn) 34 { 35 if(isInternalNode(fqn)) return; 36 37 Region region = regionManager_.getRegion(fqn.toString()); 38 region.setVisitedNode(fqn); 40 41 if(!isAopNode(fqn)) 42 return; 43 44 45 visitChildrenRecursively(region, fqn); 46 } 47 48 protected void visitChildrenRecursively(Region region, Fqn fqn) { 49 Set set = getChildrenNames(fqn); 50 int size = (set == null) ? 0: set.size(); 51 if(log_.isTraceEnabled()) { 52 log_.trace("nodeVisited(): is an aop node. fqn- " +fqn + " size of children is " +size); 53 } 54 55 if(set == null) return; Iterator it = set.iterator(); 57 while(it.hasNext()) { 58 Object childName = it.next(); 59 Fqn fqnKid = new Fqn(fqn, childName); 60 visitChildrenRecursively(region, fqnKid); 61 region.setVisitedNode(fqnKid); 62 } 63 } 64 65 private boolean isAopNode(Fqn fqn) 66 { 67 try { 68 return (cache_.peek(fqn, AOPInstance.KEY) != null) ? true: false; 69 } catch (Exception e) { 70 log_.warn("isAopNode(): cache get operation generated exception " +e); 71 return false; 72 } 73 } 74 75 public void nodeAdded(Fqn fqn) 76 { 77 if(isInternalNode(fqn)) return; 78 79 super.nodeAdded(fqn); 80 } 81 82 87 public void nodeRemoved(Fqn fqn) 88 { 89 if(isInternalNode(fqn)) return; 90 91 super.nodeRemoved(fqn); 92 } 93 94 public void nodeModified(Fqn fqn) { 95 super.nodeModified(fqn); 96 } 97 98 protected EvictionAlgorithm getEvictionAlgorithm() { 100 return new LRUAlgorithm(); 101 } 102 103 109 protected boolean isInternalNode(Fqn fqn) { 110 String startStr = (String )fqn.get(0); 111 if( startStr.equals(TreeCacheAop.JBOSS_INTERNAL.get(0))) return true; 112 113 return false; 114 } 115 } 116 | Popular Tags |