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.KeyedObjectPool;
021    import org.apache.commons.pool.KeyedObjectPoolFactory;
022    import org.apache.commons.pool.KeyedPoolableObjectFactory;
023    
024    /**
025     * A factory for creating {@link StackKeyedObjectPool} instances.
026     *
027     * @see StackKeyedObjectPool
028     * @see KeyedObjectPoolFactory
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 StackKeyedObjectPoolFactory implements KeyedObjectPoolFactory {
035        /**
036         * Create a new StackKeyedObjectPoolFactory.
037         *
038         * @see StackKeyedObjectPool#StackKeyedObjectPool()
039         */
040        public StackKeyedObjectPoolFactory() {
041            this((KeyedPoolableObjectFactory)null,StackKeyedObjectPool.DEFAULT_MAX_SLEEPING,StackKeyedObjectPool.DEFAULT_INIT_SLEEPING_CAPACITY);
042        }
043    
044        /**
045         * Create a new StackKeyedObjectPoolFactory.
046         *
047         * @param max cap on the number of "sleeping" instances in the pool.
048         * @see StackKeyedObjectPool#StackKeyedObjectPool(int)
049         */
050        public StackKeyedObjectPoolFactory(int max) {
051            this((KeyedPoolableObjectFactory)null,max,StackKeyedObjectPool.DEFAULT_INIT_SLEEPING_CAPACITY);
052        }
053    
054        /**
055         * Create a new StackKeyedObjectPoolFactory.
056         *
057         * @param max cap on the number of "sleeping" instances in the pool.
058         * @param init initial size of the pool (this specifies the size of the container, it does not cause the pool to be pre-populated.)
059         * @see StackKeyedObjectPool#StackKeyedObjectPool(int, int)
060         */
061        public StackKeyedObjectPoolFactory(int max, int init) {
062            this((KeyedPoolableObjectFactory)null,max,init);
063        }
064    
065        /**
066         * Create a new StackKeyedObjectPoolFactory.
067         *
068         * @param factory the KeyedPoolableObjectFactory used by created pools.
069         * @see StackKeyedObjectPool#StackKeyedObjectPool(KeyedPoolableObjectFactory)
070         */
071        public StackKeyedObjectPoolFactory(KeyedPoolableObjectFactory factory) {
072            this(factory,StackKeyedObjectPool.DEFAULT_MAX_SLEEPING,StackKeyedObjectPool.DEFAULT_INIT_SLEEPING_CAPACITY);
073        }
074    
075        /**
076         * Create a new StackKeyedObjectPoolFactory.
077         *
078         * @param factory the KeyedPoolableObjectFactory used by created pools.
079         * @param max cap on the number of "sleeping" instances in the pool.
080         * @see StackKeyedObjectPool#StackKeyedObjectPool(KeyedPoolableObjectFactory, int)
081         */
082        public StackKeyedObjectPoolFactory(KeyedPoolableObjectFactory factory, int max) {
083            this(factory,max,StackKeyedObjectPool.DEFAULT_INIT_SLEEPING_CAPACITY);
084        }
085    
086        /**
087         * Create a new StackKeyedObjectPoolFactory.
088         *
089         * @param factory the KeyedPoolableObjectFactory used by created pools.
090         * @param max cap on the number of "sleeping" instances in the pool.
091         * @param init initial size of the pool (this specifies the size of the container, it does not cause the pool to be pre-populated.)
092         * @see StackKeyedObjectPool#StackKeyedObjectPool(KeyedPoolableObjectFactory, int, int)
093         */
094        public StackKeyedObjectPoolFactory(KeyedPoolableObjectFactory factory, int max, int init) {
095            _factory = factory;
096            _maxSleeping = max;
097            _initCapacity = init;
098        }
099    
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    }