    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: 960705 $ $Date: 2010-07-05 14:19:10 -0700 (Mon, 05 Jul 2010) $
    032     * @since Pool 1.0
    033     */
    034    public class StackObjectPoolFactory implements ObjectPoolFactory {
    035        /**
    036         * Create a new StackObjectPoolFactory.
    037         *
    038         * @see StackObjectPool#StackObjectPool()
    039         * @deprecated to be removed in pool 2.0 - use {@link #StackObjectPoolFactory(PoolableObjectFactory)}
    040         */
    041        public StackObjectPoolFactory() {
    042            this((PoolableObjectFactory)null,StackObjectPool.DEFAULT_MAX_SLEEPING,StackObjectPool.DEFAULT_INIT_SLEEPING_CAPACITY);
    043        }
    044
    045        /**
    046         * Create a new StackObjectPoolFactory.
    047         *
    048         * @param maxIdle cap on the number of "sleeping" instances in the pool.
    049         * @see StackObjectPool#StackObjectPool(int)
    050         * @deprecated to be removed in pool 2.0 - use {@link #StackObjectPoolFactory(PoolableObjectFactory, int)}
    051         */
    052        public StackObjectPoolFactory(int maxIdle) {
    053            this((PoolableObjectFactory)null,maxIdle,StackObjectPool.DEFAULT_INIT_SLEEPING_CAPACITY);
    054        }
    055
    056        /**
    057         * Create a new StackObjectPoolFactory.
    058         *
    059         * @param maxIdle cap on the number of "sleeping" instances in the pool.
    060         * @param initIdleCapacity - initial size of the pool (this specifies the size of the container,
    061         * it does not cause the pool to be pre-populated.)
    062         * @see StackObjectPool#StackObjectPool(int, int)
    063         * @deprecated to be removed in pool 2.0 - use {@link #StackObjectPoolFactory(PoolableObjectFactory, int, int)}
    064         */
    065        public StackObjectPoolFactory(int maxIdle, int initIdleCapacity) {
    066            this((PoolableObjectFactory)null,maxIdle,initIdleCapacity);
    067        }
    068
    069        /**
    070         * Create a new StackObjectPoolFactory.
    071         *
    072         * @param factory the PoolableObjectFactory used by created pools.
    073         * @see StackObjectPool#StackObjectPool(PoolableObjectFactory)
    074         */
    075        public StackObjectPoolFactory(PoolableObjectFactory factory) {
    076            this(factory,StackObjectPool.DEFAULT_MAX_SLEEPING,StackObjectPool.DEFAULT_INIT_SLEEPING_CAPACITY);
    077        }
    078
    079        /**
    080         * Create a new StackObjectPoolFactory.
    081         *
    082         * @param factory the PoolableObjectFactory used by created pools.
    083         * @param maxIdle cap on the number of "sleeping" instances in the pool.
    084         */
    085        public StackObjectPoolFactory(PoolableObjectFactory factory, int maxIdle) {
    086            this(factory,maxIdle,StackObjectPool.DEFAULT_INIT_SLEEPING_CAPACITY);
    087        }
    088
    089        /**
    090         * Create a new StackObjectPoolFactory.
    091         *
    092         * @param factory the PoolableObjectFactory used by created pools.
    093         * @param maxIdle cap on the number of "sleeping" instances in the pool.
    094         * @param initIdleCapacity - initial size of the pool (this specifies the size of the container,
    095         * it does not cause the pool to be pre-populated.)
    096         */
    097        public StackObjectPoolFactory(PoolableObjectFactory factory, int maxIdle, int initIdleCapacity) {
    098            _factory = factory;
    099            _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    }