1 package org.apache.turbine.services.pool;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 import org.apache.turbine.services.Service;
20 import org.apache.turbine.util.TurbineException;
21
22 /***
23 * The Pool Service extends the Factory Service by adding support
24 * for pooling instantiated objects. When a new instance is
25 * requested, the service first checks its pool if one is available.
26 * If the the pool is empty, a new object will be instantiated
27 * from the specified class. If only class name is given, the request
28 * to create an intance will be forwarded to the Factory Service.
29 *
30 * <p>For objects implementing the Recyclable interface, a recycle
31 * method will be called, when they are taken from the pool, and
32 * a dispose method, when they are returned to the pool.
33 *
34 * @author <a href="mailto:ilkka.priha@simsoft.fi">Ilkka Priha</a>
35 * @version $Id: PoolService.java 264148 2005-08-29 14:21:04Z henning $
36 */
37 public interface PoolService
38 extends Service
39 {
40 /*** The key under which this service is stored in TurbineServices. */
41 String SERVICE_NAME = "PoolService";
42
43 /*** The default pool capacity. */
44 int DEFAULT_POOL_CAPACITY = 128;
45
46 /*** The name of the pool capacity property */
47 String POOL_CAPACITY_KEY = "pool.capacity";
48
49 /*** Are we running in debug mode? */
50 String POOL_DEBUG_KEY = "pool.debug";
51
52 /*** Default Value for debug mode */
53 boolean POOL_DEBUG_DEFAULT = false;
54
55 /***
56 * Gets an instance of a named class.
57 *
58 * @param className the name of the class.
59 * @return the instance.
60 * @throws TurbineException if instantiation fails.
61 */
62 Object getInstance(String className)
63 throws TurbineException;
64
65 /***
66 * Gets an instance of a named class using a specified class loader.
67 *
68 * <p>Class loaders are supported only if the isLoaderSupported
69 * method returns true. Otherwise the loader parameter is ignored.
70 *
71 * @param className the name of the class.
72 * @param loader the class loader.
73 * @return the instance.
74 * @throws TurbineException if instantiation fails.
75 */
76 Object getInstance(String className,
77 ClassLoader loader)
78 throws TurbineException;
79
80 /***
81 * Gets an instance of a named class.
82 * Parameters for its constructor are given as an array of objects,
83 * primitive types must be wrapped with a corresponding class.
84 *
85 * @param className the name of the class.
86 * @param params an array containing the parameters of the constructor.
87 * @param signature an array containing the signature of the constructor.
88 * @return the instance.
89 * @throws TurbineException if instantiation fails.
90 */
91 Object getInstance(String className,
92 Object[] params,
93 String[] signature)
94 throws TurbineException;
95
96 /***
97 * Gets an instance of a named class using a specified class loader.
98 * Parameters for its constructor are given as an array of objects,
99 * primitive types must be wrapped with a corresponding class.
100 *
101 * <p>Class loaders are supported only if the isLoaderSupported
102 * method returns true. Otherwise the loader parameter is ignored.
103 *
104 * @param className the name of the class.
105 * @param loader the class loader.
106 * @param params an array containing the parameters of the constructor.
107 * @param signature an array containing the signature of the constructor.
108 * @return the instance.
109 * @throws TurbineException if instantiation fails.
110 */
111 Object getInstance(String className,
112 ClassLoader loader,
113 Object[] params,
114 String[] signature)
115 throws TurbineException;
116
117 /***
118 * Tests if specified class loaders are supported for a named class.
119 *
120 * @param className the name of the class.
121 * @return true if class loaders are supported, false otherwise.
122 * @throws TurbineException if test fails.
123 * @deprecated Use TurbineFactory.isLoaderSupported(className)
124 */
125 boolean isLoaderSupported(String className)
126 throws TurbineException;
127
128 /***
129 * Gets an instance of a specified class either from the pool
130 * or by instatiating from the class if the pool is empty.
131 *
132 * @param clazz the class.
133 * @return the instance.
134 * @throws TurbineException if recycling fails.
135 */
136 Object getInstance(Class clazz)
137 throws TurbineException;
138
139 /***
140 * Gets an instance of a specified class either from the pool
141 * or by instatiating from the class if the pool is empty.
142 *
143 * @param clazz the class.
144 * @param params an array containing the parameters of the constructor.
145 * @param signature an array containing the signature of the constructor.
146 * @return the instance.
147 * @throws TurbineException if recycling fails.
148 */
149 Object getInstance(Class clazz,
150 Object params[],
151 String signature[])
152 throws TurbineException;
153
154 /***
155 * Puts a used object back to the pool. Objects implementing
156 * the Recyclable interface can provide a recycle method to
157 * be called when they are reused and a dispose method to be
158 * called when they are returned to the pool.
159 *
160 * @param instance the object instance to recycle.
161 * @return true if the instance was accepted.
162 */
163 boolean putInstance(Object instance);
164
165 /***
166 * Gets the capacity of the pool for a named class.
167 *
168 * @param className the name of the class.
169 */
170 int getCapacity(String className);
171
172 /***
173 * Sets the capacity of the pool for a named class.
174 * Note that the pool will be cleared after the change.
175 *
176 * @param className the name of the class.
177 * @param capacity the new capacity.
178 */
179 void setCapacity(String className,
180 int capacity);
181
182 /***
183 * Gets the current size of the pool for a named class.
184 *
185 * @param className the name of the class.
186 */
187 int getSize(String className);
188
189 /***
190 * Clears instances of a named class from the pool.
191 *
192 * @param className the name of the class.
193 */
194 void clearPool(String className);
195
196 /***
197 * Clears all instances from the pool.
198 */
199 void clearPool();
200
201 }