1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| package org.jboss.cache.config; |
8 |
| |
9 |
| import org.jboss.cache.xml.XmlHelper; |
10 |
| |
11 |
| import java.io.ByteArrayInputStream; |
12 |
| import java.io.IOException; |
13 |
| import java.util.ArrayList; |
14 |
| import java.util.List; |
15 |
| import java.util.Properties; |
16 |
| |
17 |
| |
18 |
| |
19 |
| |
20 |
| |
21 |
| |
22 |
| |
23 |
| |
24 |
| public class CacheLoaderConfig extends ConfigurationComponent |
25 |
| { |
26 |
| private static final long serialVersionUID = 2210349340378984424L; |
27 |
| |
28 |
| private boolean passivation; |
29 |
| private String preload; |
30 |
| private List<IndividualCacheLoaderConfig> cacheLoaderConfigs = new ArrayList<IndividualCacheLoaderConfig>(); |
31 |
| |
32 |
| private boolean shared; |
33 |
| |
34 |
1736
| public CacheLoaderConfig()
|
35 |
| { |
36 |
| } |
37 |
| |
38 |
2083
| public String getPreload()
|
39 |
| { |
40 |
2083
| return preload;
|
41 |
| } |
42 |
| |
43 |
1724
| public void setPreload(String preload)
|
44 |
| { |
45 |
1724
| testImmutability("preload");
|
46 |
1724
| this.preload = preload;
|
47 |
| } |
48 |
| |
49 |
1738
| public void setPassivation(boolean passivation)
|
50 |
| { |
51 |
1738
| testImmutability("passivation");
|
52 |
1738
| this.passivation = passivation;
|
53 |
| } |
54 |
| |
55 |
2107
| public boolean isPassivation()
|
56 |
| { |
57 |
2107
| return passivation;
|
58 |
| } |
59 |
| |
60 |
1820
| public void addIndividualCacheLoaderConfig(IndividualCacheLoaderConfig clc)
|
61 |
| { |
62 |
1820
| testImmutability("cacheLoaderConfigs");
|
63 |
1820
| cacheLoaderConfigs.add(clc);
|
64 |
| |
65 |
1820
| addChildConfig(clc);
|
66 |
| } |
67 |
| |
68 |
1071
| public List<IndividualCacheLoaderConfig> getIndividualCacheLoaderConfigs()
|
69 |
| { |
70 |
1071
| return cacheLoaderConfigs;
|
71 |
| } |
72 |
| |
73 |
1060
| public void setIndividualCacheLoaderConfigs(List<IndividualCacheLoaderConfig> configs)
|
74 |
| { |
75 |
1060
| testImmutability("cacheLoaderConfigs");
|
76 |
| |
77 |
1060
| replaceChildConfigs(this.cacheLoaderConfigs, configs);
|
78 |
1060
| this.cacheLoaderConfigs = configs == null ? new ArrayList<IndividualCacheLoaderConfig>() : configs;
|
79 |
| } |
80 |
| |
81 |
991
| public IndividualCacheLoaderConfig getFirstCacheLoaderConfig()
|
82 |
| { |
83 |
1
| if (cacheLoaderConfigs.size() == 0) return null;
|
84 |
990
| return cacheLoaderConfigs.get(0);
|
85 |
| } |
86 |
| |
87 |
1063
| public boolean useChainingCacheLoader()
|
88 |
| { |
89 |
1063
| return !isPassivation() && cacheLoaderConfigs.size() > 1;
|
90 |
| } |
91 |
| |
92 |
0
| public String toString()
|
93 |
| { |
94 |
0
| return new StringBuffer().append("CacheLoaderConfig{").append("shared=").append(shared).append(", passivation=").append(passivation).append(", preload='").append(preload).append('\'').append(", cacheLoaderConfigs.size()=").append(cacheLoaderConfigs.size()).append('}').toString();
|
95 |
| } |
96 |
| |
97 |
1724
| public void setShared(boolean shared)
|
98 |
| { |
99 |
1724
| testImmutability("shared");
|
100 |
1724
| this.shared = shared;
|
101 |
| } |
102 |
| |
103 |
40337
| public boolean isShared()
|
104 |
| { |
105 |
40337
| return shared;
|
106 |
| } |
107 |
| |
108 |
0
| public boolean equals(Object obj)
|
109 |
| { |
110 |
0
| if (this == obj)
|
111 |
0
| return true;
|
112 |
| |
113 |
0
| if (obj instanceof CacheLoaderConfig)
|
114 |
| { |
115 |
0
| CacheLoaderConfig other = (CacheLoaderConfig) obj;
|
116 |
0
| return (this.passivation == other.passivation)
|
117 |
| && (this.shared == other.shared) |
118 |
| && safeEquals(this.preload, other.preload) |
119 |
| && safeEquals(this.cacheLoaderConfigs, other.cacheLoaderConfigs); |
120 |
| } |
121 |
0
| return false;
|
122 |
| } |
123 |
| |
124 |
2357
| public int hashCode()
|
125 |
| { |
126 |
2357
| int result = 19;
|
127 |
2357
| result = 51 * result + (passivation ? 0 : 1);
|
128 |
2357
| result = 51 * result + (shared ? 0 : 1);
|
129 |
2357
| result = 51 * result + (preload == null ? 0 : preload.hashCode());
|
130 |
2357
| result = 51 * result + (cacheLoaderConfigs == null ? 0 : cacheLoaderConfigs.hashCode());
|
131 |
2357
| return result;
|
132 |
| } |
133 |
| |
134 |
| |
135 |
| |
136 |
| |
137 |
| |
138 |
| |
139 |
| |
140 |
| public static class IndividualCacheLoaderConfig extends ConfigurationComponent |
141 |
| { |
142 |
| private static final long serialVersionUID = -2282396799100828593L; |
143 |
| |
144 |
| private String className; |
145 |
| private boolean async; |
146 |
| private boolean ignoreModifications; |
147 |
| private boolean fetchPersistentState; |
148 |
| private boolean singletonStore; |
149 |
| private boolean pushStateWhenCoordinator; |
150 |
| |
151 |
| private boolean purgeOnStartup; |
152 |
| |
153 |
| private Properties properties; |
154 |
| |
155 |
2753
| public IndividualCacheLoaderConfig()
|
156 |
| { |
157 |
| } |
158 |
| |
159 |
912
| protected void populateFromBaseConfig(IndividualCacheLoaderConfig base)
|
160 |
| { |
161 |
912
| if (base != null)
|
162 |
| { |
163 |
912
| setAsync(base.isAsync());
|
164 |
912
| setIgnoreModifications(base.isIgnoreModifications());
|
165 |
912
| setFetchPersistentState(base.isFetchPersistentState());
|
166 |
912
| setSingletonStore(base.isSingletonStore());
|
167 |
912
| setPushStateWhenCoordinator(base.isPushStateWhenCoordinator());
|
168 |
912
| setPurgeOnStartup(base.isPurgeOnStartup());
|
169 |
912
| Properties props = base.getProperties();
|
170 |
912
| if (props != null)
|
171 |
912
| setProperties(props);
|
172 |
| } |
173 |
| } |
174 |
| |
175 |
1864
| public boolean isPurgeOnStartup()
|
176 |
| { |
177 |
1864
| return purgeOnStartup;
|
178 |
| } |
179 |
| |
180 |
2064
| public boolean isFetchPersistentState()
|
181 |
| { |
182 |
2064
| return fetchPersistentState;
|
183 |
| } |
184 |
| |
185 |
2739
| public void setFetchPersistentState(boolean fetchPersistentState)
|
186 |
| { |
187 |
2739
| testImmutability("fetchPersistentState");
|
188 |
2739
| this.fetchPersistentState = fetchPersistentState;
|
189 |
| } |
190 |
| |
191 |
2755
| public void setClassName(String className)
|
192 |
| { |
193 |
2755
| testImmutability("className");
|
194 |
2755
| this.className = className;
|
195 |
| } |
196 |
| |
197 |
1142
| public String getClassName()
|
198 |
| { |
199 |
1142
| return className;
|
200 |
| } |
201 |
| |
202 |
2732
| public void setAsync(boolean async)
|
203 |
| { |
204 |
2732
| testImmutability("async");
|
205 |
2732
| this.async = async;
|
206 |
| } |
207 |
| |
208 |
2054
| public boolean isAsync()
|
209 |
| { |
210 |
2054
| return async;
|
211 |
| } |
212 |
| |
213 |
2713
| public void setIgnoreModifications(boolean ignoreModifications)
|
214 |
| { |
215 |
2713
| testImmutability("ignoreModifications");
|
216 |
2713
| this.ignoreModifications = ignoreModifications;
|
217 |
| } |
218 |
| |
219 |
1205
| public boolean isIgnoreModifications()
|
220 |
| { |
221 |
1205
| return ignoreModifications;
|
222 |
| } |
223 |
| |
224 |
0
| public void setProperties(String properties) throws IOException
|
225 |
| { |
226 |
0
| if (properties == null) return;
|
227 |
| |
228 |
0
| testImmutability("properties");
|
229 |
| |
230 |
| |
231 |
0
| properties = XmlHelper.escapeBackslashes(properties);
|
232 |
0
| ByteArrayInputStream is = new ByteArrayInputStream(properties.trim().getBytes("ISO8859_1"));
|
233 |
0
| this.properties = new Properties();
|
234 |
0
| this.properties.load(is);
|
235 |
0
| is.close();
|
236 |
| } |
237 |
| |
238 |
2739
| public void setProperties(Properties properties)
|
239 |
| { |
240 |
2739
| testImmutability("properties");
|
241 |
2739
| this.properties = properties;
|
242 |
| } |
243 |
| |
244 |
981
| public Properties getProperties()
|
245 |
| { |
246 |
981
| return properties;
|
247 |
| } |
248 |
| |
249 |
2713
| public void setPurgeOnStartup(boolean purgeOnStartup)
|
250 |
| { |
251 |
2713
| testImmutability("purgeOnStartup");
|
252 |
2713
| this.purgeOnStartup = purgeOnStartup;
|
253 |
| } |
254 |
| |
255 |
2210
| public boolean isSingletonStore()
|
256 |
| { |
257 |
2210
| return singletonStore;
|
258 |
| } |
259 |
| |
260 |
2713
| public void setSingletonStore(boolean singletonStore)
|
261 |
| { |
262 |
2713
| testImmutability("singletonStore");
|
263 |
2713
| this.singletonStore = singletonStore;
|
264 |
| } |
265 |
| |
266 |
933
| public boolean isPushStateWhenCoordinator()
|
267 |
| { |
268 |
933
| return singletonStore && pushStateWhenCoordinator;
|
269 |
| } |
270 |
| |
271 |
2713
| public void setPushStateWhenCoordinator(boolean pushStateWhenCoordinator)
|
272 |
| { |
273 |
2713
| testImmutability("pushStateWhenCoordinator");
|
274 |
| |
275 |
| |
276 |
| |
277 |
| |
278 |
| |
279 |
| |
280 |
| |
281 |
2713
| this.pushStateWhenCoordinator = pushStateWhenCoordinator;
|
282 |
| |
283 |
| } |
284 |
| |
285 |
2
| public boolean equals(Object obj)
|
286 |
| { |
287 |
2
| return equalsExcludingProperties(obj)
|
288 |
| && safeEquals(this.properties, ((IndividualCacheLoaderConfig) obj).properties); |
289 |
| } |
290 |
| |
291 |
5
| protected boolean equalsExcludingProperties(Object obj)
|
292 |
| { |
293 |
5
| if (this == obj)
|
294 |
0
| return true;
|
295 |
| |
296 |
5
| if (obj instanceof IndividualCacheLoaderConfig)
|
297 |
| { |
298 |
5
| IndividualCacheLoaderConfig other = (IndividualCacheLoaderConfig) obj;
|
299 |
5
| return safeEquals(this.className, other.className)
|
300 |
| && (this.async == other.async) |
301 |
| && (this.ignoreModifications == other.ignoreModifications) |
302 |
| && (this.fetchPersistentState == other.fetchPersistentState) |
303 |
| && (this.singletonStore == other.singletonStore) |
304 |
| && (this.pushStateWhenCoordinator == other.pushStateWhenCoordinator); |
305 |
| } |
306 |
0
| return false;
|
307 |
| |
308 |
| } |
309 |
| |
310 |
5492
| public int hashCode()
|
311 |
| { |
312 |
5492
| return 31 * hashCodeExcludingProperties() + (properties == null ? 0 : properties.hashCode());
|
313 |
| } |
314 |
| |
315 |
6376
| protected int hashCodeExcludingProperties()
|
316 |
| { |
317 |
6376
| int result = 17;
|
318 |
6376
| result = 31 * result + (className == null ? 0 : className.hashCode());
|
319 |
6376
| result = 31 * result + (async ? 0 : 1);
|
320 |
6376
| result = 31 * result + (ignoreModifications ? 0 : 1);
|
321 |
6376
| result = 31 * result + (fetchPersistentState ? 0 : 1);
|
322 |
6376
| result = 31 * result + (singletonStore ? 0 : 1);
|
323 |
6376
| result = 31 * result + (pushStateWhenCoordinator ? 0 : 1);
|
324 |
6376
| result = 31 * result + (purgeOnStartup ? 0 : 1);
|
325 |
6376
| return result;
|
326 |
| } |
327 |
| |
328 |
0
| public String toString()
|
329 |
| { |
330 |
0
| return new StringBuffer().append("IndividualCacheLoaderConfig{").append("className='").append(className).append('\'')
|
331 |
| .append(", async=").append(async) |
332 |
| .append(", ignoreModifications=").append(ignoreModifications) |
333 |
| .append(", fetchPersistentState=").append(fetchPersistentState) |
334 |
| .append(", properties=").append(properties).append('}') |
335 |
| .append(", purgeOnStartup=").append(purgeOnStartup) |
336 |
| .append(", singletonStore=").append(singletonStore) |
337 |
| .append(", singletonStore.pushStateWhenCoordinator=").append(pushStateWhenCoordinator) |
338 |
| .toString(); |
339 |
| } |
340 |
| } |
341 |
| } |