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: 958436 $ $Date: 2010-06-27 17:33:17 -0700 (Sun, 27 Jun 2010) $
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 maxSleeping cap on the number of "sleeping" instances in the pool.
048 * @see StackKeyedObjectPool#StackKeyedObjectPool(int)
049 */
050 public StackKeyedObjectPoolFactory(int maxSleeping) {
051 this((KeyedPoolableObjectFactory)null,maxSleeping,StackKeyedObjectPool.DEFAULT_INIT_SLEEPING_CAPACITY);
052 }
053
054 /**
055 * Create a new StackKeyedObjectPoolFactory.
056 *
057 * @param maxSleeping cap on the number of "sleeping" instances in the pool.
058 * @param initialCapacity initial size of the pool (this specifies the size of the container,
059 * it does not cause the pool to be pre-populated.)
060 * @see StackKeyedObjectPool#StackKeyedObjectPool(int, int)
061 */
062 public StackKeyedObjectPoolFactory(int maxSleeping, int initialCapacity) {
063 this((KeyedPoolableObjectFactory)null,maxSleeping,initialCapacity);
064 }
065
066 /**
067 * Create a new StackKeyedObjectPoolFactory.
068 *
069 * @param factory the KeyedPoolableObjectFactory used by created pools.
070 * @see StackKeyedObjectPool#StackKeyedObjectPool(KeyedPoolableObjectFactory)
071 */
072 public StackKeyedObjectPoolFactory(KeyedPoolableObjectFactory factory) {
073 this(factory,StackKeyedObjectPool.DEFAULT_MAX_SLEEPING,StackKeyedObjectPool.DEFAULT_INIT_SLEEPING_CAPACITY);
074 }
075
076 /**
077 * Create a new StackKeyedObjectPoolFactory.
078 *
079 * @param factory the KeyedPoolableObjectFactory used by created pools.
080 * @param maxSleeping cap on the number of "sleeping" instances in the pool.
081 * @see StackKeyedObjectPool#StackKeyedObjectPool(KeyedPoolableObjectFactory, int)
082 */
083 public StackKeyedObjectPoolFactory(KeyedPoolableObjectFactory factory, int maxSleeping) {
084 this(factory,maxSleeping,StackKeyedObjectPool.DEFAULT_INIT_SLEEPING_CAPACITY);
085 }
086
087 /**
088 * Create a new StackKeyedObjectPoolFactory.
089 *
090 * @param factory the KeyedPoolableObjectFactory used by created pools.
091 * @param maxSleeping cap on the number of "sleeping" instances in the pool.
092 * @param initialCapacity initial size of the pool (this specifies the size of the container,
093 * it does not cause the pool to be pre-populated.)
094 * @see StackKeyedObjectPool#StackKeyedObjectPool(KeyedPoolableObjectFactory, int, int)
095 */
096 public StackKeyedObjectPoolFactory(KeyedPoolableObjectFactory factory, int maxSleeping, int initialCapacity) {
097 _factory = factory;
098 _maxSleeping = maxSleeping;
099 _initCapacity = initialCapacity;
100 }
101
102 /**
103 * Create a StackKeyedObjectPool with current property settings.
104 *
105 * @return a new StackKeyedObjectPool with the configured factory, maxSleeping and initialCapacity
106 */
107 public KeyedObjectPool createPool() {
108 return new StackKeyedObjectPool(_factory,_maxSleeping,_initCapacity);
109 }
110
111 /**
112 * KeyedPoolableObjectFactory used by StackKeyedObjectPools created by this factory
113 * @deprecated to be removed in pool 2.0
114 */
115 protected KeyedPoolableObjectFactory _factory = null;
116
117 /**
118 * Maximum number of idle instances in each keyed pool for StackKeyedObjectPools created by this factory
119 * @deprecated to be removed in pool 2.0
120 */
121 protected int _maxSleeping = StackKeyedObjectPool.DEFAULT_MAX_SLEEPING;
122
123 /**
124 * Initial capacity of StackKeyedObjectPools created by this factory.
125 * @deprecated to be removed in pool 2.0
126 */
127 protected int _initCapacity = StackKeyedObjectPool.DEFAULT_INIT_SLEEPING_CAPACITY;
128
129 /**
130 * Returns the KeyedPoolableObjectFactory used by StackKeyedObjectPools created by this factory
131 *
132 * @return factory setting for created pools
133 * @since 1.5.5
134 */
135 public KeyedPoolableObjectFactory getFactory() {
136 return _factory;
137 }
138
139 /**
140 * Returns the maximum number of idle instances in each keyed pool for StackKeyedObjectPools created by this factory
141 *
142 * @return maxSleeping setting for created pools
143 * @since 1.5.5
144 */
145 public int getMaxSleeping() {
146 return _maxSleeping;
147 }
148
149 /**
150 * Returns the initial capacity of StackKeyedObjectPools created by this factory.
151 *
152 * @return initial capacity setting for created pools
153 * @since 1.5.5
154 */
155 public int getInitialCapacity() {
156 return _initCapacity;
157 }
158
159 }