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 * @param <K> the type of keys in this pool 028 * @param <V> the type of objects held in this pool 029 * 030 * @see StackKeyedObjectPool 031 * @see KeyedObjectPoolFactory 032 * 033 * @author Rodney Waldhoff 034 * @version $Revision: 1222396 $ $Date: 2011-12-22 14:02:25 -0500 (Thu, 22 Dec 2011) $ 035 * @since Pool 1.0 036 */ 037 public class StackKeyedObjectPoolFactory<K, V> implements KeyedObjectPoolFactory<K, V> { 038 /** 039 * Create a new StackKeyedObjectPoolFactory. 040 * 041 * @see StackKeyedObjectPool#StackKeyedObjectPool() 042 */ 043 public StackKeyedObjectPoolFactory() { 044 this(null,StackKeyedObjectPool.DEFAULT_MAX_SLEEPING,StackKeyedObjectPool.DEFAULT_INIT_SLEEPING_CAPACITY); 045 } 046 047 /** 048 * Create a new StackKeyedObjectPoolFactory. 049 * 050 * @param maxSleeping cap on the number of "sleeping" instances in the pool. 051 * @see StackKeyedObjectPool#StackKeyedObjectPool(int) 052 */ 053 public StackKeyedObjectPoolFactory(int maxSleeping) { 054 this(null,maxSleeping,StackKeyedObjectPool.DEFAULT_INIT_SLEEPING_CAPACITY); 055 } 056 057 /** 058 * Create a new StackKeyedObjectPoolFactory. 059 * 060 * @param maxSleeping cap on the number of "sleeping" instances in the pool. 061 * @param initialCapacity initial size of the pool (this specifies the size of the container, 062 * it does not cause the pool to be pre-populated.) 063 * @see StackKeyedObjectPool#StackKeyedObjectPool(int, int) 064 */ 065 public StackKeyedObjectPoolFactory(int maxSleeping, int initialCapacity) { 066 this(null,maxSleeping,initialCapacity); 067 } 068 069 /** 070 * Create a new StackKeyedObjectPoolFactory. 071 * 072 * @param factory the KeyedPoolableObjectFactory used by created pools. 073 * @see StackKeyedObjectPool#StackKeyedObjectPool(KeyedPoolableObjectFactory) 074 */ 075 public StackKeyedObjectPoolFactory(KeyedPoolableObjectFactory<K, V> factory) { 076 this(factory,StackKeyedObjectPool.DEFAULT_MAX_SLEEPING,StackKeyedObjectPool.DEFAULT_INIT_SLEEPING_CAPACITY); 077 } 078 079 /** 080 * Create a new StackKeyedObjectPoolFactory. 081 * 082 * @param factory the KeyedPoolableObjectFactory used by created pools. 083 * @param maxSleeping cap on the number of "sleeping" instances in the pool. 084 * @see StackKeyedObjectPool#StackKeyedObjectPool(KeyedPoolableObjectFactory, int) 085 */ 086 public StackKeyedObjectPoolFactory(KeyedPoolableObjectFactory<K, V> factory, int maxSleeping) { 087 this(factory,maxSleeping,StackKeyedObjectPool.DEFAULT_INIT_SLEEPING_CAPACITY); 088 } 089 090 /** 091 * Create a new StackKeyedObjectPoolFactory. 092 * 093 * @param factory the KeyedPoolableObjectFactory used by created pools. 094 * @param maxSleeping cap on the number of "sleeping" instances in the pool. 095 * @param initialCapacity initial size of the pool (this specifies the size of the container, 096 * it does not cause the pool to be pre-populated.) 097 * @see StackKeyedObjectPool#StackKeyedObjectPool(KeyedPoolableObjectFactory, int, int) 098 */ 099 public StackKeyedObjectPoolFactory(KeyedPoolableObjectFactory<K, V> factory, int maxSleeping, int initialCapacity) { 100 _factory = factory; 101 _maxSleeping = maxSleeping; 102 _initCapacity = initialCapacity; 103 } 104 105 /** 106 * Create a StackKeyedObjectPool with current property settings. 107 * 108 * @return a new StackKeyedObjectPool with the configured factory, maxSleeping and initialCapacity 109 */ 110 public KeyedObjectPool<K, V> createPool() { 111 return new StackKeyedObjectPool<K, V>(_factory,_maxSleeping,_initCapacity); 112 } 113 114 /** 115 * KeyedPoolableObjectFactory used by StackKeyedObjectPools created by this factory 116 * @deprecated to be removed in pool 2.0 117 */ 118 @Deprecated 119 protected KeyedPoolableObjectFactory<K, V> _factory = null; 120 121 /** 122 * Maximum number of idle instances in each keyed pool for StackKeyedObjectPools created by this factory 123 * @deprecated to be removed in pool 2.0 124 */ 125 @Deprecated 126 protected int _maxSleeping = StackKeyedObjectPool.DEFAULT_MAX_SLEEPING; 127 128 /** 129 * Initial capacity of StackKeyedObjectPools created by this factory. 130 * @deprecated to be removed in pool 2.0 131 */ 132 @Deprecated 133 protected int _initCapacity = StackKeyedObjectPool.DEFAULT_INIT_SLEEPING_CAPACITY; 134 135 /** 136 * Returns the KeyedPoolableObjectFactory used by StackKeyedObjectPools created by this factory 137 * 138 * @return factory setting for created pools 139 * @since 1.5.5 140 */ 141 public KeyedPoolableObjectFactory<K, V> getFactory() { 142 return _factory; 143 } 144 145 /** 146 * Returns the maximum number of idle instances in each keyed pool for StackKeyedObjectPools created by this factory 147 * 148 * @return maxSleeping setting for created pools 149 * @since 1.5.5 150 */ 151 public int getMaxSleeping() { 152 return _maxSleeping; 153 } 154 155 /** 156 * Returns the initial capacity of StackKeyedObjectPools created by this factory. 157 * 158 * @return initial capacity setting for created pools 159 * @since 1.5.5 160 */ 161 public int getInitialCapacity() { 162 return _initCapacity; 163 } 164 165 }