1 14 package org.wings.recorder; 15 16 public class Client 17 extends Thread { 18 private Script script; 19 protected String userid; 20 protected String passwd; 21 private int initialDelay = 0; 22 private int iterations = 1; 23 private int currentIteration = 0; 24 25 public void init(Script script) { 26 this.script = script; 27 } 28 29 public String getUserid() { return userid; } 30 31 public void setUserid(String userid) { this.userid = userid; } 32 33 public void setPasswd(String passwd) { this.passwd = passwd; } 34 35 public void setInitialDelay(int initialDelay) { 36 this.initialDelay = initialDelay; 37 } 38 39 public void setIterations(int iterations) { 40 this.iterations = iterations; 41 } 42 43 public int getCurrentIteration() { return currentIteration; } 44 45 public void run() { 46 try { 47 if (initialDelay > 0) 48 sleep(initialDelay); 49 } catch (InterruptedException e) { } 50 51 login(); 52 53 for (currentIteration = 1; currentIteration <= iterations; currentIteration++) { 54 try { 55 long millis = System.currentTimeMillis(); 56 System.out.println("CLIENT: " + getUserid() + " begin (" + currentIteration + ")"); 57 script.execute(); 58 System.out.println("CLIENT: " + getUserid() + " end (" + currentIteration + ") after " + 59 (System.currentTimeMillis() - millis) + "ms"); 60 } catch (Exception e) { 61 System.out.println("CLIENT: " + getUserid() + " in iteration " + currentIteration 62 + " threw exception: " + 63 e.getClass().getName() + ": " + e.getMessage()); 64 System.err.println(e.getMessage()); 65 e.printStackTrace(System.err); 66 } 67 } 68 } 69 70 protected void login() {} 71 } 72 73 74 | Popular Tags |