001: /*
002: * Copyright 1999-2004 The Apache Software Foundation.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.apache.commons.pool.impl;
018:
019: import org.apache.commons.pool.KeyedObjectPool;
020: import org.apache.commons.pool.KeyedObjectPoolFactory;
021: import org.apache.commons.pool.KeyedPoolableObjectFactory;
022:
023: /**
024: * A factory for creating {@link GenericKeyedObjectPool} instances.
025: *
026: * @see GenericKeyedObjectPool
027: * @see KeyedObjectPoolFactory
028: *
029: * @author Rodney Waldhoff
030: * @author Dirk Verbeeck
031: * @version $Revision: 390792 $ $Date: 2006-04-02 03:13:42 -0400 (Sun, 02 Apr 2006) $
032: */
033: public class GenericKeyedObjectPoolFactory implements
034: KeyedObjectPoolFactory {
035: public GenericKeyedObjectPoolFactory(
036: KeyedPoolableObjectFactory factory) {
037: this (
038: factory,
039: GenericKeyedObjectPool.DEFAULT_MAX_ACTIVE,
040: GenericKeyedObjectPool.DEFAULT_WHEN_EXHAUSTED_ACTION,
041: GenericKeyedObjectPool.DEFAULT_MAX_WAIT,
042: GenericKeyedObjectPool.DEFAULT_MAX_IDLE,
043: GenericKeyedObjectPool.DEFAULT_TEST_ON_BORROW,
044: GenericKeyedObjectPool.DEFAULT_TEST_ON_RETURN,
045: GenericKeyedObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,
046: GenericKeyedObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN,
047: GenericKeyedObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,
048: GenericKeyedObjectPool.DEFAULT_TEST_WHILE_IDLE);
049: }
050:
051: public GenericKeyedObjectPoolFactory(
052: KeyedPoolableObjectFactory factory,
053: GenericKeyedObjectPool.Config config) {
054: this (factory, config.maxActive, config.whenExhaustedAction,
055: config.maxWait, config.maxIdle, config.testOnBorrow,
056: config.testOnReturn,
057: config.timeBetweenEvictionRunsMillis,
058: config.numTestsPerEvictionRun,
059: config.minEvictableIdleTimeMillis, config.testWhileIdle);
060: }
061:
062: public GenericKeyedObjectPoolFactory(
063: KeyedPoolableObjectFactory factory, int maxActive) {
064: this (
065: factory,
066: maxActive,
067: GenericKeyedObjectPool.DEFAULT_WHEN_EXHAUSTED_ACTION,
068: GenericKeyedObjectPool.DEFAULT_MAX_WAIT,
069: GenericKeyedObjectPool.DEFAULT_MAX_IDLE,
070: GenericKeyedObjectPool.DEFAULT_MAX_TOTAL,
071: GenericKeyedObjectPool.DEFAULT_TEST_ON_BORROW,
072: GenericKeyedObjectPool.DEFAULT_TEST_ON_RETURN,
073: GenericKeyedObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,
074: GenericKeyedObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN,
075: GenericKeyedObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,
076: GenericKeyedObjectPool.DEFAULT_TEST_WHILE_IDLE);
077: }
078:
079: public GenericKeyedObjectPoolFactory(
080: KeyedPoolableObjectFactory factory, int maxActive,
081: byte whenExhaustedAction, long maxWait) {
082: this (
083: factory,
084: maxActive,
085: whenExhaustedAction,
086: maxWait,
087: GenericKeyedObjectPool.DEFAULT_MAX_IDLE,
088: GenericKeyedObjectPool.DEFAULT_MAX_TOTAL,
089: GenericKeyedObjectPool.DEFAULT_TEST_ON_BORROW,
090: GenericKeyedObjectPool.DEFAULT_TEST_ON_RETURN,
091: GenericKeyedObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,
092: GenericKeyedObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN,
093: GenericKeyedObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,
094: GenericKeyedObjectPool.DEFAULT_TEST_WHILE_IDLE);
095: }
096:
097: public GenericKeyedObjectPoolFactory(
098: KeyedPoolableObjectFactory factory, int maxActive,
099: byte whenExhaustedAction, long maxWait,
100: boolean testOnBorrow, boolean testOnReturn) {
101: this (
102: factory,
103: maxActive,
104: whenExhaustedAction,
105: maxWait,
106: GenericKeyedObjectPool.DEFAULT_MAX_IDLE,
107: GenericKeyedObjectPool.DEFAULT_MAX_TOTAL,
108: testOnBorrow,
109: testOnReturn,
110: GenericKeyedObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,
111: GenericKeyedObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN,
112: GenericKeyedObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,
113: GenericKeyedObjectPool.DEFAULT_TEST_WHILE_IDLE);
114: }
115:
116: public GenericKeyedObjectPoolFactory(
117: KeyedPoolableObjectFactory factory, int maxActive,
118: byte whenExhaustedAction, long maxWait, int maxIdle) {
119: this (
120: factory,
121: maxActive,
122: whenExhaustedAction,
123: maxWait,
124: maxIdle,
125: GenericKeyedObjectPool.DEFAULT_MAX_TOTAL,
126: GenericKeyedObjectPool.DEFAULT_TEST_ON_BORROW,
127: GenericKeyedObjectPool.DEFAULT_TEST_ON_RETURN,
128: GenericKeyedObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,
129: GenericKeyedObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN,
130: GenericKeyedObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,
131: GenericKeyedObjectPool.DEFAULT_TEST_WHILE_IDLE);
132: }
133:
134: public GenericKeyedObjectPoolFactory(
135: KeyedPoolableObjectFactory factory, int maxActive,
136: byte whenExhaustedAction, long maxWait, int maxIdle,
137: int maxTotal) {
138: this (
139: factory,
140: maxActive,
141: whenExhaustedAction,
142: maxWait,
143: maxIdle,
144: maxTotal,
145: GenericKeyedObjectPool.DEFAULT_TEST_ON_BORROW,
146: GenericKeyedObjectPool.DEFAULT_TEST_ON_RETURN,
147: GenericKeyedObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,
148: GenericKeyedObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN,
149: GenericKeyedObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,
150: GenericKeyedObjectPool.DEFAULT_TEST_WHILE_IDLE);
151: }
152:
153: public GenericKeyedObjectPoolFactory(
154: KeyedPoolableObjectFactory factory, int maxActive,
155: byte whenExhaustedAction, long maxWait, int maxIdle,
156: boolean testOnBorrow, boolean testOnReturn) {
157: this (
158: factory,
159: maxActive,
160: whenExhaustedAction,
161: maxWait,
162: maxIdle,
163: GenericKeyedObjectPool.DEFAULT_MAX_TOTAL,
164: testOnBorrow,
165: testOnReturn,
166: GenericKeyedObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,
167: GenericKeyedObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN,
168: GenericKeyedObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,
169: GenericKeyedObjectPool.DEFAULT_TEST_WHILE_IDLE);
170: }
171:
172: public GenericKeyedObjectPoolFactory(
173: KeyedPoolableObjectFactory factory, int maxActive,
174: byte whenExhaustedAction, long maxWait, int maxIdle,
175: boolean testOnBorrow, boolean testOnReturn,
176: long timeBetweenEvictionRunsMillis,
177: int numTestsPerEvictionRun,
178: long minEvictableIdleTimeMillis, boolean testWhileIdle) {
179: this (factory, maxActive, whenExhaustedAction, maxWait, maxIdle,
180: GenericKeyedObjectPool.DEFAULT_MAX_TOTAL, testOnBorrow,
181: testOnReturn, timeBetweenEvictionRunsMillis,
182: numTestsPerEvictionRun, minEvictableIdleTimeMillis,
183: testWhileIdle);
184: }
185:
186: public GenericKeyedObjectPoolFactory(
187: KeyedPoolableObjectFactory factory, int maxActive,
188: byte whenExhaustedAction, long maxWait, int maxIdle,
189: int maxTotal, boolean testOnBorrow, boolean testOnReturn,
190: long timeBetweenEvictionRunsMillis,
191: int numTestsPerEvictionRun,
192: long minEvictableIdleTimeMillis, boolean testWhileIdle) {
193: this (factory, maxActive, whenExhaustedAction, maxWait, maxIdle,
194: maxTotal, GenericKeyedObjectPool.DEFAULT_MIN_IDLE,
195: testOnBorrow, testOnReturn,
196: timeBetweenEvictionRunsMillis, numTestsPerEvictionRun,
197: minEvictableIdleTimeMillis, testWhileIdle);
198: }
199:
200: public GenericKeyedObjectPoolFactory(
201: KeyedPoolableObjectFactory factory, int maxActive,
202: byte whenExhaustedAction, long maxWait, int maxIdle,
203: int maxTotal, int minIdle, boolean testOnBorrow,
204: boolean testOnReturn, long timeBetweenEvictionRunsMillis,
205: int numTestsPerEvictionRun,
206: long minEvictableIdleTimeMillis, boolean testWhileIdle) {
207: _maxIdle = maxIdle;
208: _maxActive = maxActive;
209: _maxTotal = maxTotal;
210: _minIdle = minIdle;
211: _maxWait = maxWait;
212: _whenExhaustedAction = whenExhaustedAction;
213: _testOnBorrow = testOnBorrow;
214: _testOnReturn = testOnReturn;
215: _testWhileIdle = testWhileIdle;
216: _timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis;
217: _numTestsPerEvictionRun = numTestsPerEvictionRun;
218: _minEvictableIdleTimeMillis = minEvictableIdleTimeMillis;
219: _factory = factory;
220: }
221:
222: public KeyedObjectPool createPool() {
223: return new GenericKeyedObjectPool(_factory, _maxActive,
224: _whenExhaustedAction, _maxWait, _maxIdle, _maxTotal,
225: _minIdle, _testOnBorrow, _testOnReturn,
226: _timeBetweenEvictionRunsMillis,
227: _numTestsPerEvictionRun, _minEvictableIdleTimeMillis,
228: _testWhileIdle);
229: }
230:
231: //--- protected attributes ---------------------------------------
232:
233: protected int _maxIdle = GenericKeyedObjectPool.DEFAULT_MAX_IDLE;
234: protected int _maxActive = GenericKeyedObjectPool.DEFAULT_MAX_ACTIVE;
235: protected int _maxTotal = GenericKeyedObjectPool.DEFAULT_MAX_TOTAL;
236: protected int _minIdle = GenericKeyedObjectPool.DEFAULT_MIN_IDLE;
237: protected long _maxWait = GenericKeyedObjectPool.DEFAULT_MAX_WAIT;
238: protected byte _whenExhaustedAction = GenericKeyedObjectPool.DEFAULT_WHEN_EXHAUSTED_ACTION;
239: protected boolean _testOnBorrow = GenericKeyedObjectPool.DEFAULT_TEST_ON_BORROW;
240: protected boolean _testOnReturn = GenericKeyedObjectPool.DEFAULT_TEST_ON_RETURN;
241: protected boolean _testWhileIdle = GenericKeyedObjectPool.DEFAULT_TEST_WHILE_IDLE;
242: protected long _timeBetweenEvictionRunsMillis = GenericKeyedObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS;
243: protected int _numTestsPerEvictionRun = GenericKeyedObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN;
244: protected long _minEvictableIdleTimeMillis = GenericKeyedObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS;
245: protected KeyedPoolableObjectFactory _factory = null;
246:
247: }
|