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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 package org.apache.jk.status;
20 import java.io.UnsupportedEncodingException;
21 import java.net.URLEncoder;
23 import org.apache.tools.ant.BuildException;
26 * Ant task that implements the <code>/status</code> update loadbalancer command, supported by the
27 * mod_jk status (1.2.20) application.
30 * @author Peter Rossbach
31 * @version $Revision: 611693 $
32 * @since mod_jk 1.2.20
34 public class JkStatusUpdateLoadbalancerTask extends AbstractJkStatusTask {
37 * The descriptive information about this implementation.
39 private static final String info = "org.apache.jk.status.JkStatusUpdateLoadbalancerTask/1.0";
41 protected String loadbalancer ;
43 protected int retries = -1;
44 protected int recoverWaitTime = -1;
45 protected int methodCode = -1;
46 protected String method;
48 protected Boolean stickySession ;
50 protected Boolean forceStickySession ;
52 protected int lockCode = -1;
53 protected String lock;
54 protected int maxReplyTimeouts = -1;
57 * Return descriptive information about this implementation and the
58 * corresponding version number, in the format
59 * <code><description>/<version></code>.
61 public String getInfo() {
70 public JkStatusUpdateLoadbalancerTask() {
72 setUrl("http://localhost/jkstatus");
76 * @return the forceStickySession
78 public Boolean getForceStickySession() {
79 return forceStickySession;
83 * @param forceStickySession the forceStickySession to set
85 public void setForceStickySession(Boolean forceStickySession) {
86 this.forceStickySession = forceStickySession;
90 * @return the loadbalancer
92 public String getLoadbalancer() {
97 * @param loadbalancer the loadbalancer to set
99 public void setLoadbalancer(String loadbalancer) {
100 this.loadbalancer = loadbalancer;
105 * @return the locking
107 public String getLock() {
112 * @param locking the locking to set
114 public void setLock(String locking) {
119 * @return the lockingCode
121 public int getLockCode() {
126 * @param lockingCode the lockingCode to set
128 public void setLockCode(int lockingCode) {
129 this.lockCode = lockingCode;
135 public String getMethod() {
140 * @param method the method to set
142 public void setMethod(String method) {
143 this.method = method;
147 * @return the methodCode
149 public int getMethodCode() {
154 * @param methodCode the methodCode to set
156 public void setMethodCode(int methodCode) {
157 this.methodCode = methodCode;
161 * @return the recoverWaitTime
163 public int getRecoverWaitTime() {
164 return recoverWaitTime;
168 * @param recoverWaitTime the recoverWaitTime to set
170 public void setRecoverWaitTime(int recoverWaitTime) {
171 this.recoverWaitTime = recoverWaitTime;
175 * @return the retries
177 public int getRetries() {
182 * @param retries the retries to set
184 public void setRetries(int retries) {
185 this.retries = retries;
189 * @return the stickySession
191 public Boolean getStickySession() {
192 return stickySession;
196 * @param stickySession the stickySession to set
198 public void setStickySession(Boolean stickySession) {
199 this.stickySession = stickySession;
203 * @return the maxReplyTimeouts
205 public int getMaxReplyTimeouts() {
206 return maxReplyTimeouts;
210 * @param maxReplyTimeouts the maxReplyTimeouts to set
212 public void setMaxReplyTimeouts(int maxReplyTimeouts) {
213 this.maxReplyTimeouts = maxReplyTimeouts;
217 * Create JkStatus worker update link
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
223 * <br/>Tcp worker parameter:
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>
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>
242 * <li>vll=0 or Optimistic</li>
243 * <li>vll=1 or Pessimistic</li>
246 * @return create jkstatus update worker link
248 protected StringBuffer createLink() {
250 StringBuffer sb = new StringBuffer();
252 sb.append("?cmd=update&mime=txt");
254 sb.append(URLEncoder.encode(loadbalancer, getCharset()));
255 if (stickySession != null) {
257 sb.append(stickySession);
259 if (forceStickySession != null) {
261 sb.append(forceStickySession);
267 if (recoverWaitTime >= 0) {
269 sb.append(recoverWaitTime);
271 if (method == null && methodCode >= 0 && methodCode < 4) {
273 sb.append(methodCode);
275 if (method != null) {
279 if (lock == null && lockCode >= 0 && lockCode < 2) {
287 if (maxReplyTimeouts >= 0) {
289 sb.append(maxReplyTimeouts);
292 } catch (UnsupportedEncodingException e) {
293 throw new BuildException("Invalid 'charset' attribute: "
300 * check correct lb and worker pararmeter
302 protected void checkParameter() {
303 if (loadbalancer == null) {
304 throw new BuildException("Must specify 'loadbalancer' attribute");