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