Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
StackKeyedObjectPoolFactory |
|
| 1.0;1 |
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.KeyedObjectPool; | |
21 | import org.apache.commons.pool.KeyedObjectPoolFactory; | |
22 | import org.apache.commons.pool.KeyedPoolableObjectFactory; | |
23 | ||
24 | /** | |
25 | * A factory for creating {@link StackKeyedObjectPool} instances. | |
26 | * | |
27 | * @see StackKeyedObjectPool | |
28 | * @see KeyedObjectPoolFactory | |
29 | * | |
30 | * @author Rodney Waldhoff | |
31 | * @version $Revision: 958436 $ $Date: 2010-06-27 17:33:17 -0700 (Sun, 27 Jun 2010) $ | |
32 | * @since Pool 1.0 | |
33 | */ | |
34 | public class StackKeyedObjectPoolFactory implements KeyedObjectPoolFactory { | |
35 | /** | |
36 | * Create a new StackKeyedObjectPoolFactory. | |
37 | * | |
38 | * @see StackKeyedObjectPool#StackKeyedObjectPool() | |
39 | */ | |
40 | public StackKeyedObjectPoolFactory() { | |
41 | 0 | this((KeyedPoolableObjectFactory)null,StackKeyedObjectPool.DEFAULT_MAX_SLEEPING,StackKeyedObjectPool.DEFAULT_INIT_SLEEPING_CAPACITY); |
42 | 0 | } |
43 | ||
44 | /** | |
45 | * Create a new StackKeyedObjectPoolFactory. | |
46 | * | |
47 | * @param maxSleeping cap on the number of "sleeping" instances in the pool. | |
48 | * @see StackKeyedObjectPool#StackKeyedObjectPool(int) | |
49 | */ | |
50 | public StackKeyedObjectPoolFactory(int maxSleeping) { | |
51 | 0 | this((KeyedPoolableObjectFactory)null,maxSleeping,StackKeyedObjectPool.DEFAULT_INIT_SLEEPING_CAPACITY); |
52 | 0 | } |
53 | ||
54 | /** | |
55 | * Create a new StackKeyedObjectPoolFactory. | |
56 | * | |
57 | * @param maxSleeping cap on the number of "sleeping" instances in the pool. | |
58 | * @param initialCapacity initial size of the pool (this specifies the size of the container, | |
59 | * it does not cause the pool to be pre-populated.) | |
60 | * @see StackKeyedObjectPool#StackKeyedObjectPool(int, int) | |
61 | */ | |
62 | public StackKeyedObjectPoolFactory(int maxSleeping, int initialCapacity) { | |
63 | 0 | this((KeyedPoolableObjectFactory)null,maxSleeping,initialCapacity); |
64 | 0 | } |
65 | ||
66 | /** | |
67 | * Create a new StackKeyedObjectPoolFactory. | |
68 | * | |
69 | * @param factory the KeyedPoolableObjectFactory used by created pools. | |
70 | * @see StackKeyedObjectPool#StackKeyedObjectPool(KeyedPoolableObjectFactory) | |
71 | */ | |
72 | public StackKeyedObjectPoolFactory(KeyedPoolableObjectFactory factory) { | |
73 | 0 | this(factory,StackKeyedObjectPool.DEFAULT_MAX_SLEEPING,StackKeyedObjectPool.DEFAULT_INIT_SLEEPING_CAPACITY); |
74 | 0 | } |
75 | ||
76 | /** | |
77 | * Create a new StackKeyedObjectPoolFactory. | |
78 | * | |
79 | * @param factory the KeyedPoolableObjectFactory used by created pools. | |
80 | * @param maxSleeping cap on the number of "sleeping" instances in the pool. | |
81 | * @see StackKeyedObjectPool#StackKeyedObjectPool(KeyedPoolableObjectFactory, int) | |
82 | */ | |
83 | public StackKeyedObjectPoolFactory(KeyedPoolableObjectFactory factory, int maxSleeping) { | |
84 | 0 | this(factory,maxSleeping,StackKeyedObjectPool.DEFAULT_INIT_SLEEPING_CAPACITY); |
85 | 0 | } |
86 | ||
87 | /** | |
88 | * Create a new StackKeyedObjectPoolFactory. | |
89 | * | |
90 | * @param factory the KeyedPoolableObjectFactory used by created pools. | |
91 | * @param maxSleeping cap on the number of "sleeping" instances in the pool. | |
92 | * @param initialCapacity initial size of the pool (this specifies the size of the container, | |
93 | * it does not cause the pool to be pre-populated.) | |
94 | * @see StackKeyedObjectPool#StackKeyedObjectPool(KeyedPoolableObjectFactory, int, int) | |
95 | */ | |
96 | 0 | public StackKeyedObjectPoolFactory(KeyedPoolableObjectFactory factory, int maxSleeping, int initialCapacity) { |
97 | 0 | _factory = factory; |
98 | 0 | _maxSleeping = maxSleeping; |
99 | 0 | _initCapacity = initialCapacity; |
100 | 0 | } |
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 | 0 | 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 | 0 | 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 | 0 | 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 | 0 | 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 | 0 | 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 | 0 | 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 | 0 | return _initCapacity; |
157 | } | |
158 | ||
159 | } |