1 22 package org.jboss.cache.config; 23 24 import org.jboss.cache.RegionManager; 25 import org.jboss.cache.eviction.EvictionPolicy; 26 import org.jboss.cache.eviction.EvictionPolicyConfig; 27 28 import java.util.Collections ; 29 import java.util.List ; 30 31 public class EvictionConfig extends ConfigurationComponent 32 { 33 36 private static final long serialVersionUID = -7979639000026975201L; 37 38 public static final String WAKEUP_INTERVAL_SECONDS = "wakeUpIntervalSeconds"; 39 40 public static final int WAKEUP_DEFAULT = 5; 41 42 public static final String EVENT_QUEUE_SIZE = "eventQueueSize"; 43 44 public static final String EVICTION_POLICY_CLASS = "policyClass"; 45 46 public static final int EVENT_QUEUE_SIZE_DEFAULT = 200000; 47 48 private String defaultEvictionPolicyClass; 49 50 private int wakeupIntervalSeconds = WAKEUP_DEFAULT; 51 52 private int defaultEventQueueSize = EVENT_QUEUE_SIZE_DEFAULT; 53 54 @Dynamic 56 private List <EvictionRegionConfig> evictionRegionConfigs; 57 58 public EvictionConfig() 59 { 60 } 61 62 public EvictionConfig(String defaultEvictionClass) 63 { 64 setDefaultEvictionPolicyClass(defaultEvictionClass); 65 } 66 67 public boolean isValidConfig() 68 { 69 return (defaultEvictionPolicyClass != null && defaultEvictionPolicyClass.length() > 0) 70 || (evictionRegionConfigs != null && evictionRegionConfigs.size() > 0); 71 } 72 73 public String getDefaultEvictionPolicyClass() 74 { 75 return defaultEvictionPolicyClass; 76 } 77 78 public void setDefaultEvictionPolicyClass(String defaultEvictionPolicyClass) 79 { 80 testImmutability("defaultEvictionPolicyClass"); 81 this.defaultEvictionPolicyClass = defaultEvictionPolicyClass; 82 } 83 84 public List <EvictionRegionConfig> getEvictionRegionConfigs() 85 { 86 if (evictionRegionConfigs == null && defaultEvictionPolicyClass != null) 87 { 88 try 90 { 91 Class <EvictionPolicy> cpolicy = (Class <EvictionPolicy>) Class.forName(defaultEvictionPolicyClass); 92 EvictionPolicy policy; 93 policy = cpolicy.newInstance(); 94 EvictionRegionConfig erc = new EvictionRegionConfig(); 95 EvictionPolicyConfig epc = policy.getEvictionConfigurationClass().newInstance(); 96 erc.setEvictionPolicyConfig(epc); 98 erc.setRegionFqn(RegionManager.DEFAULT_REGION); 99 return Collections.singletonList(erc); 100 } 101 catch (Exception e) 102 { 103 throw new ConfigurationException(e); 104 } 105 } 106 return evictionRegionConfigs; 107 } 108 109 public int getDefaultEventQueueSize() 110 { 111 return defaultEventQueueSize; 112 } 113 114 public void setDefaultEventQueueSize(int eventQueueSize) 115 { 116 this.defaultEventQueueSize = eventQueueSize; 117 } 118 119 public void setEvictionRegionConfigs(List <EvictionRegionConfig> evictionRegionConfigs) 120 { 121 testImmutability("evictionRegionConfigs"); 122 123 if (evictionRegionConfigs != null) 125 { 126 for (EvictionRegionConfig cfg : evictionRegionConfigs) 127 { 128 cfg.setDefaultEventQueueSize(getDefaultEventQueueSize()); 129 } 130 } 131 replaceChildConfigs(this.evictionRegionConfigs, evictionRegionConfigs); 132 this.evictionRegionConfigs = evictionRegionConfigs; 133 } 134 135 public int getWakeupIntervalSeconds() 136 { 137 return wakeupIntervalSeconds; 138 } 139 140 public void setWakeupIntervalSeconds(int wakeupIntervalSeconds) 141 { 142 testImmutability("wakeupIntervalSeconds"); 143 this.wakeupIntervalSeconds = wakeupIntervalSeconds; 144 } 145 146 public boolean equals(Object obj) 147 { 148 if (this == obj) 149 return true; 150 151 if (obj instanceof EvictionConfig) 152 { 153 EvictionConfig other = (EvictionConfig) obj; 154 return (this.wakeupIntervalSeconds == other.wakeupIntervalSeconds) 155 && safeEquals(this.defaultEvictionPolicyClass, other.defaultEvictionPolicyClass) 156 && safeEquals(this.evictionRegionConfigs, other.evictionRegionConfigs); 157 } 158 return false; 159 } 160 161 public int hashCode() 162 { 163 int result = 17; 164 result = 37 * result + wakeupIntervalSeconds; 165 result = 37 * result + (defaultEvictionPolicyClass == null ? 0 : defaultEvictionPolicyClass.hashCode()); 166 result = 37 * result + (evictionRegionConfigs == null ? 0 : evictionRegionConfigs.hashCode()); 167 return result; 168 } 169 } 170 | Popular Tags |