View Javadoc

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.ObjectPool;
21  import org.apache.commons.pool.ObjectPoolFactory;
22  import org.apache.commons.pool.PoolableObjectFactory;
23  
24  /**
25   * A factory for creating {@link StackObjectPool} instances.
26   *
27   * @param <T> the type of objects held in this pool
28   * 
29   * @see StackObjectPool
30   * @see StackKeyedObjectPoolFactory
31   *
32   * @author Rodney Waldhoff
33   * @version $Revision: 1222396 $ $Date: 2011-12-22 14:02:25 -0500 (Thu, 22 Dec 2011) $
34   * @since Pool 1.0
35   */
36  public class StackObjectPoolFactory<T> implements ObjectPoolFactory<T> {
37      /**
38       * Create a new StackObjectPoolFactory.
39       *
40       * @see StackObjectPool#StackObjectPool()
41       * @deprecated to be removed in pool 2.0 - use {@link #StackObjectPoolFactory(PoolableObjectFactory)}
42       */
43      @Deprecated
44      public StackObjectPoolFactory() {
45          this(null,StackObjectPool.DEFAULT_MAX_SLEEPING,StackObjectPool.DEFAULT_INIT_SLEEPING_CAPACITY);
46      }
47  
48      /**
49       * Create a new StackObjectPoolFactory.
50       *
51       * @param maxIdle cap on the number of "sleeping" instances in the pool.
52       * @see StackObjectPool#StackObjectPool(int)
53       * @deprecated to be removed in pool 2.0 - use {@link #StackObjectPoolFactory(PoolableObjectFactory, int)}
54       */
55      @Deprecated
56      public StackObjectPoolFactory(int maxIdle) {
57          this(null,maxIdle,StackObjectPool.DEFAULT_INIT_SLEEPING_CAPACITY);
58      }
59  
60      /**
61       * Create a new StackObjectPoolFactory.
62       *
63       * @param maxIdle cap on the number of "sleeping" instances in the pool.
64       * @param initIdleCapacity - initial size of the pool (this specifies the size of the container,
65       * it does not cause the pool to be pre-populated.)
66       * @see StackObjectPool#StackObjectPool(int, int)
67       * @deprecated to be removed in pool 2.0 - use {@link #StackObjectPoolFactory(PoolableObjectFactory, int, int)}
68       */
69      @Deprecated
70      public StackObjectPoolFactory(int maxIdle, int initIdleCapacity) {
71          this(null,maxIdle,initIdleCapacity);
72      }
73  
74      /**
75       * Create a new StackObjectPoolFactory.
76       *
77       * @param factory the PoolableObjectFactory used by created pools.
78       * @see StackObjectPool#StackObjectPool(PoolableObjectFactory)
79       */
80      public StackObjectPoolFactory(PoolableObjectFactory<T> factory) {
81          this(factory,StackObjectPool.DEFAULT_MAX_SLEEPING,StackObjectPool.DEFAULT_INIT_SLEEPING_CAPACITY);
82      }
83  
84      /**
85       * Create a new StackObjectPoolFactory.
86       *
87       * @param factory the PoolableObjectFactory used by created pools.
88       * @param maxIdle cap on the number of "sleeping" instances in the pool.
89       */
90      public StackObjectPoolFactory(PoolableObjectFactory<T> factory, int maxIdle) {
91          this(factory,maxIdle,StackObjectPool.DEFAULT_INIT_SLEEPING_CAPACITY);
92      }
93  
94      /**
95       * Create a new StackObjectPoolFactory.
96       *
97       * @param factory the PoolableObjectFactory used by created pools.
98       * @param maxIdle cap on the number of "sleeping" instances in the pool.
99       * @param initIdleCapacity - initial size of the pool (this specifies the size of the container,
100      * it does not cause the pool to be pre-populated.)
101      */
102     public StackObjectPoolFactory(PoolableObjectFactory<T> factory, int maxIdle, int initIdleCapacity) {
103         _factory = factory;
104         _maxSleeping = maxIdle;
105         _initCapacity = initIdleCapacity;
106     }
107 
108     /**
109      * Create a StackObjectPool.
110      * 
111      * @return a new StackObjectPool with the configured factory, maxIdle and initial capacity settings
112      */
113     public ObjectPool<T> createPool() {
114         return new StackObjectPool<T>(_factory,_maxSleeping,_initCapacity);
115     }
116 
117     /**
118      * The PoolableObjectFactory used by created pools.
119      * @deprecated to be made private in pool 2.0
120      */
121     @Deprecated
122     protected PoolableObjectFactory<T> _factory = null;
123     
124     /**
125      * The maximum number of idle instances in created pools.
126      * @deprecated to be made private in pool 2.0
127      */
128     @Deprecated
129     protected int _maxSleeping = StackObjectPool.DEFAULT_MAX_SLEEPING;
130     
131     /**
132      * The initial size of created pools.
133      * @deprecated to be made private in pool 2.0
134      */
135     @Deprecated
136     protected int _initCapacity = StackObjectPool.DEFAULT_INIT_SLEEPING_CAPACITY;
137 
138     /**
139      * Returns the factory used by created pools.
140      * 
141      * @return the PoolableObjectFactory used by created pools
142      * @since 1.5.5
143      */
144     public PoolableObjectFactory<T> getFactory() {
145         return _factory;
146     }
147 
148     /**
149      * Returns the maxIdle setting for created pools.
150      * 
151      * @return the maximum number of idle instances in created pools
152      * @since 1.5.5
153      */
154     public int getMaxSleeping() {
155         return _maxSleeping;
156     }
157 
158     /**
159      * Returns the initial capacity of created pools.
160      * 
161      * @return size of created containers (created pools are not pre-populated)
162      * @since 1.5.5
163      */
164     public int getInitCapacity() {
165         return _initCapacity;
166     }
167 
168 }