1 17 18 package org.apache.catalina.ant; 19 20 import java.io.UnsupportedEncodingException ; 21 import java.net.URLEncoder ; 22 23 import org.apache.tools.ant.BuildException; 24 25 33 public class JKStatusUpdateTask extends AbstractCatalinaTask { 34 35 private String worker = "lb"; 36 37 private String workerType = "lb"; 38 39 private int internalid = 0; 40 41 private Integer lbRetries; 42 43 private Integer lbRecovertime; 44 45 private Boolean lbStickySession = Boolean.TRUE; 46 47 private Boolean lbForceSession = Boolean.FALSE; 48 49 private Integer workerLoadFactor; 50 51 private String workerRedirect; 52 53 private String workerClusterDomain; 54 55 private Boolean workerDisabled = Boolean.FALSE; 56 57 private Boolean workerStopped = Boolean.FALSE; 58 59 private boolean isLBMode = true; 60 61 private String workerLb; 62 63 66 public JKStatusUpdateTask() { 67 super(); 68 setUrl("http://localhost/status"); 69 } 70 71 74 public int getInternalid() { 75 return internalid; 76 } 77 78 82 public void setInternalid(int internalid) { 83 this.internalid = internalid; 84 } 85 86 89 public Boolean getLbForceSession() { 90 return lbForceSession; 91 } 92 93 97 public void setLbForceSession(Boolean lbForceSession) { 98 this.lbForceSession = lbForceSession; 99 } 100 101 104 public Integer getLbRecovertime() { 105 return lbRecovertime; 106 } 107 108 112 public void setLbRecovertime(Integer lbRecovertime) { 113 this.lbRecovertime = lbRecovertime; 114 } 115 116 119 public Integer getLbRetries() { 120 return lbRetries; 121 } 122 123 127 public void setLbRetries(Integer lbRetries) { 128 this.lbRetries = lbRetries; 129 } 130 131 134 public Boolean getLbStickySession() { 135 return lbStickySession; 136 } 137 138 142 public void setLbStickySession(Boolean lbStickySession) { 143 this.lbStickySession = lbStickySession; 144 } 145 146 149 public String getWorker() { 150 return worker; 151 } 152 153 157 public void setWorker(String worker) { 158 this.worker = worker; 159 } 160 161 164 public String getWorkerType() { 165 return workerType; 166 } 167 168 172 public void setWorkerType(String workerType) { 173 this.workerType = workerType; 174 } 175 176 179 public String getWorkerLb() { 180 return workerLb; 181 } 182 183 187 public void setWorkerLb(String workerLb) { 188 this.workerLb = workerLb; 189 } 190 191 194 public String getWorkerClusterDomain() { 195 return workerClusterDomain; 196 } 197 198 202 public void setWorkerClusterDomain(String workerClusterDomain) { 203 this.workerClusterDomain = workerClusterDomain; 204 } 205 206 209 public Boolean getWorkerDisabled() { 210 return workerDisabled; 211 } 212 213 217 public void setWorkerDisabled(Boolean workerDisabled) { 218 this.workerDisabled = workerDisabled; 219 } 220 221 224 public Boolean getWorkerStopped() { 225 return workerStopped; 226 } 227 228 231 public void setWorkerStopped(Boolean workerStopped) { 232 this.workerStopped = workerStopped; 233 } 234 235 238 public Integer getWorkerLoadFactor() { 239 return workerLoadFactor; 240 } 241 242 246 public void setWorkerLoadFactor(Integer workerLoadFactor) { 247 this.workerLoadFactor = workerLoadFactor; 248 } 249 250 253 public String getWorkerRedirect() { 254 return workerRedirect; 255 } 256 257 261 public void setWorkerRedirect(String workerRedirect) { 262 this.workerRedirect = workerRedirect; 263 } 264 265 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 292 private StringBuffer createLink() { 293 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 if ((lbRetries != null)) { sb.append("&lr="); 304 sb.append(lbRetries); 305 } 306 if ((lbRecovertime != null)) { sb.append("<="); 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 if ((workerLb != null)) { sb.append("&l="); 322 sb.append(URLEncoder.encode(workerLb, getCharset())); 323 } 324 if ((workerLoadFactor != null)) { sb.append("&wf="); 326 sb.append(workerLoadFactor); 327 } 328 if ((workerDisabled != null)) { 329 sb.append("&wd="); 330 sb.append(workerDisabled); 331 } 332 if ((workerStopped != null)) { 333 sb.append("&ws="); 334 sb.append(workerStopped); 335 } 336 if ((workerRedirect != null)) { sb.append("&wr="); 338 } 339 if ((workerClusterDomain != null)) { 340 sb.append("&wc="); 341 sb.append(URLEncoder.encode(workerClusterDomain, 342 getCharset())); 343 } 344 } 345 346 } catch (UnsupportedEncodingException e) { 347 throw new BuildException("Invalid 'charset' attribute: " 348 + getCharset()); 349 } 350 return sb; 351 } 352 353 356 protected void checkParameter() { 357 if (worker == null) { 358 throw new BuildException("Must specify 'worker' attribute"); 359 } 360 if (workerType == null) { 361 throw new BuildException("Must specify 'workerType' attribute"); 362 } 363 if ("lb".equals(workerType)) { 364 if (lbRecovertime == null && lbRetries == null) { 365 throw new BuildException( 366 "Must specify at a lb worker either 'lbRecovertime' or" 367 + "'lbRetries' attribute"); 368 } 369 if (lbStickySession == null || lbForceSession == null) { 370 throw new BuildException("Must specify at a lb worker either" 371 + "'lbStickySession' and 'lbForceSession' attribute"); 372 } 373 if (null != lbRecovertime && 60 < lbRecovertime.intValue()) { 374 throw new BuildException( 375 "The 'lbRecovertime' must be greater than 59"); 376 } 377 if (null != lbRetries && 1 < lbRetries.intValue()) { 378 throw new BuildException( 379 "The 'lbRetries' must be greater than 1"); 380 } 381 isLBMode = true; 382 } else if ("worker".equals(workerType)) { 383 if (workerDisabled == null) { 384 throw new BuildException( 385 "Must specify at a node worker 'workerDisabled' attribute"); 386 } 387 if (workerStopped == null) { 388 throw new BuildException( 389 "Must specify at a node worker 'workerStopped' attribute"); 390 } 391 if (workerLoadFactor == null ) { 392 throw new BuildException( 393 "Must specify at a node worker 'workerLoadFactor' attribute"); 394 } 395 if (workerClusterDomain == null) { 396 throw new BuildException( 397 "Must specify at a node worker 'workerClusterDomain' attribute"); 398 } 399 if (workerRedirect == null) { 400 throw new BuildException( 401 "Must specify at a node worker 'workerRedirect' attribute"); 402 } 403 if (workerLb == null) { 404 throw new BuildException("Must specify 'workerLb' attribute"); 405 } 406 if (workerLoadFactor.intValue() < 1) { 407 throw new BuildException( 408 "The 'workerLoadFactor' must be greater or equal 1"); 409 } 410 isLBMode = false; 411 } else { 412 throw new BuildException( 413 "Only 'lb' and 'worker' supported as workerType attribute"); 414 } 415 } 416 } | Popular Tags |