KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mchange > v2 > resourcepool > ResourcePoolFactory


1 /*
2  * Distributed as part of c3p0 v.0.9.1
3  *
4  * Copyright (C) 2005 Machinery For Change, Inc.
5  *
6  * Author: Steve Waldman <swaldman@mchange.com>
7  *
8  * This library is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License version 2.1, as
10  * published by the Free Software Foundation.
11  *
12  * This software is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this software; see the file LICENSE. If not, write to the
19  * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */

22
23
24 package com.mchange.v2.resourcepool;
25
26 import java.util.Timer JavaDoc;
27 import com.mchange.v2.async.*;
28
29 /**
30  * <P>A Factory for ResourcePools. ResourcePoolFactories may manage
31  * resources (usually threads that perform maintenance tasks) that
32  * are shared by all pools that they create. Clients who require
33  * a large number of pools may wish to create their own factory
34  * instances rather than using the shared instance to control
35  * the degree of resource (Thread) sharing among pools.</P>
36  *
37  * <P>Factories should (and the default implementation does) be careful
38  * to ensure that factories keep resources open only while there
39  * are active ResourcePools that they have created.</P>
40  *
41  * <P>Subclasses must mark all methods synchronized so that clients
42  * may reliably use shared factories to do stuff like...</P>
43  *
44  * <pre>
45  * synchronized (factory)
46  * {
47  * factory.setMin(8);
48  * factory.setMax(24);
49  * ResourcePool rp = factory.createPool();
50  * }
51  * </pre>
52  */

53 public abstract class ResourcePoolFactory
54 {
55     // okay, 'cuz we don't actually create any threads / resourced
56
// until the factory is used.
57
final static ResourcePoolFactory SHARED_INSTANCE = new BasicResourcePoolFactory();
58
59     final static int DEFAULT_NUM_TASK_THREADS = 3;
60
61     public static ResourcePoolFactory getSharedInstance()
62     throws ResourcePoolException
63     { return SHARED_INSTANCE; }
64
65     public static ResourcePoolFactory createInstance()
66     { return new BasicResourcePoolFactory(); }
67
68     public static ResourcePoolFactory createInstance( int num_task_threads )
69     { return new BasicResourcePoolFactory( num_task_threads ); }
70
71     /**
72      * Any or all of these arguments can be null -- any unspecified resources
73      * will be created and cleaned up internally.
74      */

75     public static ResourcePoolFactory createInstance( AsynchronousRunner taskRunner,
76                               RunnableQueue asyncEventQueue,
77                               Timer JavaDoc cullTimer )
78     { return new BasicResourcePoolFactory( taskRunner, asyncEventQueue, cullTimer ); }
79
80     public static ResourcePoolFactory createInstance( Queuable taskRunnerEventQueue,
81                               Timer JavaDoc cullTimer )
82     {
83     return createInstance( taskRunnerEventQueue,
84                    taskRunnerEventQueue == null ?
85                    null :
86                    taskRunnerEventQueue.asRunnableQueue(),
87                    cullTimer );
88     }
89
90     public abstract void setMin( int min )
91     throws ResourcePoolException;
92
93     public abstract int getMin()
94     throws ResourcePoolException;
95
96     public abstract void setMax( int max )
97     throws ResourcePoolException;
98
99     public abstract int getStart()
100     throws ResourcePoolException;
101
102     public abstract void setStart( int start )
103     throws ResourcePoolException;
104
105     public abstract int getMax()
106     throws ResourcePoolException;
107
108     public abstract void setIncrement( int max )
109     throws ResourcePoolException;
110
111     public abstract int getIncrement()
112     throws ResourcePoolException;
113
114     public abstract void setAcquisitionRetryAttempts( int retry_attempts )
115     throws ResourcePoolException;
116
117     public abstract int getAcquisitionRetryAttempts()
118     throws ResourcePoolException;
119
120     public abstract void setAcquisitionRetryDelay( int retry_delay )
121     throws ResourcePoolException;
122
123     public abstract int getAcquisitionRetryDelay()
124     throws ResourcePoolException;
125
126     public abstract void setIdleResourceTestPeriod( long test_period )
127     throws ResourcePoolException;
128
129     public abstract long getIdleResourceTestPeriod()
130     throws ResourcePoolException;
131
132     public abstract void setResourceMaxAge( long millis )
133     throws ResourcePoolException;
134
135     public abstract long getResourceMaxAge()
136     throws ResourcePoolException;
137
138     public abstract void setResourceMaxIdleTime( long millis )
139     throws ResourcePoolException;
140
141     public abstract long getResourceMaxIdleTime()
142     throws ResourcePoolException;
143
144     public abstract void setExcessResourceMaxIdleTime( long millis )
145     throws ResourcePoolException;
146
147     public abstract long getExcessResourceMaxIdleTime()
148     throws ResourcePoolException;
149
150     public abstract long getDestroyOverdueResourceTime()
151     throws ResourcePoolException;
152
153     public abstract void setDestroyOverdueResourceTime( long millis )
154     throws ResourcePoolException;
155
156     public abstract void setExpirationEnforcementDelay( long millis )
157     throws ResourcePoolException;
158
159     public abstract long getExpirationEnforcementDelay()
160     throws ResourcePoolException;
161
162     public abstract void setBreakOnAcquisitionFailure( boolean b )
163     throws ResourcePoolException;
164
165     public abstract boolean getBreakOnAcquisitionFailure()
166     throws ResourcePoolException;
167
168     public abstract void setDebugStoreCheckoutStackTrace( boolean debug_store_checkout_stacktrace )
169     throws ResourcePoolException;
170
171     public abstract boolean getDebugStoreCheckoutStackTrace()
172     throws ResourcePoolException;
173
174 // /**
175
// * Sets whether or not maxAge should be interpreted
176
// * as the maximum age since the resource was first acquired
177
// * (age_is_absolute == true) or since the resource was last
178
// * checked in (age_is_absolute == false).
179
// */
180
// public abstract void setAgeIsAbsolute( boolean age_is_absolute )
181
// throws ResourcePoolException;
182

183 // public abstract boolean getAgeIsAbsolute()
184
// throws ResourcePoolException;
185

186     public abstract ResourcePool createPool(ResourcePool.Manager mgr)
187     throws ResourcePoolException;
188 }
189
190
Popular Tags