1 7 package org.jboss.cache.eviction; 8 9 import org.jboss.cache.config.ConfigurationException; 10 import org.jboss.cache.config.Dynamic; 11 12 28 public class LRUConfiguration extends EvictionPolicyConfigBase 29 { 30 31 private static final long serialVersionUID = -3426716488271559729L; 32 33 @Dynamic 34 private int timeToLiveSeconds; 35 @Dynamic 36 private int maxAgeSeconds; 37 38 public LRUConfiguration() 39 { 40 setEvictionPolicyClassName(); 41 setTimeToLiveSeconds(-1); 43 } 44 45 @Override 46 protected void setEvictionPolicyClassName() 47 { 48 setEvictionPolicyClass(LRUPolicy.class.getName()); 49 } 50 51 52 public int getTimeToLiveSeconds() 53 { 54 return timeToLiveSeconds; 55 } 56 57 public void setTimeToLiveSeconds(int timeToLiveSeconds) 58 { 59 testImmutability("timeToLiveSeconds"); 60 this.timeToLiveSeconds = timeToLiveSeconds; 61 } 62 63 public int getMaxAgeSeconds() 64 { 65 return maxAgeSeconds; 66 } 67 68 public void setMaxAgeSeconds(int maxAgeSeconds) 69 { 70 testImmutability("maxAgeSeconds"); 71 this.maxAgeSeconds = maxAgeSeconds; 72 } 73 74 78 @Override 79 public void validate() throws ConfigurationException 80 { 81 if (timeToLiveSeconds < 0) 82 throw new ConfigurationException("timeToLiveSeconds not configured"); 83 } 84 85 public String toString() 86 { 87 StringBuffer str = new StringBuffer (); 88 str.append("LRUConfiguration: timeToLiveSeconds = ").append(getTimeToLiveSeconds()).append(" maxAgeSeconds ="); 89 str.append(getMaxAgeSeconds()).append(" maxNodes =").append(getMaxNodes()); 90 return str.toString(); 91 } 92 93 @Override 94 public boolean equals(Object obj) 95 { 96 if (obj instanceof LRUConfiguration && super.equals(obj)) 97 { 98 LRUConfiguration other = (LRUConfiguration) obj; 99 return maxAgeSeconds == other.maxAgeSeconds 100 && timeToLiveSeconds == other.timeToLiveSeconds; 101 } 102 return false; 103 } 104 105 @Override 106 public int hashCode() 107 { 108 int result = super.hashCode(); 109 result = 31 * result + maxAgeSeconds; 110 result = 31 * result + timeToLiveSeconds; 111 return result; 112 } 113 114 @Override 115 public void reset() 116 { 117 super.reset(); 118 setTimeToLiveSeconds(-1); 119 } 120 121 } 122 | Popular Tags |