bottleneck testcase based on rubbos
[bottlenecks.git] / rubbos / app / tomcat-connectors-1.2.32-src / jkstatus / src / share / org / apache / jk / status / JkStatusUpdateLoadbalancerTask.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>/status</code> update loadbalancer command, supported by the
27  * mod_jk status (1.2.20) application.
28  * 
29  * 
30  * @author Peter Rossbach
31  * @version $Revision: 611693 $
32  * @since mod_jk 1.2.20
33  */
34 public class JkStatusUpdateLoadbalancerTask extends AbstractJkStatusTask {
35
36     /**
37      * The descriptive information about this implementation.
38      */
39     private static final String info = "org.apache.jk.status.JkStatusUpdateLoadbalancerTask/1.0";
40
41     protected String loadbalancer ;
42     
43     protected int retries = -1;
44     protected int recoverWaitTime = -1;
45     protected int methodCode = -1;
46     protected String method;
47
48     protected Boolean stickySession ;
49     
50     protected Boolean forceStickySession ;
51    
52     protected int lockCode = -1;
53     protected String lock;
54     protected int maxReplyTimeouts = -1;
55
56     /**
57      * Return descriptive information about this implementation and the
58      * corresponding version number, in the format
59      * <code>&lt;description&gt;/&lt;version&gt;</code>.
60      */
61     public String getInfo() {
62
63         return (info);
64
65     }
66     
67     /**
68      *  
69      */
70     public JkStatusUpdateLoadbalancerTask() {
71         super();
72         setUrl("http://localhost/jkstatus");
73     }
74  
75     /**
76          * @return the forceStickySession
77          */
78         public Boolean getForceStickySession() {
79                 return forceStickySession;
80         }
81
82         /**
83          * @param forceStickySession the forceStickySession to set
84          */
85         public void setForceStickySession(Boolean forceStickySession) {
86                 this.forceStickySession = forceStickySession;
87         }
88
89         /**
90          * @return the loadbalancer
91          */
92         public String getLoadbalancer() {
93                 return loadbalancer;
94         }
95
96         /**
97          * @param loadbalancer the loadbalancer to set
98          */
99         public void setLoadbalancer(String loadbalancer) {
100                 this.loadbalancer = loadbalancer;
101         }
102
103
104         /**
105          * @return the locking
106          */
107         public String getLock() {
108                 return lock;
109         }
110
111         /**
112          * @param locking the locking to set
113          */
114         public void setLock(String locking) {
115                 this.lock = locking;
116         }
117
118         /**
119          * @return the lockingCode
120          */
121         public int getLockCode() {
122                 return lockCode;
123         }
124
125         /**
126          * @param lockingCode the lockingCode to set
127          */
128         public void setLockCode(int lockingCode) {
129                 this.lockCode = lockingCode;
130         }
131
132         /**
133          * @return the method
134          */
135         public String getMethod() {
136                 return method;
137         }
138
139         /**
140          * @param method the method to set
141          */
142         public void setMethod(String method) {
143                 this.method = method;
144         }
145
146         /**
147          * @return the methodCode
148          */
149         public int getMethodCode() {
150                 return methodCode;
151         }
152
153         /**
154          * @param methodCode the methodCode to set
155          */
156         public void setMethodCode(int methodCode) {
157                 this.methodCode = methodCode;
158         }
159
160         /**
161          * @return the recoverWaitTime
162          */
163         public int getRecoverWaitTime() {
164                 return recoverWaitTime;
165         }
166
167         /**
168          * @param recoverWaitTime the recoverWaitTime to set
169          */
170         public void setRecoverWaitTime(int recoverWaitTime) {
171                 this.recoverWaitTime = recoverWaitTime;
172         }
173
174         /**
175          * @return the retries
176          */
177         public int getRetries() {
178                 return retries;
179         }
180
181         /**
182          * @param retries the retries to set
183          */
184         public void setRetries(int retries) {
185                 this.retries = retries;
186         }
187
188         /**
189          * @return the stickySession
190          */
191         public Boolean getStickySession() {
192                 return stickySession;
193         }
194
195         /**
196          * @param stickySession the stickySession to set
197          */
198         public void setStickySession(Boolean stickySession) {
199                 this.stickySession = stickySession;
200         }
201
202         /**
203          * @return the maxReplyTimeouts
204          */
205         public int getMaxReplyTimeouts() {
206                 return maxReplyTimeouts;
207         }
208
209         /**
210          * @param maxReplyTimeouts the maxReplyTimeouts to set
211          */
212         public void setMaxReplyTimeouts(int maxReplyTimeouts) {
213                 this.maxReplyTimeouts = maxReplyTimeouts;
214         }
215
216         /**
217      * Create JkStatus worker update link
218      * <ul>
219      * </b>http://localhost/jkstatus?cmd=update&mime=txt&w=loadbalancer&vlm=1&vll=1&vlr=2&vlt=60&vls=true&vlf=false&vlx=0
220      * <br/>
221      *
222      * 
223      * <br/>Tcp worker parameter:
224      * <br/>
225      * <ul>
226      * <li><b>w:<b/> name loadbalancer</li>
227      * <li><b>vlm:<b/> method (lb strategy)</li>
228      * <li><b>vll:<b/> lock</li>
229      * <li><b>vlr:<b/> retries</li>
230      * <li><b>vlt:<b/> recover wait timeout</li>
231      * <li><b>vls:<b/> sticky session</li>
232      * <li><b>vlf:<b/> force sticky session</li>
233      * <li><b>vlx:<b/> max reply timeouts</li>
234      * </ul>
235      * <ul>
236      * <li>vlm=0 or Requests</li>
237      * <li>vlm=1 or Traffic</li>
238      * <li>vlm=2 or Busyness</li>
239      * <li>vlm=3 or Sessions</li>
240      * </ul>
241      * <ul>
242      * <li>vll=0 or Optimistic</li>
243      * <li>vll=1 or Pessimistic</li>
244      * </ul>
245      * 
246      * @return create jkstatus update worker link
247      */
248     protected StringBuffer createLink() {
249         // Building URL
250         StringBuffer sb = new StringBuffer();
251         try {
252             sb.append("?cmd=update&mime=txt");
253             sb.append("&w=");
254             sb.append(URLEncoder.encode(loadbalancer, getCharset()));
255             if (stickySession != null) { 
256                                 sb.append("&vls=");
257                                 sb.append(stickySession);
258                         }
259             if (forceStickySession != null) { 
260                                 sb.append("&vlf=");
261                                 sb.append(forceStickySession);
262                         }
263                         if (retries >= 0) {
264                                 sb.append("&vlr=");
265                                 sb.append(retries);
266                         }
267                         if (recoverWaitTime >= 0) {
268                                 sb.append("&vlt=");
269                                 sb.append(recoverWaitTime);
270                         }
271                         if (method == null && methodCode >= 0 && methodCode < 4) {
272                                 sb.append("&vlm=");
273                                 sb.append(methodCode);
274                         }
275             if (method != null) { 
276                                 sb.append("&vlm=");
277                                 sb.append(method);
278                         }
279                         if (lock == null && lockCode >= 0 && lockCode < 2) {
280                                 sb.append("&vll=");
281                                 sb.append(lockCode);
282                         }
283             if (lock != null) { 
284                                 sb.append("&vll=");
285                                 sb.append(lock);
286                         }
287                         if (maxReplyTimeouts >= 0) {
288                                 sb.append("&vlx=");
289                                 sb.append(maxReplyTimeouts);
290                         }
291             
292         } catch (UnsupportedEncodingException e) {
293             throw new BuildException("Invalid 'charset' attribute: "
294                     + getCharset());
295         }
296         return sb;
297     }
298
299     /**
300          * check correct lb and worker pararmeter
301          */
302     protected void checkParameter() {
303         if (loadbalancer == null) {
304             throw new BuildException("Must specify 'loadbalancer' attribute");
305         }
306     }
307 }