bottleneck testcase based on rubbos
[bottlenecks.git] / rubbos / app / tomcat-connectors-1.2.32-src / jkstatus / src / share / org / apache / jk / status / JkStatusResetTask.java
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements.  See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License.  You may obtain a copy of the License at
8  * 
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  * 
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 package org.apache.jk.status;
19
20 import java.io.UnsupportedEncodingException;
21 import java.net.URLEncoder;
22
23 import org.apache.tools.ant.BuildException;
24
25 /**
26  * Ant task that implements the <code>/jkstatus?cmd=reset&amp;w=loadbalancer</code> command, supported by the
27  * mod_jk status (1.2.20) application.
28  * 
29  * @author Peter Rossbach
30  * @version $Revision: 485242 $
31  * @since mod_jk 1.2.20
32  */
33 public class JkStatusResetTask extends AbstractJkStatusTask {
34
35         /**
36      * The descriptive information about this implementation.
37      */
38     private static final String info = "org.apache.jk.status.JkStatusResetTask/1.1";
39
40     private String worker;
41     private String loadbalancer;
42
43     /**
44      *  
45      */
46     public JkStatusResetTask() {
47         super();
48         setUrl("http://localhost/jkstatus");
49     }
50
51     /**
52      * Return descriptive information about this implementation and the
53      * corresponding version number, in the format
54      * <code>&lt;description&gt;/&lt;version&gt;</code>.
55      */
56     public String getInfo() {
57
58         return (info);
59
60     }
61     
62     /**
63          * @return the loadbalancer
64          */
65         public String getLoadbalancer() {
66                 return loadbalancer;
67         }
68
69
70         /**
71          * @param loadbalancer the loadbalancer to set
72          */
73         public void setLoadbalancer(String loadbalancer) {
74                 this.loadbalancer = loadbalancer;
75         }
76
77
78         /**
79          * @return the worker
80          */
81         public String getWorker() {
82                 return worker;
83         }
84
85
86         /**
87          * @param worker the worker to set
88          */
89         public void setWorker(String worker) {
90                 this.worker = worker;
91         }
92
93
94         /**
95      * Create jkstatus reset link
96      * <ul>
97      * <li><b>loadbalancer example:
98      * </b>http://localhost/jkstatus?cmd=reset&mime=txt&w=loadbalancer</li>
99      * <li><b>loadbalancer + sub worker example:
100      * </b>http://localhost/jkstatus?cmd=reset&mime=txt&w=loadbalancer&sw=node01</li>
101      * </ul>
102      * 
103      * @return create jkstatus reset link
104      */
105     protected StringBuffer createLink() {
106         // Building URL
107         StringBuffer sb = new StringBuffer();
108         try {
109             sb.append("?cmd=reset");
110             sb.append("&mime=txt");
111             sb.append("&w=");
112             sb.append(URLEncoder.encode(loadbalancer, getCharset()));
113             if(worker != null) {
114                 sb.append("&sw=");
115                 sb.append(URLEncoder.encode(worker, getCharset()));             
116                 }
117
118         } catch (UnsupportedEncodingException e) {
119             throw new BuildException("Invalid 'charset' attribute: "
120                     + getCharset());
121         }
122         return sb;
123     }
124
125     /**
126      * check correct pararmeter
127      */
128     protected void checkParameter() {
129         if (loadbalancer == null) {
130             throw new BuildException("Must specify 'loadbalanacer' attribute");
131         }
132     }
133 }