1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 package org.apache.commons.pool.impl; 19 20 import org.apache.commons.pool.ObjectPool; 21 import org.apache.commons.pool.ObjectPoolFactory; 22 import org.apache.commons.pool.PoolableObjectFactory; 23 24 /** 25 * A factory for creating {@link StackObjectPool} instances. 26 * 27 * @see StackObjectPool 28 * @see StackKeyedObjectPoolFactory 29 * 30 * @author Rodney Waldhoff 31 * @version $Revision: 960705 $ $Date: 2010-07-05 14:19:10 -0700 (Mon, 05 Jul 2010) $ 32 * @since Pool 1.0 33 */ 34 public class StackObjectPoolFactory implements ObjectPoolFactory { 35 /** 36 * Create a new StackObjectPoolFactory. 37 * 38 * @see StackObjectPool#StackObjectPool() 39 * @deprecated to be removed in pool 2.0 - use {@link #StackObjectPoolFactory(PoolableObjectFactory)} 40 */ 41 public StackObjectPoolFactory() { 42 this((PoolableObjectFactory)null,StackObjectPool.DEFAULT_MAX_SLEEPING,StackObjectPool.DEFAULT_INIT_SLEEPING_CAPACITY); 43 } 44 45 /** 46 * Create a new StackObjectPoolFactory. 47 * 48 * @param maxIdle cap on the number of "sleeping" instances in the pool. 49 * @see StackObjectPool#StackObjectPool(int) 50 * @deprecated to be removed in pool 2.0 - use {@link #StackObjectPoolFactory(PoolableObjectFactory, int)} 51 */ 52 public StackObjectPoolFactory(int maxIdle) { 53 this((PoolableObjectFactory)null,maxIdle,StackObjectPool.DEFAULT_INIT_SLEEPING_CAPACITY); 54 } 55 56 /** 57 * Create a new StackObjectPoolFactory. 58 * 59 * @param maxIdle cap on the number of "sleeping" instances in the pool. 60 * @param initIdleCapacity - initial size of the pool (this specifies the size of the container, 61 * it does not cause the pool to be pre-populated.) 62 * @see StackObjectPool#StackObjectPool(int, int) 63 * @deprecated to be removed in pool 2.0 - use {@link #StackObjectPoolFactory(PoolableObjectFactory, int, int)} 64 */ 65 public StackObjectPoolFactory(int maxIdle, int initIdleCapacity) { 66 this((PoolableObjectFactory)null,maxIdle,initIdleCapacity); 67 } 68 69 /** 70 * Create a new StackObjectPoolFactory. 71 * 72 * @param factory the PoolableObjectFactory used by created pools. 73 * @see StackObjectPool#StackObjectPool(PoolableObjectFactory) 74 */ 75 public StackObjectPoolFactory(PoolableObjectFactory factory) { 76 this(factory,StackObjectPool.DEFAULT_MAX_SLEEPING,StackObjectPool.DEFAULT_INIT_SLEEPING_CAPACITY); 77 } 78 79 /** 80 * Create a new StackObjectPoolFactory. 81 * 82 * @param factory the PoolableObjectFactory used by created pools. 83 * @param maxIdle cap on the number of "sleeping" instances in the pool. 84 */ 85 public StackObjectPoolFactory(PoolableObjectFactory factory, int maxIdle) { 86 this(factory,maxIdle,StackObjectPool.DEFAULT_INIT_SLEEPING_CAPACITY); 87 } 88 89 /** 90 * Create a new StackObjectPoolFactory. 91 * 92 * @param factory the PoolableObjectFactory used by created pools. 93 * @param maxIdle cap on the number of "sleeping" instances in the pool. 94 * @param initIdleCapacity - initial size of the pool (this specifies the size of the container, 95 * it does not cause the pool to be pre-populated.) 96 */ 97 public StackObjectPoolFactory(PoolableObjectFactory factory, int maxIdle, int initIdleCapacity) { 98 _factory = factory; 99 _maxSleeping = maxIdle; 100 _initCapacity = initIdleCapacity; 101 } 102 103 /** 104 * Create a StackObjectPool. 105 * 106 * @return a new StackObjectPool with the configured factory, maxIdle and initial capacity settings 107 */ 108 public ObjectPool createPool() { 109 return new StackObjectPool(_factory,_maxSleeping,_initCapacity); 110 } 111 112 /** 113 * The PoolableObjectFactory used by created pools. 114 * @deprecated to be made private in pool 2.0 115 */ 116 protected PoolableObjectFactory _factory = null; 117 118 /** 119 * The maximum number of idle instances in created pools. 120 * @deprecated to be made private in pool 2.0 121 */ 122 protected int _maxSleeping = StackObjectPool.DEFAULT_MAX_SLEEPING; 123 124 /** 125 * The initial size of created pools. 126 * @deprecated to be made private in pool 2.0 127 */ 128 protected int _initCapacity = StackObjectPool.DEFAULT_INIT_SLEEPING_CAPACITY; 129 130 /** 131 * Returns the factory used by created pools. 132 * 133 * @return the PoolableObjectFactory used by created pools 134 * @since 1.5.5 135 */ 136 public PoolableObjectFactory getFactory() { 137 return _factory; 138 } 139 140 /** 141 * Returns the maxIdle setting for created pools. 142 * 143 * @return the maximum number of idle instances in created pools 144 * @since 1.5.5 145 */ 146 public int getMaxSleeping() { 147 return _maxSleeping; 148 } 149 150 /** 151 * Returns the initial capacity of created pools. 152 * 153 * @return size of created containers (created pools are not pre-populated) 154 * @since 1.5.5 155 */ 156 public int getInitCapacity() { 157 return _initCapacity; 158 } 159 160 }