View Javadoc

1   /*
2    * $Id: DefaultConfigurableKeyedObjectPool.java 19252 2010-08-30 18:06:30Z 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 java.util.NoSuchElementException;
14  
15  import org.apache.commons.pool.KeyedPoolableObjectFactory;
16  import org.apache.commons.pool.impl.GenericKeyedObjectPool;
17  
18  /**
19   * Implements {@link ConfigurableKeyedObjectPool} as a delegate of a {@link KeyedPoolableObjectFactory}
20   * instance.
21   */
22  public class DefaultConfigurableKeyedObjectPool implements ConfigurableKeyedObjectPool
23  {
24  
25      private final GenericKeyedObjectPool pool;
26  
27      public DefaultConfigurableKeyedObjectPool()
28      {
29          pool = new GenericKeyedObjectPool();
30  
31          // NOTE: testOnBorrow MUST be FALSE. this is a bit of a design bug in
32          // commons-pool since validate is used for both activation and passivation,
33          // but has no way of knowing which way it is going.
34          pool.setTestOnBorrow(false);
35          pool.setTestOnReturn(true);
36      }
37  
38      public Object borrowObject(Object key) throws Exception, NoSuchElementException, IllegalStateException
39      {
40          return pool.borrowObject(key);
41      }
42  
43      public void returnObject(Object key, Object obj) throws Exception
44      {
45          pool.returnObject(key, obj);
46      }
47  
48      public void invalidateObject(Object key, Object obj) throws Exception
49      {
50          pool.invalidateObject(key, obj);
51      }
52  
53      public void addObject(Object key) throws Exception, IllegalStateException, UnsupportedOperationException
54      {
55          pool.addObject(key);
56      }
57  
58      public int getNumIdle(Object key) throws UnsupportedOperationException
59      {
60          return pool.getNumIdle(key);
61      }
62  
63      public int getNumActive(Object key) throws UnsupportedOperationException
64      {
65          return pool.getNumActive(key);
66      }
67  
68      public int getNumIdle() throws UnsupportedOperationException
69      {
70          return pool.getNumIdle();
71      }
72  
73      public int getNumActive() throws UnsupportedOperationException
74      {
75          return pool.getNumActive();
76      }
77  
78      public void clear()
79      {
80          pool.clear();
81      }
82  
83      public void clear(Object key) throws Exception, UnsupportedOperationException
84      {
85          pool.clear(key);
86      }
87  
88      public void close() throws Exception
89      {
90          pool.close();
91      }
92  
93      public void setFactory(KeyedPoolableObjectFactory factory) throws IllegalStateException, UnsupportedOperationException
94      {
95          pool.setFactory(factory);
96      }
97  
98      public int getMaxActive()
99      {
100         return pool.getMaxActive();
101     }
102 
103     public int getMaxTotal()
104     {
105         return pool.getMaxTotal();
106     }
107 
108     public void setMaxWait(long maxWait)
109     {
110         pool.setMaxWait(maxWait);
111     }
112 
113     public void setMaxActive(int maxActive)
114     {
115         pool.setMaxActive(maxActive);
116     }
117 
118     public void setMaxIdle(int maxIdle)
119     {
120         pool.setMaxIdle(maxIdle);
121     }
122 
123     public void setMaxTotal(int maxTotal)
124     {
125         pool.setMaxTotal(maxTotal);
126     }
127 
128     public int getMaxIdle()
129     {
130         return pool.getMaxIdle();
131     }
132 
133     public void setWhenExhaustedAction(byte whenExhaustedAction)
134     {
135         pool.setWhenExhaustedAction(whenExhaustedAction);
136     }
137 
138     public byte getWhenExhaustedAction()
139     {
140         return pool.getWhenExhaustedAction();
141     }
142 
143     public long getMaxWait()
144     {
145         return pool.getMaxWait();
146     }
147 }