1 package org.apache.jcs.utils.threadpool;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.jcs.utils.threadpool.behavior.IPoolConfiguration;
23
24
25 /***
26 * This object holds configuration data for a thread pool.
27 * <p>
28 * @author Aaron Smuts
29 */
30 public class PoolConfiguration
31 implements Cloneable, IPoolConfiguration
32 {
33 private boolean useBoundary = true;
34
35 private int boundarySize = 2000;
36
37
38 private int maximumPoolSize = 150;
39
40
41
42 private int minimumPoolSize = 4;
43
44 private int keepAliveTime = 1000 * 60 * 5;
45
46
47 private String whenBlockedPolicy = POLICY_RUN;
48
49 private int startUpSize = 4;
50
51 /***
52 * @param useBoundary
53 * The useBoundary to set.
54 */
55 public void setUseBoundary( boolean useBoundary )
56 {
57 this.useBoundary = useBoundary;
58 }
59
60 /***
61 * @return Returns the useBoundary.
62 */
63 public boolean isUseBoundary()
64 {
65 return useBoundary;
66 }
67
68 /***
69 * Default
70 */
71 public PoolConfiguration()
72 {
73
74 }
75
76 /***
77 * Construct a completely configured instance.
78 * <p>
79 * @param useBoundary
80 * @param boundarySize
81 * @param maximumPoolSize
82 * @param minimumPoolSize
83 * @param keepAliveTime
84 * @param whenBlockedPolicy
85 * @param startUpSize
86 */
87 public PoolConfiguration( boolean useBoundary, int boundarySize, int maximumPoolSize, int minimumPoolSize,
88 int keepAliveTime, String whenBlockedPolicy, int startUpSize )
89 {
90 setUseBoundary( useBoundary );
91 setBoundarySize( boundarySize );
92 setMaximumPoolSize( maximumPoolSize );
93 setMinimumPoolSize( minimumPoolSize );
94 setKeepAliveTime( keepAliveTime );
95 setWhenBlockedPolicy( whenBlockedPolicy );
96 setStartUpSize( startUpSize );
97 }
98
99 /***
100 * @param boundarySize
101 * The boundarySize to set.
102 */
103 public void setBoundarySize( int boundarySize )
104 {
105 this.boundarySize = boundarySize;
106 }
107
108 /***
109 * @return Returns the boundarySize.
110 */
111 public int getBoundarySize()
112 {
113 return boundarySize;
114 }
115
116 /***
117 * @param maximumPoolSize
118 * The maximumPoolSize to set.
119 */
120 public void setMaximumPoolSize( int maximumPoolSize )
121 {
122 this.maximumPoolSize = maximumPoolSize;
123 }
124
125 /***
126 * @return Returns the maximumPoolSize.
127 */
128 public int getMaximumPoolSize()
129 {
130 return maximumPoolSize;
131 }
132
133 /***
134 * @param minimumPoolSize
135 * The minimumPoolSize to set.
136 */
137 public void setMinimumPoolSize( int minimumPoolSize )
138 {
139 this.minimumPoolSize = minimumPoolSize;
140 }
141
142 /***
143 * @return Returns the minimumPoolSize.
144 */
145 public int getMinimumPoolSize()
146 {
147 return minimumPoolSize;
148 }
149
150 /***
151 * @param keepAliveTime
152 * The keepAliveTime to set.
153 */
154 public void setKeepAliveTime( int keepAliveTime )
155 {
156 this.keepAliveTime = keepAliveTime;
157 }
158
159 /***
160 * @return Returns the keepAliveTime.
161 */
162 public int getKeepAliveTime()
163 {
164 return keepAliveTime;
165 }
166
167 /***
168 * @param whenBlockedPolicy
169 * The whenBlockedPolicy to set.
170 */
171 public void setWhenBlockedPolicy( String whenBlockedPolicy )
172 {
173 if ( whenBlockedPolicy != null )
174 {
175 whenBlockedPolicy = whenBlockedPolicy.trim();
176
177 if ( whenBlockedPolicy.equalsIgnoreCase( POLICY_ABORT ) )
178 {
179 this.whenBlockedPolicy = POLICY_ABORT;
180 }
181 else if ( whenBlockedPolicy.equalsIgnoreCase( POLICY_RUN ) )
182 {
183 this.whenBlockedPolicy = POLICY_RUN;
184 }
185 else if ( whenBlockedPolicy.equalsIgnoreCase( POLICY_BLOCK ) )
186 {
187 this.whenBlockedPolicy = POLICY_BLOCK;
188 }
189 else if ( whenBlockedPolicy.equalsIgnoreCase( POLICY_DISCARDOLDEST ) )
190 {
191 this.whenBlockedPolicy = POLICY_DISCARDOLDEST;
192 }
193 else if ( whenBlockedPolicy.equalsIgnoreCase( POLICY_WAIT ) )
194 {
195 this.whenBlockedPolicy = POLICY_WAIT;
196 }
197 else
198 {
199
200 this.whenBlockedPolicy = POLICY_RUN;
201 }
202 }
203 else
204 {
205
206 this.whenBlockedPolicy = POLICY_RUN;
207 }
208 }
209
210 /***
211 * @return Returns the whenBlockedPolicy.
212 */
213 public String getWhenBlockedPolicy()
214 {
215 return whenBlockedPolicy;
216 }
217
218 /***
219 * @param startUpSize
220 * The startUpSize to set.
221 */
222 public void setStartUpSize( int startUpSize )
223 {
224 this.startUpSize = startUpSize;
225 }
226
227 /***
228 * @return Returns the startUpSize.
229 */
230 public int getStartUpSize()
231 {
232 return startUpSize;
233 }
234
235 /***
236 * To string for debugging purposes.
237 * @return String
238 */
239 public String toString()
240 {
241 StringBuffer buf = new StringBuffer();
242 buf.append( "useBoundary = [" + isUseBoundary() + "] " );
243 buf.append( "boundarySize = [" + boundarySize + "] " );
244 buf.append( "maximumPoolSize = [" + maximumPoolSize + "] " );
245 buf.append( "minimumPoolSize = [" + minimumPoolSize + "] " );
246 buf.append( "keepAliveTime = [" + keepAliveTime + "] " );
247 buf.append( "whenBlockedPolicy = [" + getWhenBlockedPolicy() + "] " );
248 buf.append( "startUpSize = [" + startUpSize + "]" );
249 return buf.toString();
250 }
251
252 /***
253 * Copies the instance variables to another instance.
254 * <p>
255 * @return PoolConfiguration
256 */
257 public Object clone()
258 {
259 return new PoolConfiguration( isUseBoundary(), boundarySize, maximumPoolSize, minimumPoolSize, keepAliveTime,
260 getWhenBlockedPolicy(), startUpSize );
261 }
262 }