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