1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| package org.jboss.cache.config; |
8 |
| |
9 |
| import org.apache.commons.logging.Log; |
10 |
| import org.apache.commons.logging.LogFactory; |
11 |
| import org.jboss.cache.CacheImpl; |
12 |
| |
13 |
| import java.io.Serializable; |
14 |
| import java.util.Collection; |
15 |
| import java.util.Collections; |
16 |
| import java.util.HashSet; |
17 |
| import java.util.Set; |
18 |
| |
19 |
| |
20 |
| |
21 |
| |
22 |
| |
23 |
| |
24 |
| |
25 |
| |
26 |
| |
27 |
| public class ConfigurationComponent implements Serializable, Cloneable |
28 |
| { |
29 |
| private static final long serialVersionUID = 4879873994727821938L; |
30 |
| |
31 |
| protected transient Log log = LogFactory.getLog(getClass()); |
32 |
| private transient CacheImpl cache; |
33 |
| private final Set<ConfigurationComponent> children = |
34 |
| Collections.synchronizedSet(new HashSet<ConfigurationComponent>()); |
35 |
| |
36 |
23261
| protected ConfigurationComponent()
|
37 |
| { |
38 |
| } |
39 |
| |
40 |
0
| public void passCacheToChildConfig(ConfigurationComponent child)
|
41 |
| { |
42 |
0
| if (child != null)
|
43 |
| { |
44 |
0
| child.setCacheImpl(cache);
|
45 |
| } |
46 |
| } |
47 |
| |
48 |
13056
| protected void addChildConfig(ConfigurationComponent child)
|
49 |
| { |
50 |
13056
| if (child != null && children.add(child))
|
51 |
12243
| child.setCacheImpl(cache);
|
52 |
| } |
53 |
| |
54 |
2069
| protected void addChildConfigs(Collection<? extends ConfigurationComponent> toAdd)
|
55 |
| { |
56 |
2069
| if (toAdd != null)
|
57 |
| { |
58 |
2069
| for (ConfigurationComponent child : toAdd)
|
59 |
4166
| addChildConfig(child);
|
60 |
| } |
61 |
| } |
62 |
| |
63 |
4022
| protected void removeChildConfig(ConfigurationComponent child)
|
64 |
| { |
65 |
4022
| children.remove(child);
|
66 |
| } |
67 |
| |
68 |
2069
| protected void removeChildConfigs(Collection<? extends ConfigurationComponent> toRemove)
|
69 |
| { |
70 |
2069
| if (toRemove != null)
|
71 |
| { |
72 |
1060
| for (ConfigurationComponent child : toRemove)
|
73 |
1142
| removeChildConfig(child);
|
74 |
| } |
75 |
| } |
76 |
| |
77 |
2868
| protected void replaceChildConfig(ConfigurationComponent oldConfig, ConfigurationComponent newConfig)
|
78 |
| { |
79 |
2868
| removeChildConfig(oldConfig);
|
80 |
2868
| addChildConfig(newConfig);
|
81 |
| } |
82 |
| |
83 |
2069
| protected void replaceChildConfigs(Collection<? extends ConfigurationComponent> oldConfigs,
|
84 |
| Collection<? extends ConfigurationComponent> newConfigs) |
85 |
| { |
86 |
2069
| synchronized (children)
|
87 |
| { |
88 |
2069
| removeChildConfigs(oldConfigs);
|
89 |
2069
| addChildConfigs(newConfigs);
|
90 |
| } |
91 |
| } |
92 |
| |
93 |
| |
94 |
| |
95 |
| |
96 |
| |
97 |
| |
98 |
97365
| protected void testImmutability(String fieldName)
|
99 |
| { |
100 |
97365
| try
|
101 |
| { |
102 |
97365
| if (cache != null && cache.isStarted() && !getClass().getDeclaredField(fieldName).isAnnotationPresent(Dynamic.class))
|
103 |
| { |
104 |
2
| throw new ConfigurationException("Attempted to modify a non-Dynamic configuration element [" + fieldName + "] after the cache has started!");
|
105 |
| } |
106 |
| } |
107 |
| catch (NoSuchFieldException e) |
108 |
| { |
109 |
0
| log.warn("Field " + fieldName + " not found!!");
|
110 |
| } |
111 |
| } |
112 |
| |
113 |
0
| protected CacheImpl getTreeCache()
|
114 |
| { |
115 |
0
| return cache;
|
116 |
| } |
117 |
| |
118 |
| |
119 |
| |
120 |
| |
121 |
| |
122 |
| |
123 |
24104
| public void setCacheImpl(CacheImpl cache)
|
124 |
| { |
125 |
24104
| this.cache = cache;
|
126 |
24104
| synchronized (children)
|
127 |
| { |
128 |
24104
| for (ConfigurationComponent child : children)
|
129 |
| { |
130 |
5186
| child.setCacheImpl(cache);
|
131 |
| } |
132 |
| } |
133 |
| } |
134 |
| |
135 |
48
| public ConfigurationComponent clone() throws CloneNotSupportedException
|
136 |
| { |
137 |
48
| ConfigurationComponent c = (ConfigurationComponent) super.clone();
|
138 |
48
| c.setCacheImpl(null);
|
139 |
48
| return c;
|
140 |
| } |
141 |
| |
142 |
| |
143 |
| |
144 |
| |
145 |
| |
146 |
| |
147 |
42
| protected static boolean safeEquals(Object a, Object b)
|
148 |
| { |
149 |
42
| return (a == b) || (a != null && a.equals(b));
|
150 |
| } |
151 |
| } |