Source Code Cross Referenced for JKStatusUpdateTask.java in  » Sevlet-Container » apache-tomcat-6.0.14 » org » apache » catalina » ant » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Sevlet Container » apache tomcat 6.0.14 » org.apache.catalina.ant 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         * 
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         * 
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:
018:        package org.apache.catalina.ant;
019:
020:        import java.io.UnsupportedEncodingException;
021:        import java.net.URLEncoder;
022:
023:        import org.apache.tools.ant.BuildException;
024:
025:        /**
026:         * Ant task that implements the <code>/status</code> command, supported by the
027:         * mod_jk status (1.2.9) application.
028:         * 
029:         * @author Peter Rossbach
030:         * @version $Revision: 467222 $
031:         * @since 5.5.9
032:         */
033:        public class JKStatusUpdateTask extends AbstractCatalinaTask {
034:
035:            private String worker = "lb";
036:
037:            private String workerType = "lb";
038:
039:            private int internalid = 0;
040:
041:            private Integer lbRetries;
042:
043:            private Integer lbRecovertime;
044:
045:            private Boolean lbStickySession = Boolean.TRUE;
046:
047:            private Boolean lbForceSession = Boolean.FALSE;
048:
049:            private Integer workerLoadFactor;
050:
051:            private String workerRedirect;
052:
053:            private String workerClusterDomain;
054:
055:            private Boolean workerDisabled = Boolean.FALSE;
056:
057:            private Boolean workerStopped = Boolean.FALSE;
058:
059:            private boolean isLBMode = true;
060:
061:            private String workerLb;
062:
063:            /**
064:             *  
065:             */
066:            public JKStatusUpdateTask() {
067:                super ();
068:                setUrl("http://localhost/status");
069:            }
070:
071:            /**
072:             * @return Returns the internalid.
073:             */
074:            public int getInternalid() {
075:                return internalid;
076:            }
077:
078:            /**
079:             * @param internalid
080:             *            The internalid to set.
081:             */
082:            public void setInternalid(int internalid) {
083:                this .internalid = internalid;
084:            }
085:
086:            /**
087:             * @return Returns the lbForceSession.
088:             */
089:            public Boolean getLbForceSession() {
090:                return lbForceSession;
091:            }
092:
093:            /**
094:             * @param lbForceSession
095:             *            The lbForceSession to set.
096:             */
097:            public void setLbForceSession(Boolean lbForceSession) {
098:                this .lbForceSession = lbForceSession;
099:            }
100:
101:            /**
102:             * @return Returns the lbRecovertime.
103:             */
104:            public Integer getLbRecovertime() {
105:                return lbRecovertime;
106:            }
107:
108:            /**
109:             * @param lbRecovertime
110:             *            The lbRecovertime to set.
111:             */
112:            public void setLbRecovertime(Integer lbRecovertime) {
113:                this .lbRecovertime = lbRecovertime;
114:            }
115:
116:            /**
117:             * @return Returns the lbRetries.
118:             */
119:            public Integer getLbRetries() {
120:                return lbRetries;
121:            }
122:
123:            /**
124:             * @param lbRetries
125:             *            The lbRetries to set.
126:             */
127:            public void setLbRetries(Integer lbRetries) {
128:                this .lbRetries = lbRetries;
129:            }
130:
131:            /**
132:             * @return Returns the lbStickySession.
133:             */
134:            public Boolean getLbStickySession() {
135:                return lbStickySession;
136:            }
137:
138:            /**
139:             * @param lbStickySession
140:             *            The lbStickySession to set.
141:             */
142:            public void setLbStickySession(Boolean lbStickySession) {
143:                this .lbStickySession = lbStickySession;
144:            }
145:
146:            /**
147:             * @return Returns the worker.
148:             */
149:            public String getWorker() {
150:                return worker;
151:            }
152:
153:            /**
154:             * @param worker
155:             *            The worker to set.
156:             */
157:            public void setWorker(String worker) {
158:                this .worker = worker;
159:            }
160:
161:            /**
162:             * @return Returns the workerType.
163:             */
164:            public String getWorkerType() {
165:                return workerType;
166:            }
167:
168:            /**
169:             * @param workerType
170:             *            The workerType to set.
171:             */
172:            public void setWorkerType(String workerType) {
173:                this .workerType = workerType;
174:            }
175:
176:            /**
177:             * @return Returns the workerLb.
178:             */
179:            public String getWorkerLb() {
180:                return workerLb;
181:            }
182:
183:            /**
184:             * @param workerLb
185:             *            The workerLb to set.
186:             */
187:            public void setWorkerLb(String workerLb) {
188:                this .workerLb = workerLb;
189:            }
190:
191:            /**
192:             * @return Returns the workerClusterDomain.
193:             */
194:            public String getWorkerClusterDomain() {
195:                return workerClusterDomain;
196:            }
197:
198:            /**
199:             * @param workerClusterDomain
200:             *            The workerClusterDomain to set.
201:             */
202:            public void setWorkerClusterDomain(String workerClusterDomain) {
203:                this .workerClusterDomain = workerClusterDomain;
204:            }
205:
206:            /**
207:             * @return Returns the workerDisabled.
208:             */
209:            public Boolean getWorkerDisabled() {
210:                return workerDisabled;
211:            }
212:
213:            /**
214:             * @param workerDisabled
215:             *            The workerDisabled to set.
216:             */
217:            public void setWorkerDisabled(Boolean workerDisabled) {
218:                this .workerDisabled = workerDisabled;
219:            }
220:
221:            /**
222:             * @return Returns the workerStopped.
223:             */
224:            public Boolean getWorkerStopped() {
225:                return workerStopped;
226:            }
227:
228:            /**
229:             * @param workerStopped The workerStopped to set.
230:             */
231:            public void setWorkerStopped(Boolean workerStopped) {
232:                this .workerStopped = workerStopped;
233:            }
234:
235:            /**
236:             * @return Returns the workerLoadFactor.
237:             */
238:            public Integer getWorkerLoadFactor() {
239:                return workerLoadFactor;
240:            }
241:
242:            /**
243:             * @param workerLoadFactor
244:             *            The workerLoadFactor to set.
245:             */
246:            public void setWorkerLoadFactor(Integer workerLoadFactor) {
247:                this .workerLoadFactor = workerLoadFactor;
248:            }
249:
250:            /**
251:             * @return Returns the workerRedirect.
252:             */
253:            public String getWorkerRedirect() {
254:                return workerRedirect;
255:            }
256:
257:            /**
258:             * @param workerRedirect
259:             *            The workerRedirect to set.
260:             */
261:            public void setWorkerRedirect(String workerRedirect) {
262:                this .workerRedirect = workerRedirect;
263:            }
264:
265:            /**
266:             * Execute the requested operation.
267:             * 
268:             * @exception BuildException
269:             *                if an error occurs
270:             */
271:            public void execute() throws BuildException {
272:
273:                super .execute();
274:                checkParameter();
275:                StringBuffer sb = createLink();
276:                execute(sb.toString(), null, null, -1);
277:
278:            }
279:
280:            /**
281:             * Create JkStatus link
282:             * <ul>
283:             * <li><b>load balance example:
284:             * </b>http://localhost/status?cmd=update&mime=txt&w=lb&lf=false&ls=true</li>
285:             * <li><b>worker example:
286:             * </b>http://localhost/status?cmd=update&mime=txt&w=node1&l=lb&wf=1&wd=false&ws=false
287:             * </li>
288:             * </ul>
289:             * 
290:             * @return create jkstatus link
291:             */
292:            private StringBuffer createLink() {
293:                // Building URL
294:                StringBuffer sb = new StringBuffer();
295:                try {
296:                    sb.append("?cmd=update&mime=txt");
297:                    sb.append("&w=");
298:                    sb.append(URLEncoder.encode(worker, getCharset()));
299:
300:                    if (isLBMode) {
301:                        //http://localhost/status?cmd=update&mime=txt&w=lb&lf=false&ls=true
302:                        if ((lbRetries != null)) { // > 0
303:                            sb.append("&lr=");
304:                            sb.append(lbRetries);
305:                        }
306:                        if ((lbRecovertime != null)) { // > 59
307:                            sb.append("&lt=");
308:                            sb.append(lbRecovertime);
309:                        }
310:                        if ((lbStickySession != null)) {
311:                            sb.append("&ls=");
312:                            sb.append(lbStickySession);
313:                        }
314:                        if ((lbForceSession != null)) {
315:                            sb.append("&lf=");
316:                            sb.append(lbForceSession);
317:                        }
318:                    } else {
319:                        //http://localhost/status?cmd=update&mime=txt&w=node1&l=lb&wf=1&wd=false&ws=false
320:                        if ((workerLb != null)) { // must be configured
321:                            sb.append("&l=");
322:                            sb
323:                                    .append(URLEncoder.encode(workerLb,
324:                                            getCharset()));
325:                        }
326:                        if ((workerLoadFactor != null)) { // >= 1
327:                            sb.append("&wf=");
328:                            sb.append(workerLoadFactor);
329:                        }
330:                        if ((workerDisabled != null)) {
331:                            sb.append("&wd=");
332:                            sb.append(workerDisabled);
333:                        }
334:                        if ((workerStopped != null)) {
335:                            sb.append("&ws=");
336:                            sb.append(workerStopped);
337:                        }
338:                        if ((workerRedirect != null)) { // other worker conrecte lb's
339:                            sb.append("&wr=");
340:                        }
341:                        if ((workerClusterDomain != null)) {
342:                            sb.append("&wc=");
343:                            sb.append(URLEncoder.encode(workerClusterDomain,
344:                                    getCharset()));
345:                        }
346:                    }
347:
348:                } catch (UnsupportedEncodingException e) {
349:                    throw new BuildException("Invalid 'charset' attribute: "
350:                            + getCharset());
351:                }
352:                return sb;
353:            }
354:
355:            /**
356:             * check correct lb and worker pararmeter
357:             */
358:            protected void checkParameter() {
359:                if (worker == null) {
360:                    throw new BuildException("Must specify 'worker' attribute");
361:                }
362:                if (workerType == null) {
363:                    throw new BuildException(
364:                            "Must specify 'workerType' attribute");
365:                }
366:                if ("lb".equals(workerType)) {
367:                    if (lbRecovertime == null && lbRetries == null) {
368:                        throw new BuildException(
369:                                "Must specify at a lb worker either 'lbRecovertime' or"
370:                                        + "'lbRetries' attribute");
371:                    }
372:                    if (lbStickySession == null || lbForceSession == null) {
373:                        throw new BuildException(
374:                                "Must specify at a lb worker either"
375:                                        + "'lbStickySession' and 'lbForceSession' attribute");
376:                    }
377:                    if (null != lbRecovertime && 60 < lbRecovertime.intValue()) {
378:                        throw new BuildException(
379:                                "The 'lbRecovertime' must be greater than 59");
380:                    }
381:                    if (null != lbRetries && 1 < lbRetries.intValue()) {
382:                        throw new BuildException(
383:                                "The 'lbRetries' must be greater than 1");
384:                    }
385:                    isLBMode = true;
386:                } else if ("worker".equals(workerType)) {
387:                    if (workerDisabled == null) {
388:                        throw new BuildException(
389:                                "Must specify at a node worker 'workerDisabled' attribute");
390:                    }
391:                    if (workerStopped == null) {
392:                        throw new BuildException(
393:                                "Must specify at a node worker 'workerStopped' attribute");
394:                    }
395:                    if (workerLoadFactor == null) {
396:                        throw new BuildException(
397:                                "Must specify at a node worker 'workerLoadFactor' attribute");
398:                    }
399:                    if (workerClusterDomain == null) {
400:                        throw new BuildException(
401:                                "Must specify at a node worker 'workerClusterDomain' attribute");
402:                    }
403:                    if (workerRedirect == null) {
404:                        throw new BuildException(
405:                                "Must specify at a node worker 'workerRedirect' attribute");
406:                    }
407:                    if (workerLb == null) {
408:                        throw new BuildException(
409:                                "Must specify 'workerLb' attribute");
410:                    }
411:                    if (workerLoadFactor.intValue() < 1) {
412:                        throw new BuildException(
413:                                "The 'workerLoadFactor' must be greater or equal 1");
414:                    }
415:                    isLBMode = false;
416:                } else {
417:                    throw new BuildException(
418:                            "Only 'lb' and 'worker' supported as workerType attribute");
419:                }
420:            }
421:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.