Coverage Report - org.mule.config.PoolingProfile
 
Classes in this File Line Coverage Branch Coverage Complexity
PoolingProfile
0%
0/48
0%
0/1
1.059
PoolingProfile$1
0%
0/12
N/A
1.059
PoolingProfile$2
0%
0/9
N/A
1.059
 
 1  
 /*
 2  
  * $Id: PoolingProfile.java 7976 2007-08-21 14:26:13Z dirk.olmes $
 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 CPAL v1.0
 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.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  
  * <code>PoolingProfile</code> is a configuration object used to define the object
 24  
  * pooling parameters for the component it is associated with.
 25  
  */
 26  
 
 27  
 public class PoolingProfile
 28  
 {
 29  
 
 30  
     /**
 31  
      * Tells the object pool not to initialise any components on startup.
 32  
      */
 33  
     public static final int INITIALISE_NONE = 0;
 34  
     /** @deprecated use INITIALISE_NONE instead */
 35  
     public static final int POOL_INITIALISE_NO_COMPONENTS = INITIALISE_NONE;
 36  
 
 37  
     /**
 38  
      * Tells the object pool only to initialise one component on startup.
 39  
      */
 40  
     public static final int INITIALISE_ONE = 1;
 41  
     /** @deprecated use INITIALISE_ONE instead */
 42  
     public static final int POOL_INITIALISE_ONE_COMPONENT = INITIALISE_ONE;
 43  
 
 44  
     /**
 45  
      * Tells the object pool to initialise all components on startup.
 46  
      */
 47  
     public static final int INITIALISE_ALL = 2;
 48  
     /** @deprecated use INITIALISE_ALL instead */
 49  
     public static final int POOL_INITIALISE_ALL_COMPONENTS = INITIALISE_ALL;
 50  
 
 51  
     /**
 52  
      * Controls the maximum number of Mule UMOs that can be borrowed from a component
 53  
      * pool at one time. When non-positive, there is no limit to the number of
 54  
      * components that may be active at one time. When maxActive is exceeded, the
 55  
      * pool is said to be exhausted. You can specify this value on the descriptor
 56  
      * declaration. If none is set this value will be used.
 57  
      */
 58  
     public static final int DEFAULT_MAX_POOL_ACTIVE = ObjectPool.DEFAULT_MAX_SIZE;
 59  
 
 60  
     /**
 61  
      * Controls the maximum number of Mule UMOs that can sit idle in the pool at any
 62  
      * time. When non-positive, there is no limit to the number of Mule UMOs that may
 63  
      * be idle at one time. You can specify this value on the descriptor declaration.
 64  
      * If none is set this value will be used. If this value is not set then a system
 65  
      * default of '5' will be used.
 66  
      */
 67  
     public static final int DEFAULT_MAX_POOL_IDLE = ObjectPool.DEFAULT_MAX_SIZE;
 68  
 
 69  
     /**
 70  
      * When the threadPoolExhaustedAction is set to WHEN_EXHAUSTED_WAIT this can
 71  
      * specify the maximum milliseconds the pool should block before throwing a
 72  
      * NoSuchElementException
 73  
      */
 74  
     public static final long DEFAULT_MAX_POOL_WAIT = ObjectPool.DEFAULT_MAX_WAIT;
 75  
 
 76  
     /**
 77  
      * Specifies the behaviour of the Mule UMO pool when the pool is exhausted:
 78  
      * <ul>
 79  
      * <li>WHEN_EXHAUSTED_FAIL : will throw a NoSuchElementException</li>
 80  
      * <li>WHEN_EXHAUSTED_WAIT : will block (invoke Object.wait(long) until a new or
 81  
      * idle object is available.</li>
 82  
      * <li>WHEN_EXHAUSTED_GROW : will create a new Mule and return it (essentially
 83  
      * making maxActive meaningless).</li>
 84  
      * </ul>
 85  
      * If a positive maxWait value is supplied, it will block for at most that many
 86  
      * milliseconds, after which a NoSuchElementException will be thrown. If maxWait
 87  
      * is non-positive, it will block indefinitely.
 88  
      */
 89  
     public static final int DEFAULT_POOL_EXHAUSTED_ACTION = ObjectPool.WHEN_EXHAUSTED_GROW;
 90  
 
 91  
     /**
 92  
      * Determines how components in a pool should be initialised. The possible values
 93  
      * are:
 94  
      * <ul>
 95  
      * <li>INITIALISE_NONE : Will not load any components in the pool on startup</li>
 96  
      * <li>INITIALISE_ONE : Will load only the first component in the pool on
 97  
      * startup</li>
 98  
      * <li>INITIALISE_ALL : Will load all components in the pool on startup</li>
 99  
      * </ul>
 100  
      */
 101  
     public static final int DEFAULT_POOL_INITIALISATION_POLICY = INITIALISE_ONE;
 102  
 
 103  
     // map pool exhaustion strings to their respective values
 104  0
     private static final Map POOL_EXHAUSTED_ACTIONS = new CaseInsensitiveMap()
 105  
     {
 106  
         private static final long serialVersionUID = 1L;
 107  
 
 108  
         // static initializer
 109  0
         {
 110  
             // if the values were an actual enum in ObjectPool we could iterate
 111  
             // properly.. :/
 112  
 
 113  0
             Integer value = new Integer(ObjectPool.WHEN_EXHAUSTED_WAIT);
 114  0
             this.put("WHEN_EXHAUSTED_WAIT", value);
 115  0
             this.put("WAIT", value);
 116  
             // TODO HH: remove for 2.0 (only keep WAIT)
 117  0
             this.put("BLOCK", value);
 118  
 
 119  0
             value = new Integer(ObjectPool.WHEN_EXHAUSTED_FAIL);
 120  0
             this.put("WHEN_EXHAUSTED_FAIL", value);
 121  0
             this.put("FAIL", value);
 122  
 
 123  0
             value = new Integer(ObjectPool.WHEN_EXHAUSTED_GROW);
 124  0
             this.put("WHEN_EXHAUSTED_GROW", value);
 125  0
             this.put("GROW", value);
 126  0
         }
 127  
     };
 128  
 
 129  
     // map pool initialisation policy strings to their respective values
 130  0
     private static final Map POOL_INITIALISATION_POLICIES = new CaseInsensitiveMap()
 131  
     {
 132  
         private static final long serialVersionUID = 1L;
 133  
 
 134  
         // static initializer
 135  0
         {
 136  0
             Integer value = new Integer(INITIALISE_NONE);
 137  0
             this.put("INITIALISE_NONE", value);
 138  
 
 139  0
             value = new Integer(INITIALISE_ONE);
 140  0
             this.put("INITIALISE_ONE", value);
 141  
             // TODO HH: remove for 2.0 (only keep INITIALISE_ONE)
 142  0
             this.put("INITIALISE_FIRST", value);
 143  
 
 144  0
             value = new Integer(INITIALISE_ALL);
 145  0
             this.put("INITIALISE_ALL", value);
 146  0
         }
 147  
     };
 148  
 
 149  0
     private int maxActive = DEFAULT_MAX_POOL_ACTIVE;
 150  
 
 151  0
     private int maxIdle = DEFAULT_MAX_POOL_IDLE;
 152  
 
 153  0
     private long maxWait = DEFAULT_MAX_POOL_WAIT;
 154  
 
 155  0
     private int exhaustedAction = DEFAULT_POOL_EXHAUSTED_ACTION;
 156  
 
 157  0
     private int initialisationPolicy = DEFAULT_POOL_INITIALISATION_POLICY;
 158  
 
 159  0
     private UMOPoolFactory poolFactory = new CommonsPoolFactory();
 160  
 
 161  
     public PoolingProfile()
 162  
     {
 163  0
         super();
 164  0
     }
 165  
 
 166  
     public PoolingProfile(PoolingProfile pp)
 167  0
     {
 168  0
         this.maxActive = pp.getMaxActive();
 169  0
         this.maxIdle = pp.getMaxIdle();
 170  0
         this.maxWait = pp.getMaxWait();
 171  0
         this.exhaustedAction = pp.getExhaustedAction();
 172  0
         this.initialisationPolicy = pp.getInitialisationPolicy();
 173  0
         if (pp.getPoolFactory() != null)
 174  
         {
 175  0
             poolFactory = pp.getPoolFactory();
 176  
         }
 177  0
     }
 178  
 
 179  
     public PoolingProfile(int maxActive,
 180  
                           int maxIdle,
 181  
                           long maxWait,
 182  
                           int exhaustedAction,
 183  
                           int initialisationPolicy)
 184  0
     {
 185  0
         this.maxActive = maxActive;
 186  0
         this.maxIdle = maxIdle;
 187  0
         this.maxWait = maxWait;
 188  0
         this.exhaustedAction = exhaustedAction;
 189  0
         this.initialisationPolicy = initialisationPolicy;
 190  0
     }
 191  
 
 192  
     /**
 193  
      * @return max number of Mule UMOs that can be idle in a component
 194  
      */
 195  
     public int getMaxIdle()
 196  
     {
 197  0
         return maxIdle;
 198  
     }
 199  
 
 200  
     /**
 201  
      * @return max number of Mule UMOs that can be active in a component
 202  
      */
 203  
     public int getMaxActive()
 204  
     {
 205  0
         return maxActive;
 206  
     }
 207  
 
 208  
     /**
 209  
      * @return time in miilisconds to wait for a Mule UMO to be available in a
 210  
      *         component when the pool of Mule UMOs is exhausted and the
 211  
      *         PoolExhaustedAction is set to WHEN_EXHAUSTED_BLOCK
 212  
      */
 213  
     public long getMaxWait()
 214  
     {
 215  0
         return maxWait;
 216  
     }
 217  
 
 218  
     /**
 219  
      * @return the action when the Mule UMO pool is exhaused for a component
 220  
      */
 221  
     public int getExhaustedAction()
 222  
     {
 223  0
         return exhaustedAction;
 224  
     }
 225  
 
 226  
     public int getInitialisationPolicy()
 227  
     {
 228  0
         return initialisationPolicy;
 229  
     }
 230  
 
 231  
     public void setInitialisationPolicy(int policy)
 232  
     {
 233  0
         initialisationPolicy = policy;
 234  0
     }
 235  
 
 236  
     public void setMaxIdle(int maxIdle)
 237  
     {
 238  0
         this.maxIdle = maxIdle;
 239  0
     }
 240  
 
 241  
     public void setMaxActive(int maxActive)
 242  
     {
 243  0
         this.maxActive = maxActive;
 244  0
     }
 245  
 
 246  
     public void setMaxWait(long maxWait)
 247  
     {
 248  0
         this.maxWait = maxWait;
 249  0
     }
 250  
 
 251  
     public void setExhaustedAction(int exhaustedAction)
 252  
     {
 253  0
         this.exhaustedAction = exhaustedAction;
 254  0
     }
 255  
 
 256  
     public void setExhaustedActionString(String poolExhaustedAction)
 257  
     {
 258  0
         this.exhaustedAction = MapUtils.getIntValue(POOL_EXHAUSTED_ACTIONS, poolExhaustedAction,
 259  
             ObjectPool.DEFAULT_EXHAUSTED_ACTION);
 260  0
     }
 261  
 
 262  
     public void setInitialisationPolicyString(String policy)
 263  
     {
 264  0
         this.initialisationPolicy = MapUtils.getIntValue(POOL_INITIALISATION_POLICIES, policy,
 265  
             DEFAULT_POOL_INITIALISATION_POLICY);
 266  0
     }
 267  
 
 268  
     public UMOPoolFactory getPoolFactory()
 269  
     {
 270  0
         return poolFactory;
 271  
     }
 272  
 
 273  
     public void setPoolFactory(UMOPoolFactory poolFactory)
 274  
     {
 275  0
         this.poolFactory = poolFactory;
 276  0
     }
 277  
 
 278  
 }