KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > config > PoolingProfile


1 /*
2  * $Id: PoolingProfile.java 3798 2006-11-04 04:07:14Z aperepel $
3  * --------------------------------------------------------------------------------------
4  * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
5  *
6  * The software in this package is published under the terms of the MuleSource MPL
7  * license, a copy of which has been included with this distribution in the
8  * LICENSE.txt file.
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.ObjectPool;
16
17 /**
18  * <code>PoolingProfile</code> is a configuration object used to define the object
19  * pooling parameters for the component it is associated with.
20  *
21  * @author <a HREF="mailto:ross.mason@symphonysoft.com">Ross Mason</a>
22  * @version $Revision: 3798 $
23  */

24
25 public class PoolingProfile
26 {
27
28     /**
29      * Tells the object pool not to initialise any components on startup
30      */

31     public static final int POOL_INITIALISE_NO_COMPONENTS = 0;
32
33     /**
34      * Tells the object pool only to initialise one component on startup
35      */

36     public static final int POOL_INITIALISE_ONE_COMPONENT = 1;
37
38     /**
39      * Tells the object pool not to initialise any components on startup
40      */

41     public static final int POOL_INITIALISE_ALL_COMPONENTS = 2;
42
43     /**
44      * Controls the maximum number of Mule UMOs that can be borrowed from a component
45      * pool at one time. When non-positive, there is no limit to the number of
46      * components that may be active at one time. When maxActive is exceeded, the
47      * pool is said to be exhausted. You can specify this value on the descriptor
48      * declaration. If none is set this value will be used.
49      */

50     public static final int DEFAULT_MAX_POOL_ACTIVE = ObjectPool.DEFAULT_MAX_SIZE;
51
52     /**
53      * Controls the maximum number of Mule UMOs that can sit idle in the pool at any
54      * time. When non-positive, there is no limit to the number of Mule UMOs that may
55      * be idle at one time. You can specify this value on the descriptor declaration.
56      * If none is set this value will be used. If this value is not set then a system
57      * default of '5' will be used.
58      */

59     public static final int DEFAULT_MAX_POOL_IDLE = ObjectPool.DEFAULT_MAX_SIZE;
60
61     /**
62      * When the threadPoolExhaustedAction is setto 2 (WHEN_EXHAUSTED_BLOCK) this can
63      * specify the maximum milliseconds the pool should block before throwing a
64      * NoSuchElementException
65      */

66     public static final long DEFAULT_MAX_POOL_WAIT = ObjectPool.DEFAULT_MAX_WAIT;
67
68     /**
69      * Specifies the behaviour of the Mule UMO pool when the pool is exhausted: <p/>
70      * 0 (WHEN_EXHAUSTED_FAIL) : will throw a NoSuchElementException 1
71      * (WHEN_EXHAUSTED_BLOCK): will block (invoke Object.wait(long) until a new or
72      * idle object is available. 2 (WHEN_EXHAUSTED_GROW) : will create a new Mule and
73      * return it(essentially making maxActive meaningless.) <p/> If a positive
74      * maxWait value is supplied, it will block for at most that many milliseconds,
75      * after which a NoSuchElementException will be thrown. If maxThraedWait is
76      * non-positive, it will block indefinitely.
77      */

78     public static final int DEFAULT_POOL_EXHAUSTED_ACTION = ObjectPool.WHEN_EXHAUSTED_GROW;
79
80     /**
81      * Determines how components in a pool should be initialised. the possible values
82      * are -
83      * <ul>
84      * <li>0 (POOL_INIT_NO_COMPONENTs) : Will not load any components in the pool on
85      * startup</li>
86      * <li>1 (POOL_INIT_ONE_COMPONENT) : Will load only the first component in the
87      * pool on startup</li>
88      * <li>2 (POOL_INIT_ALL_COMPONENTS) : Will load all components in the pool on
89      * startup</li>
90      * </ul>
91      */

92     public static final int DEFAULT_POOL_INITIALISATION_POLICY = POOL_INITIALISE_ONE_COMPONENT;
93
94     private int maxActive = DEFAULT_MAX_POOL_ACTIVE;
95
96     private int maxIdle = DEFAULT_MAX_POOL_IDLE;
97
98     private long maxWait = DEFAULT_MAX_POOL_WAIT;
99
100     private int exhaustedAction = DEFAULT_POOL_EXHAUSTED_ACTION;
101
102     private int initialisationPolicy = DEFAULT_POOL_INITIALISATION_POLICY;
103
104     private UMOPoolFactory poolFactory = new CommonsPoolFactory();
105
106     public PoolingProfile()
107     {
108         super();
109     }
110
111     public PoolingProfile(PoolingProfile pp)
112     {
113         this.maxActive = pp.getMaxActive();
114         this.maxIdle = pp.getMaxIdle();
115         this.maxWait = pp.getMaxWait();
116         this.exhaustedAction = pp.getExhaustedAction();
117         this.initialisationPolicy = pp.getInitialisationPolicy();
118         if (pp.getPoolFactory() != null)
119         {
120             poolFactory = pp.getPoolFactory();
121         }
122     }
123
124     public PoolingProfile(int maxActive,
125                           int maxIdle,
126                           long maxWait,
127                           int exhaustedAction,
128                           int initialisationPolicy)
129     {
130         this.maxActive = maxActive;
131         this.maxIdle = maxIdle;
132         this.maxWait = maxWait;
133         this.exhaustedAction = exhaustedAction;
134         this.initialisationPolicy = initialisationPolicy;
135     }
136
137     /**
138      * @return max number of Mule UMOs that can be idle in a component
139      */

140     public int getMaxIdle()
141     {
142         return maxIdle;
143     }
144
145     /**
146      * @return max number of Mule UMOs that can be active in a component
147      */

148     public int getMaxActive()
149     {
150         return maxActive;
151     }
152
153     /**
154      * @return time in miilisconds to wait for a Mule UMO to be available in a
155      * component when the pool of Mule UMOs is exhausted and the
156      * PoolExhaustedAction is set to WHEN_EXHAUSTED_BLOCK
157      */

158     public long getMaxWait()
159     {
160         return maxWait;
161     }
162
163     /**
164      * @return the action when the Mule UMO pool is exhaused for a component
165      */

166     public int getExhaustedAction()
167     {
168         return exhaustedAction;
169     }
170
171     public int getInitialisationPolicy()
172     {
173         return initialisationPolicy;
174     }
175
176     public void setInitialisationPolicy(int policy)
177     {
178         initialisationPolicy = policy;
179     }
180
181     public void setMaxIdle(int maxIdle)
182     {
183         this.maxIdle = maxIdle;
184     }
185
186     public void setMaxActive(int maxActive)
187     {
188         this.maxActive = maxActive;
189     }
190
191     public void setMaxWait(long maxWait)
192     {
193         this.maxWait = maxWait;
194     }
195
196     public void setExhaustedAction(int exhaustedAction)
197     {
198         this.exhaustedAction = exhaustedAction;
199     }
200
201     public void setExhaustedActionString(String JavaDoc poolExhaustedAction)
202     {
203         if (poolExhaustedAction != null)
204         {
205             if ("GROW".equalsIgnoreCase(poolExhaustedAction))
206             {
207                 this.exhaustedAction = ObjectPool.WHEN_EXHAUSTED_GROW;
208             }
209             else if ("BLOCK".equalsIgnoreCase(poolExhaustedAction))
210             {
211                 this.exhaustedAction = ObjectPool.WHEN_EXHAUSTED_BLOCK;
212             }
213             else if ("FAIL".equalsIgnoreCase(poolExhaustedAction))
214             {
215                 this.exhaustedAction = ObjectPool.WHEN_EXHAUSTED_FAIL;
216             }
217             else
218             {
219                 this.exhaustedAction = ObjectPool.DEFAULT_EXHAUSTED_ACTION;
220             }
221         }
222     }
223
224     public void setInitialisationPolicyString(String JavaDoc policy)
225     {
226         if (policy != null)
227         {
228             if ("INITIALISE_NONE".equalsIgnoreCase(policy))
229             {
230                 this.initialisationPolicy = POOL_INITIALISE_NO_COMPONENTS;
231             }
232             else if ("INITIALISE_ALL".equalsIgnoreCase(policy))
233             {
234                 this.initialisationPolicy = POOL_INITIALISE_ALL_COMPONENTS;
235             }
236             else
237             {
238                 this.initialisationPolicy = POOL_INITIALISE_ONE_COMPONENT;
239             }
240         }
241     }
242
243     public UMOPoolFactory getPoolFactory()
244     {
245         return poolFactory;
246     }
247
248     public void setPoolFactory(UMOPoolFactory poolFactory)
249     {
250         this.poolFactory = poolFactory;
251     }
252
253 }
254
Popular Tags