001: /*
002: * Copyright 1999-2004,2006 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.ObjectPool;
020: import org.apache.commons.pool.ObjectPoolFactory;
021: import org.apache.commons.pool.PoolableObjectFactory;
022:
023: /**
024: * A factory for creating {@link GenericObjectPool} instances.
025: *
026: * @see GenericObjectPool
027: * @see ObjectPoolFactory
028: *
029: * @author Rodney Waldhoff
030: * @version $Revision: 390563 $ $Date: 2006-03-31 20:28:14 -0500 (Fri, 31 Mar 2006) $
031: */
032: public class GenericObjectPoolFactory implements ObjectPoolFactory {
033: public GenericObjectPoolFactory(PoolableObjectFactory factory) {
034: this (
035: factory,
036: GenericObjectPool.DEFAULT_MAX_ACTIVE,
037: GenericObjectPool.DEFAULT_WHEN_EXHAUSTED_ACTION,
038: GenericObjectPool.DEFAULT_MAX_WAIT,
039: GenericObjectPool.DEFAULT_MAX_IDLE,
040: GenericObjectPool.DEFAULT_MIN_IDLE,
041: GenericObjectPool.DEFAULT_TEST_ON_BORROW,
042: GenericObjectPool.DEFAULT_TEST_ON_RETURN,
043: GenericObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,
044: GenericObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN,
045: GenericObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,
046: GenericObjectPool.DEFAULT_TEST_WHILE_IDLE);
047: }
048:
049: public GenericObjectPoolFactory(PoolableObjectFactory factory,
050: GenericObjectPool.Config config) {
051: this (factory, config.maxActive, config.whenExhaustedAction,
052: config.maxWait, config.maxIdle, config.minIdle,
053: config.testOnBorrow, config.testOnReturn,
054: config.timeBetweenEvictionRunsMillis,
055: config.numTestsPerEvictionRun,
056: config.minEvictableIdleTimeMillis,
057: config.testWhileIdle,
058: config.softMinEvictableIdleTimeMillis);
059: }
060:
061: public GenericObjectPoolFactory(PoolableObjectFactory factory,
062: int maxActive) {
063: this (
064: factory,
065: maxActive,
066: GenericObjectPool.DEFAULT_WHEN_EXHAUSTED_ACTION,
067: GenericObjectPool.DEFAULT_MAX_WAIT,
068: GenericObjectPool.DEFAULT_MAX_IDLE,
069: GenericObjectPool.DEFAULT_MIN_IDLE,
070: GenericObjectPool.DEFAULT_TEST_ON_BORROW,
071: GenericObjectPool.DEFAULT_TEST_ON_RETURN,
072: GenericObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,
073: GenericObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN,
074: GenericObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,
075: GenericObjectPool.DEFAULT_TEST_WHILE_IDLE);
076: }
077:
078: public GenericObjectPoolFactory(PoolableObjectFactory factory,
079: int maxActive, byte whenExhaustedAction, long maxWait) {
080: this (
081: factory,
082: maxActive,
083: whenExhaustedAction,
084: maxWait,
085: GenericObjectPool.DEFAULT_MAX_IDLE,
086: GenericObjectPool.DEFAULT_MIN_IDLE,
087: GenericObjectPool.DEFAULT_TEST_ON_BORROW,
088: GenericObjectPool.DEFAULT_TEST_ON_RETURN,
089: GenericObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,
090: GenericObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN,
091: GenericObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,
092: GenericObjectPool.DEFAULT_TEST_WHILE_IDLE);
093: }
094:
095: public GenericObjectPoolFactory(PoolableObjectFactory factory,
096: int maxActive, byte whenExhaustedAction, long maxWait,
097: boolean testOnBorrow, boolean testOnReturn) {
098: this (
099: factory,
100: maxActive,
101: whenExhaustedAction,
102: maxWait,
103: GenericObjectPool.DEFAULT_MAX_IDLE,
104: GenericObjectPool.DEFAULT_MIN_IDLE,
105: testOnBorrow,
106: testOnReturn,
107: GenericObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,
108: GenericObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN,
109: GenericObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,
110: GenericObjectPool.DEFAULT_TEST_WHILE_IDLE);
111: }
112:
113: public GenericObjectPoolFactory(PoolableObjectFactory factory,
114: int maxActive, byte whenExhaustedAction, long maxWait,
115: int maxIdle) {
116: this (
117: factory,
118: maxActive,
119: whenExhaustedAction,
120: maxWait,
121: maxIdle,
122: GenericObjectPool.DEFAULT_MIN_IDLE,
123: GenericObjectPool.DEFAULT_TEST_ON_BORROW,
124: GenericObjectPool.DEFAULT_TEST_ON_RETURN,
125: GenericObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,
126: GenericObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN,
127: GenericObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,
128: GenericObjectPool.DEFAULT_TEST_WHILE_IDLE);
129: }
130:
131: public GenericObjectPoolFactory(PoolableObjectFactory factory,
132: int maxActive, byte whenExhaustedAction, long maxWait,
133: int maxIdle, boolean testOnBorrow, boolean testOnReturn) {
134: this (
135: factory,
136: maxActive,
137: whenExhaustedAction,
138: maxWait,
139: maxIdle,
140: GenericObjectPool.DEFAULT_MIN_IDLE,
141: testOnBorrow,
142: testOnReturn,
143: GenericObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,
144: GenericObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN,
145: GenericObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,
146: GenericObjectPool.DEFAULT_TEST_WHILE_IDLE);
147: }
148:
149: public GenericObjectPoolFactory(PoolableObjectFactory factory,
150: int maxActive, byte whenExhaustedAction, long maxWait,
151: int maxIdle, boolean testOnBorrow, boolean testOnReturn,
152: long timeBetweenEvictionRunsMillis,
153: int numTestsPerEvictionRun,
154: long minEvictableIdleTimeMillis, boolean testWhileIdle) {
155: this (
156: factory,
157: maxActive,
158: whenExhaustedAction,
159: maxWait,
160: maxIdle,
161: GenericObjectPool.DEFAULT_MIN_IDLE,
162: testOnBorrow,
163: testOnReturn,
164: timeBetweenEvictionRunsMillis,
165: numTestsPerEvictionRun,
166: minEvictableIdleTimeMillis,
167: testWhileIdle,
168: GenericObjectPool.DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS);
169: }
170:
171: public GenericObjectPoolFactory(PoolableObjectFactory factory,
172: int maxActive, byte whenExhaustedAction, long maxWait,
173: int maxIdle, int minIdle, boolean testOnBorrow,
174: boolean testOnReturn, long timeBetweenEvictionRunsMillis,
175: int numTestsPerEvictionRun,
176: long minEvictableIdleTimeMillis, boolean testWhileIdle) {
177: this (
178: factory,
179: maxActive,
180: whenExhaustedAction,
181: maxWait,
182: maxIdle,
183: minIdle,
184: testOnBorrow,
185: testOnReturn,
186: timeBetweenEvictionRunsMillis,
187: numTestsPerEvictionRun,
188: minEvictableIdleTimeMillis,
189: testWhileIdle,
190: GenericObjectPool.DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS);
191: }
192:
193: public GenericObjectPoolFactory(PoolableObjectFactory factory,
194: int maxActive, byte whenExhaustedAction, long maxWait,
195: int maxIdle, int minIdle, boolean testOnBorrow,
196: boolean testOnReturn, long timeBetweenEvictionRunsMillis,
197: int numTestsPerEvictionRun,
198: long minEvictableIdleTimeMillis, boolean testWhileIdle,
199: long softMinEvictableIdleTimeMillis) {
200: _maxIdle = maxIdle;
201: _minIdle = minIdle;
202: _maxActive = maxActive;
203: _maxWait = maxWait;
204: _whenExhaustedAction = whenExhaustedAction;
205: _testOnBorrow = testOnBorrow;
206: _testOnReturn = testOnReturn;
207: _testWhileIdle = testWhileIdle;
208: _timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis;
209: _numTestsPerEvictionRun = numTestsPerEvictionRun;
210: _minEvictableIdleTimeMillis = minEvictableIdleTimeMillis;
211: _softMinEvictableIdleTimeMillis = softMinEvictableIdleTimeMillis;
212: _factory = factory;
213: }
214:
215: public ObjectPool createPool() {
216: return new GenericObjectPool(_factory, _maxActive,
217: _whenExhaustedAction, _maxWait, _maxIdle, _minIdle,
218: _testOnBorrow, _testOnReturn,
219: _timeBetweenEvictionRunsMillis,
220: _numTestsPerEvictionRun, _minEvictableIdleTimeMillis,
221: _testWhileIdle, _softMinEvictableIdleTimeMillis);
222: }
223:
224: protected int _maxIdle = GenericObjectPool.DEFAULT_MAX_IDLE;
225: protected int _minIdle = GenericObjectPool.DEFAULT_MIN_IDLE;
226: protected int _maxActive = GenericObjectPool.DEFAULT_MAX_ACTIVE;
227: protected long _maxWait = GenericObjectPool.DEFAULT_MAX_WAIT;
228: protected byte _whenExhaustedAction = GenericObjectPool.DEFAULT_WHEN_EXHAUSTED_ACTION;
229: protected boolean _testOnBorrow = GenericObjectPool.DEFAULT_TEST_ON_BORROW;
230: protected boolean _testOnReturn = GenericObjectPool.DEFAULT_TEST_ON_RETURN;
231: protected boolean _testWhileIdle = GenericObjectPool.DEFAULT_TEST_WHILE_IDLE;
232: protected long _timeBetweenEvictionRunsMillis = GenericObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS;
233: protected int _numTestsPerEvictionRun = GenericObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN;
234: protected long _minEvictableIdleTimeMillis = GenericObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS;
235: protected long _softMinEvictableIdleTimeMillis = GenericObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS;
236: protected PoolableObjectFactory _factory = null;
237:
238: }
|