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