View Javadoc

1   /*
2    * $Id: ConfigurableKeyedObjectPool.java 19251 2010-08-30 17:53:17Z pablo.kraan $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.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.transport;
12  
13  import org.apache.commons.pool.KeyedObjectPool;
14  
15  /**
16   * A configurable {@link KeyedObjectPool}. Extracted from
17   * {@link org.apache.commons.pool.impl.GenericKeyedObjectPool}.
18   */
19  public interface ConfigurableKeyedObjectPool extends KeyedObjectPool
20  {
21  
22      byte WHEN_EXHAUSTED_FAIL = 0;
23      byte WHEN_EXHAUSTED_BLOCK = 1;
24      byte WHEN_EXHAUSTED_GROW = 2;
25  
26      /**
27       * Clears the pool, removing all pooled instances.
28       */
29      void clear();
30  
31      /**
32       * Returns the overall maximum number of objects (across pools) that can
33       * exist at one time. A negative value indicates no limit.
34       */
35      int getMaxTotal();
36  
37      /**
38       * Sets the cap on the total number of instances from all pools combined.
39       *
40       * @param maxTotal The cap on the total number of instances across pools.
41       *                 Use a negative value for no limit.
42       */
43      void setMaxTotal(int maxTotal);
44  
45      /**
46       * Returns the cap on the number of active instances per key.
47       * A negative value indicates no limit.
48       */
49      int getMaxActive();
50  
51      /**
52       * Sets the cap on the number of active instances per key.
53       *
54       * @param maxActive The cap on the number of active instances per key.
55       *                  Use a negative value for no limit.
56       */
57      void setMaxActive(int maxActive);
58  
59      /**
60       * Returns the maximum amount of time (in milliseconds) the
61       * {@link #borrowObject} method should block before throwing
62       * an exception when the pool is exhausted and the
63       * {@link #setWhenExhaustedAction "when exhausted" action} is
64       * {@link #WHEN_EXHAUSTED_BLOCK}.
65       * <p/>
66       * When less than or equal to 0, the {@link #borrowObject} method
67       * may block indefinitely.
68       */
69      long getMaxWait();
70  
71      /**
72       * Sets the maximum amount of time (in milliseconds) the
73       * {@link #borrowObject} method should block before throwing
74       * an exception when the pool is exhausted and the
75       * {@link #setWhenExhaustedAction "when exhausted" action} is
76       * {@link #WHEN_EXHAUSTED_BLOCK}.
77       * <p/>
78       * When less than or equal to 0, the {@link #borrowObject} method
79       * may block indefinitely.
80       *
81       * @param maxWait the maximum number of milliseconds borrowObject will block or negative for indefinitely.
82       */
83      void setMaxWait(long maxWait);
84  
85      /**
86       * Returns the cap on the number of "idle" instances per key.
87       */
88      int getMaxIdle();
89  
90      /**
91       * Sets the cap on the number of "idle" instances in the pool.
92       *
93       * @param maxIdle the maximum number of "idle" instances that can be held
94       *                in a given keyed pool. Use a negative value for no limit.
95       */
96      void setMaxIdle(int maxIdle);
97  
98      /**
99       * Sets the action to take when the {@link #borrowObject} method
100      * is invoked when the pool is exhausted.
101      *
102      * @param whenExhaustedAction the action code, which must be one of
103      *                            {@link #WHEN_EXHAUSTED_BLOCK}, {@link #WHEN_EXHAUSTED_FAIL},
104      *                            or {@link #WHEN_EXHAUSTED_GROW}
105      */
106     void setWhenExhaustedAction(byte whenExhaustedAction);
107 
108     /**
109      * Returns the action to take when the {@link #borrowObject} method
110      * is invoked when the pool is exhausted.
111      *
112      * @return one of {@link #WHEN_EXHAUSTED_BLOCK},
113      *         {@link #WHEN_EXHAUSTED_FAIL} or {@link #WHEN_EXHAUSTED_GROW}
114      */
115     byte getWhenExhaustedAction();
116 }