1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.config; |
12 | |
|
13 | |
import org.mule.config.pool.CommonsPoolFactory; |
14 | |
import org.mule.umo.model.UMOPoolFactory; |
15 | |
import org.mule.util.MapUtils; |
16 | |
import org.mule.util.ObjectPool; |
17 | |
|
18 | |
import java.util.Map; |
19 | |
|
20 | |
import org.apache.commons.collections.map.CaseInsensitiveMap; |
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
public class PoolingProfile |
28 | |
{ |
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
public static final int INITIALISE_NONE = 0; |
34 | |
|
35 | |
public static final int POOL_INITIALISE_NO_COMPONENTS = INITIALISE_NONE; |
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
public static final int INITIALISE_ONE = 1; |
41 | |
|
42 | |
public static final int POOL_INITIALISE_ONE_COMPONENT = INITIALISE_ONE; |
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
public static final int INITIALISE_ALL = 2; |
48 | |
|
49 | |
public static final int POOL_INITIALISE_ALL_COMPONENTS = INITIALISE_ALL; |
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
public static final int DEFAULT_MAX_POOL_ACTIVE = ObjectPool.DEFAULT_MAX_SIZE; |
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
public static final int DEFAULT_MAX_POOL_IDLE = ObjectPool.DEFAULT_MAX_SIZE; |
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
public static final long DEFAULT_MAX_POOL_WAIT = ObjectPool.DEFAULT_MAX_WAIT; |
75 | |
|
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
public static final int DEFAULT_POOL_EXHAUSTED_ACTION = ObjectPool.WHEN_EXHAUSTED_GROW; |
90 | |
|
91 | |
|
92 | |
|
93 | |
|
94 | |
|
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
public static final int DEFAULT_POOL_INITIALISATION_POLICY = INITIALISE_ONE; |
100 | |
|
101 | |
|
102 | 2 | private static final Map POOL_EXHAUSTED_ACTIONS = new CaseInsensitiveMap() |
103 | |
{ |
104 | |
private static final long serialVersionUID = 1L; |
105 | |
|
106 | |
|
107 | 2 | { |
108 | |
|
109 | |
|
110 | |
|
111 | 2 | Integer value = new Integer(ObjectPool.WHEN_EXHAUSTED_WAIT); |
112 | 2 | this.put("WHEN_EXHAUSTED_WAIT", value); |
113 | 2 | this.put("WAIT", value); |
114 | |
|
115 | 2 | this.put("BLOCK", value); |
116 | |
|
117 | 2 | value = new Integer(ObjectPool.WHEN_EXHAUSTED_FAIL); |
118 | 2 | this.put("WHEN_EXHAUSTED_FAIL", value); |
119 | 2 | this.put("FAIL", value); |
120 | |
|
121 | 2 | value = new Integer(ObjectPool.WHEN_EXHAUSTED_GROW); |
122 | 2 | this.put("WHEN_EXHAUSTED_GROW", value); |
123 | 2 | this.put("GROW", value); |
124 | 2 | } |
125 | |
}; |
126 | |
|
127 | |
|
128 | 2 | private static final Map POOL_INITIALISATION_POLICIES = new CaseInsensitiveMap() |
129 | |
{ |
130 | |
private static final long serialVersionUID = 1L; |
131 | |
|
132 | |
|
133 | 2 | { |
134 | 2 | Integer value = new Integer(INITIALISE_NONE); |
135 | 2 | this.put("INITIALISE_NONE", value); |
136 | |
|
137 | 2 | value = new Integer(INITIALISE_ONE); |
138 | 2 | this.put("INITIALISE_ONE", value); |
139 | |
|
140 | 2 | this.put("INITIALISE_FIRST", value); |
141 | |
|
142 | 2 | value = new Integer(INITIALISE_ALL); |
143 | 2 | this.put("INITIALISE_ALL", value); |
144 | 2 | } |
145 | |
}; |
146 | |
|
147 | 3566 | private int maxActive = DEFAULT_MAX_POOL_ACTIVE; |
148 | |
|
149 | 3566 | private int maxIdle = DEFAULT_MAX_POOL_IDLE; |
150 | |
|
151 | 3566 | private long maxWait = DEFAULT_MAX_POOL_WAIT; |
152 | |
|
153 | 3566 | private int exhaustedAction = DEFAULT_POOL_EXHAUSTED_ACTION; |
154 | |
|
155 | 3566 | private int initialisationPolicy = DEFAULT_POOL_INITIALISATION_POLICY; |
156 | |
|
157 | 3566 | private UMOPoolFactory poolFactory = new CommonsPoolFactory(); |
158 | |
|
159 | |
public PoolingProfile() |
160 | |
{ |
161 | 3106 | super(); |
162 | 3106 | } |
163 | |
|
164 | |
public PoolingProfile(PoolingProfile pp) |
165 | 460 | { |
166 | 460 | this.maxActive = pp.getMaxActive(); |
167 | 460 | this.maxIdle = pp.getMaxIdle(); |
168 | 460 | this.maxWait = pp.getMaxWait(); |
169 | 460 | this.exhaustedAction = pp.getExhaustedAction(); |
170 | 460 | this.initialisationPolicy = pp.getInitialisationPolicy(); |
171 | 460 | if (pp.getPoolFactory() != null) |
172 | |
{ |
173 | 460 | poolFactory = pp.getPoolFactory(); |
174 | |
} |
175 | 460 | } |
176 | |
|
177 | |
public PoolingProfile(int maxActive, |
178 | |
int maxIdle, |
179 | |
long maxWait, |
180 | |
int exhaustedAction, |
181 | |
int initialisationPolicy) |
182 | 0 | { |
183 | 0 | this.maxActive = maxActive; |
184 | 0 | this.maxIdle = maxIdle; |
185 | 0 | this.maxWait = maxWait; |
186 | 0 | this.exhaustedAction = exhaustedAction; |
187 | 0 | this.initialisationPolicy = initialisationPolicy; |
188 | 0 | } |
189 | |
|
190 | |
|
191 | |
|
192 | |
|
193 | |
public int getMaxIdle() |
194 | |
{ |
195 | 498 | return maxIdle; |
196 | |
} |
197 | |
|
198 | |
|
199 | |
|
200 | |
|
201 | |
public int getMaxActive() |
202 | |
{ |
203 | 532 | return maxActive; |
204 | |
} |
205 | |
|
206 | |
|
207 | |
|
208 | |
|
209 | |
|
210 | |
|
211 | |
public long getMaxWait() |
212 | |
{ |
213 | 498 | return maxWait; |
214 | |
} |
215 | |
|
216 | |
|
217 | |
|
218 | |
|
219 | |
public int getExhaustedAction() |
220 | |
{ |
221 | 494 | return exhaustedAction; |
222 | |
} |
223 | |
|
224 | |
public int getInitialisationPolicy() |
225 | |
{ |
226 | 492 | return initialisationPolicy; |
227 | |
} |
228 | |
|
229 | |
public void setInitialisationPolicy(int policy) |
230 | |
{ |
231 | 44 | initialisationPolicy = policy; |
232 | 44 | } |
233 | |
|
234 | |
public void setMaxIdle(int maxIdle) |
235 | |
{ |
236 | 0 | this.maxIdle = maxIdle; |
237 | 0 | } |
238 | |
|
239 | |
public void setMaxActive(int maxActive) |
240 | |
{ |
241 | 0 | this.maxActive = maxActive; |
242 | 0 | } |
243 | |
|
244 | |
public void setMaxWait(long maxWait) |
245 | |
{ |
246 | 0 | this.maxWait = maxWait; |
247 | 0 | } |
248 | |
|
249 | |
public void setExhaustedAction(int exhaustedAction) |
250 | |
{ |
251 | 0 | this.exhaustedAction = exhaustedAction; |
252 | 0 | } |
253 | |
|
254 | |
public void setExhaustedActionString(String poolExhaustedAction) |
255 | |
{ |
256 | 0 | this.exhaustedAction = MapUtils.getIntValue(POOL_EXHAUSTED_ACTIONS, poolExhaustedAction, |
257 | |
ObjectPool.DEFAULT_EXHAUSTED_ACTION); |
258 | 0 | } |
259 | |
|
260 | |
public void setInitialisationPolicyString(String policy) |
261 | |
{ |
262 | 0 | this.initialisationPolicy = MapUtils.getIntValue(POOL_INITIALISATION_POLICIES, policy, |
263 | |
DEFAULT_POOL_INITIALISATION_POLICY); |
264 | 0 | } |
265 | |
|
266 | |
public UMOPoolFactory getPoolFactory() |
267 | |
{ |
268 | 952 | return poolFactory; |
269 | |
} |
270 | |
|
271 | |
public void setPoolFactory(UMOPoolFactory poolFactory) |
272 | |
{ |
273 | 0 | this.poolFactory = poolFactory; |
274 | 0 | } |
275 | |
|
276 | |
} |