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 private static final Map POOL_EXHAUSTED_ACTIONS = new CaseInsensitiveMap()
103 {
104 private static final long serialVersionUID = 1L;
105
106
107 {
108
109
110
111 Integer value = new Integer(ObjectPool.WHEN_EXHAUSTED_WAIT);
112 this.put("WHEN_EXHAUSTED_WAIT", value);
113 this.put("WAIT", value);
114
115 this.put("BLOCK", value);
116
117 value = new Integer(ObjectPool.WHEN_EXHAUSTED_FAIL);
118 this.put("WHEN_EXHAUSTED_FAIL", value);
119 this.put("FAIL", value);
120
121 value = new Integer(ObjectPool.WHEN_EXHAUSTED_GROW);
122 this.put("WHEN_EXHAUSTED_GROW", value);
123 this.put("GROW", value);
124 }
125 };
126
127
128 private static final Map POOL_INITIALISATION_POLICIES = new CaseInsensitiveMap()
129 {
130 private static final long serialVersionUID = 1L;
131
132
133 {
134 Integer value = new Integer(INITIALISE_NONE);
135 this.put("INITIALISE_NONE", value);
136
137 value = new Integer(INITIALISE_ONE);
138 this.put("INITIALISE_ONE", value);
139
140 this.put("INITIALISE_FIRST", value);
141
142 value = new Integer(INITIALISE_ALL);
143 this.put("INITIALISE_ALL", value);
144 }
145 };
146
147 private int maxActive = DEFAULT_MAX_POOL_ACTIVE;
148
149 private int maxIdle = DEFAULT_MAX_POOL_IDLE;
150
151 private long maxWait = DEFAULT_MAX_POOL_WAIT;
152
153 private int exhaustedAction = DEFAULT_POOL_EXHAUSTED_ACTION;
154
155 private int initialisationPolicy = DEFAULT_POOL_INITIALISATION_POLICY;
156
157 private UMOPoolFactory poolFactory = new CommonsPoolFactory();
158
159 public PoolingProfile()
160 {
161 super();
162 }
163
164 public PoolingProfile(PoolingProfile pp)
165 {
166 this.maxActive = pp.getMaxActive();
167 this.maxIdle = pp.getMaxIdle();
168 this.maxWait = pp.getMaxWait();
169 this.exhaustedAction = pp.getExhaustedAction();
170 this.initialisationPolicy = pp.getInitialisationPolicy();
171 if (pp.getPoolFactory() != null)
172 {
173 poolFactory = pp.getPoolFactory();
174 }
175 }
176
177 public PoolingProfile(int maxActive,
178 int maxIdle,
179 long maxWait,
180 int exhaustedAction,
181 int initialisationPolicy)
182 {
183 this.maxActive = maxActive;
184 this.maxIdle = maxIdle;
185 this.maxWait = maxWait;
186 this.exhaustedAction = exhaustedAction;
187 this.initialisationPolicy = initialisationPolicy;
188 }
189
190
191
192
193 public int getMaxIdle()
194 {
195 return maxIdle;
196 }
197
198
199
200
201 public int getMaxActive()
202 {
203 return maxActive;
204 }
205
206
207
208
209
210
211 public long getMaxWait()
212 {
213 return maxWait;
214 }
215
216
217
218
219 public int getExhaustedAction()
220 {
221 return exhaustedAction;
222 }
223
224 public int getInitialisationPolicy()
225 {
226 return initialisationPolicy;
227 }
228
229 public void setInitialisationPolicy(int policy)
230 {
231 initialisationPolicy = policy;
232 }
233
234 public void setMaxIdle(int maxIdle)
235 {
236 this.maxIdle = maxIdle;
237 }
238
239 public void setMaxActive(int maxActive)
240 {
241 this.maxActive = maxActive;
242 }
243
244 public void setMaxWait(long maxWait)
245 {
246 this.maxWait = maxWait;
247 }
248
249 public void setExhaustedAction(int exhaustedAction)
250 {
251 this.exhaustedAction = exhaustedAction;
252 }
253
254 public void setExhaustedActionString(String poolExhaustedAction)
255 {
256 this.exhaustedAction = MapUtils.getIntValue(POOL_EXHAUSTED_ACTIONS, poolExhaustedAction,
257 ObjectPool.DEFAULT_EXHAUSTED_ACTION);
258 }
259
260 public void setInitialisationPolicyString(String policy)
261 {
262 this.initialisationPolicy = MapUtils.getIntValue(POOL_INITIALISATION_POLICIES, policy,
263 DEFAULT_POOL_INITIALISATION_POLICY);
264 }
265
266 public UMOPoolFactory getPoolFactory()
267 {
268 return poolFactory;
269 }
270
271 public void setPoolFactory(UMOPoolFactory poolFactory)
272 {
273 this.poolFactory = poolFactory;
274 }
275
276 }