1 8 package org.jboss.cache.eviction; 9 10 import EDU.oswego.cs.dl.util.concurrent.BoundedBuffer; 11 import org.jboss.cache.Fqn; 12 import org.jboss.logging.Logger; 13 14 21 public class Region 22 { 23 24 public static final long WAIT_TIME = 10000; 26 private int maxNodes_ = 0; private long timeToLiveSeconds_ = 0; private String fqn_; 31 private EvictionAlgorithm algorithm_; 33 private EvictionPolicy policy_; 35 protected BoundedBuffer nodeEventQueue_; 37 protected Logger log_ = Logger.getLogger(Region.class); 38 39 42 Region() 43 { 44 createQueue(); 45 } 46 47 void createQueue() 48 { 49 nodeEventQueue_ = new BoundedBuffer(RegionManager.CAPACITY); 50 } 51 52 Region(String fqn, EvictionPolicy policy, EvictionAlgorithm algorithm) { 53 fqn_ = fqn; 54 policy_ = policy; 55 algorithm_ = algorithm; 56 57 createQueue(); 58 } 59 60 public int getMaxNodes() { return maxNodes_; } 61 62 public void setMaxNodes(int maxNodes) { maxNodes_ = maxNodes; } 63 64 66 68 public long getTimeToLiveSeconds() { return timeToLiveSeconds_; } 69 70 public void setTimeToLiveSeconds(long secs) { timeToLiveSeconds_ = secs; } 71 72 public EvictionAlgorithm getEvictionAlgorithm() { return algorithm_; } 73 74 public EvictionPolicy getEvictionPolicy() { return policy_; } 75 76 public String getFqn() { return fqn_; } 77 78 public void setAddedNode(Fqn fqn) 79 { 80 putNodeEvent(fqn, EvictedEventNode.ADD_EVENT); 81 } 82 83 public void setRemovedNode(Fqn fqn) 84 { 85 putNodeEvent(fqn, EvictedEventNode.REMOVE_EVENT); 86 } 87 88 public void setVisitedNode(Fqn fqn) 89 { 90 putNodeEvent(fqn, EvictedEventNode.VISIT_EVENT); 91 } 92 93 protected void putNodeEvent(Fqn fqn, Integer event) { 94 try { 95 if( nodeEventQueue_.size() > (100*RegionManager.CAPACITY)/98 ) { 97 log_.warn("putNodeEvent(): eviction node event queue size is at 98% threshold value of capacity: " 98 +RegionManager.CAPACITY + " You will need to reduce the wakeUpIntervalSeconds parameter."); 99 } 100 nodeEventQueue_.put(new EvictedEventNode(fqn, event)); 101 } catch (InterruptedException e) { 102 e.printStackTrace(); } 104 } 105 106 111 public EvictedEventNode takeLastEventNode() 112 { 113 try { 114 return (EvictedEventNode)nodeEventQueue_.poll(0); 115 } catch (InterruptedException e) { 116 e.printStackTrace(); 117 } 118 return null; 119 } 120 121 public int nodeEventQueueSize() 122 { 123 return nodeEventQueue_.size(); 124 } 125 126 public void resetEvictionQueues() 127 { 128 BoundedBuffer q1 = nodeEventQueue_; 129 log_.info("reseteEvictionQueues(): node queue size: " +q1.size() + 130 " region name: " +fqn_); 131 createQueue(); 132 for(int i=0; i < q1.size(); i++) { 134 try { 135 q1.take(); 136 } catch (InterruptedException e) { 137 e.printStackTrace(); 138 } 139 } 140 } 141 142 public String toString() { 143 StringBuffer buf = new StringBuffer (); 144 buf.append("Regions--- fqn: ").append(getFqn()).append(" maxNodes " +getMaxNodes()); 145 buf.append(" TimeToIdleSeconds " +getTimeToLiveSeconds()); 146 return buf.toString(); 147 } 148 } 149 | Popular Tags |