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.KeyedObjectPool; 21 import org.apache.commons.pool.KeyedObjectPoolFactory; 22 import org.apache.commons.pool.KeyedPoolableObjectFactory; 23 24 /** 25 * A factory for creating {@link StackKeyedObjectPool} instances. 26 * 27 * @see StackKeyedObjectPool 28 * @see KeyedObjectPoolFactory 29 * 30 * @author Rodney Waldhoff 31 * @version $Revision: 777748 $ $Date: 2009-05-22 20:00:44 -0400 (Fri, 22 May 2009) $ 32 * @since Pool 1.0 33 */ 34 public class StackKeyedObjectPoolFactory implements KeyedObjectPoolFactory { 35 /** 36 * Create a new StackKeyedObjectPoolFactory. 37 * 38 * @see StackKeyedObjectPool#StackKeyedObjectPool() 39 */ 40 public StackKeyedObjectPoolFactory() { 41 this((KeyedPoolableObjectFactory)null,StackKeyedObjectPool.DEFAULT_MAX_SLEEPING,StackKeyedObjectPool.DEFAULT_INIT_SLEEPING_CAPACITY); 42 } 43 44 /** 45 * Create a new StackKeyedObjectPoolFactory. 46 * 47 * @param max cap on the number of "sleeping" instances in the pool. 48 * @see StackKeyedObjectPool#StackKeyedObjectPool(int) 49 */ 50 public StackKeyedObjectPoolFactory(int max) { 51 this((KeyedPoolableObjectFactory)null,max,StackKeyedObjectPool.DEFAULT_INIT_SLEEPING_CAPACITY); 52 } 53 54 /** 55 * Create a new StackKeyedObjectPoolFactory. 56 * 57 * @param max cap on the number of "sleeping" instances in the pool. 58 * @param init initial size of the pool (this specifies the size of the container, it does not cause the pool to be pre-populated.) 59 * @see StackKeyedObjectPool#StackKeyedObjectPool(int, int) 60 */ 61 public StackKeyedObjectPoolFactory(int max, int init) { 62 this((KeyedPoolableObjectFactory)null,max,init); 63 } 64 65 /** 66 * Create a new StackKeyedObjectPoolFactory. 67 * 68 * @param factory the KeyedPoolableObjectFactory used by created pools. 69 * @see StackKeyedObjectPool#StackKeyedObjectPool(KeyedPoolableObjectFactory) 70 */ 71 public StackKeyedObjectPoolFactory(KeyedPoolableObjectFactory factory) { 72 this(factory,StackKeyedObjectPool.DEFAULT_MAX_SLEEPING,StackKeyedObjectPool.DEFAULT_INIT_SLEEPING_CAPACITY); 73 } 74 75 /** 76 * Create a new StackKeyedObjectPoolFactory. 77 * 78 * @param factory the KeyedPoolableObjectFactory used by created pools. 79 * @param max cap on the number of "sleeping" instances in the pool. 80 * @see StackKeyedObjectPool#StackKeyedObjectPool(KeyedPoolableObjectFactory, int) 81 */ 82 public StackKeyedObjectPoolFactory(KeyedPoolableObjectFactory factory, int max) { 83 this(factory,max,StackKeyedObjectPool.DEFAULT_INIT_SLEEPING_CAPACITY); 84 } 85 86 /** 87 * Create a new StackKeyedObjectPoolFactory. 88 * 89 * @param factory the KeyedPoolableObjectFactory used by created pools. 90 * @param max cap on the number of "sleeping" instances in the pool. 91 * @param init initial size of the pool (this specifies the size of the container, it does not cause the pool to be pre-populated.) 92 * @see StackKeyedObjectPool#StackKeyedObjectPool(KeyedPoolableObjectFactory, int, int) 93 */ 94 public StackKeyedObjectPoolFactory(KeyedPoolableObjectFactory factory, int max, int init) { 95 _factory = factory; 96 _maxSleeping = max; 97 _initCapacity = init; 98 } 99 100 public KeyedObjectPool createPool() { 101 return new StackKeyedObjectPool(_factory,_maxSleeping,_initCapacity); 102 } 103 104 protected KeyedPoolableObjectFactory _factory = null; 105 protected int _maxSleeping = StackKeyedObjectPool.DEFAULT_MAX_SLEEPING; 106 protected int _initCapacity = StackKeyedObjectPool.DEFAULT_INIT_SLEEPING_CAPACITY; 107 108 }