KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > turbine > services > pool > PoolService


1 package org.apache.turbine.services.pool;
2
3 /*
4  * Copyright 2001-2004 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License")
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
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,v 1.7.2.2 2004/05/20 03:06:52 seade Exp $
36  */

37 public interface PoolService
38         extends Service
39 {
40     /** The key under which this service is stored in TurbineServices. */
41     String JavaDoc 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 JavaDoc POOL_CAPACITY_KEY = "pool.capacity";
48     
49     /** Are we running in debug mode? */
50     String JavaDoc 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 JavaDoc getInstance(String JavaDoc 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 JavaDoc getInstance(String JavaDoc className,
77             ClassLoader JavaDoc 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 JavaDoc getInstance(String JavaDoc className,
92             Object JavaDoc[] params,
93             String JavaDoc[] 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 JavaDoc getInstance(String JavaDoc className,
112             ClassLoader JavaDoc loader,
113             Object JavaDoc[] params,
114             String JavaDoc[] 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 JavaDoc 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 JavaDoc getInstance(Class JavaDoc 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 JavaDoc getInstance(Class JavaDoc clazz,
150             Object JavaDoc params[],
151             String JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc className);
195
196     /**
197      * Clears all instances from the pool.
198      */

199     void clearPool();
200
201 }
202
Popular Tags