KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > wings > recorder > Client


1 /*
2  * $Id: Client.java,v 1.3 2004/12/01 07:54:26 hengels Exp $
3  * Copyright 2000,2005 wingS development team.
4  *
5  * This file is part of wingS (http://www.j-wings.org).
6  *
7  * wingS is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU Lesser General Public License
9  * as published by the Free Software Foundation; either version 2.1
10  * of the License, or (at your option) any later version.
11  *
12  * Please see COPYING for the complete licence.
13  */

14 package org.wings.recorder;
15
16 public class Client
17         extends Thread JavaDoc {
18     private Script script;
19     protected String JavaDoc userid;
20     protected String JavaDoc 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 JavaDoc getUserid() { return userid; }
30
31     public void setUserid(String JavaDoc userid) { this.userid = userid; }
32
33     public void setPasswd(String JavaDoc 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 JavaDoc e) { /* shit happens */ }
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 JavaDoc 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