001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017
018 package org.apache.commons.pool.impl;
019
020 import org.apache.commons.pool.ObjectPool;
021 import org.apache.commons.pool.ObjectPoolFactory;
022 import org.apache.commons.pool.PoolableObjectFactory;
023
024 /**
025 * A factory for creating {@link StackObjectPool} instances.
026 *
027 * @see StackObjectPool
028 * @see StackKeyedObjectPoolFactory
029 *
030 * @author Rodney Waldhoff
031 * @version $Revision: 777748 $ $Date: 2009-05-22 20:00:44 -0400 (Fri, 22 May 2009) $
032 * @since Pool 1.0
033 */
034 public class StackObjectPoolFactory implements ObjectPoolFactory {
035 /**
036 * Create a new StackObjectPoolFactory.
037 *
038 * @see StackObjectPool#StackObjectPool()
039 */
040 public StackObjectPoolFactory() {
041 this((PoolableObjectFactory)null,StackObjectPool.DEFAULT_MAX_SLEEPING,StackObjectPool.DEFAULT_INIT_SLEEPING_CAPACITY);
042 }
043
044 /**
045 * Create a new StackObjectPoolFactory.
046 *
047 * @param maxIdle cap on the number of "sleeping" instances in the pool.
048 * @see StackObjectPool#StackObjectPool(int)
049 */
050 public StackObjectPoolFactory(int maxIdle) {
051 this((PoolableObjectFactory)null,maxIdle,StackObjectPool.DEFAULT_INIT_SLEEPING_CAPACITY);
052 }
053
054 /**
055 * Create a new StackObjectPoolFactory.
056 *
057 * @param maxIdle cap on the number of "sleeping" instances in the pool.
058 * @param initIdleCapacity - initial size of the pool (this specifies the size of the container, it does not cause the pool to be pre-populated.)
059 * @see StackObjectPool#StackObjectPool(int, int)
060 */
061 public StackObjectPoolFactory(int maxIdle, int initIdleCapacity) {
062 this((PoolableObjectFactory)null,maxIdle,initIdleCapacity);
063 }
064
065 /**
066 * Create a new StackObjectPoolFactory.
067 *
068 * @param factory the PoolableObjectFactory used by created pools.
069 * @see StackObjectPool#StackObjectPool(PoolableObjectFactory)
070 */
071 public StackObjectPoolFactory(PoolableObjectFactory factory) {
072 this(factory,StackObjectPool.DEFAULT_MAX_SLEEPING,StackObjectPool.DEFAULT_INIT_SLEEPING_CAPACITY);
073 }
074
075 /**
076 * Create a new StackObjectPoolFactory.
077 *
078 * @param factory the PoolableObjectFactory used by created pools.
079 * @param maxIdle cap on the number of "sleeping" instances in the pool.
080 */
081 public StackObjectPoolFactory(PoolableObjectFactory factory, int maxIdle) {
082 this(factory,maxIdle,StackObjectPool.DEFAULT_INIT_SLEEPING_CAPACITY);
083 }
084
085 /**
086 * Create a new StackObjectPoolFactory.
087 *
088 * @param factory the PoolableObjectFactory used by created pools.
089 * @param maxIdle cap on the number of "sleeping" instances in the pool.
090 * @param initIdleCapacity - initial size of the pool (this specifies the size of the container, it does not cause the pool to be pre-populated.)
091 */
092 public StackObjectPoolFactory(PoolableObjectFactory factory, int maxIdle, int initIdleCapacity) {
093 _factory = factory;
094 _maxSleeping = maxIdle;
095 _initCapacity = initIdleCapacity;
096 }
097
098 public ObjectPool createPool() {
099 return new StackObjectPool(_factory,_maxSleeping,_initCapacity);
100 }
101
102 protected PoolableObjectFactory _factory = null;
103 protected int _maxSleeping = StackObjectPool.DEFAULT_MAX_SLEEPING;
104 protected int _initCapacity = StackObjectPool.DEFAULT_INIT_SLEEPING_CAPACITY;
105
106 }