KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > demo > poa_monitor > client > RequestGenerator


1 package demo.poa_monitor.client;
2
3
4
5 import demo.poa_monitor.foox.*;
6
7
8
9 public class RequestGenerator extends Thread JavaDoc {
10
11     boolean active = true;
12
13     private Foo foo;
14
15     private boolean firstObjectContact;
16
17     public RequestGenerator(Foo _foo, boolean _firstObjectContact) {
18
19         foo = _foo;
20
21         firstObjectContact = _firstObjectContact;
22
23     }
24
25     public void run() {
26
27         long startTime = 0;
28
29         long stopTime = 0;
30
31         while (active) {
32
33             try {
34
35                 int costs = (int) (Math.random() * Client.cost);
36
37                 startTime = System.currentTimeMillis();
38
39                 foo.compute(costs);
40
41                 stopTime = System.currentTimeMillis();
42
43                 Client.addTime((int)(stopTime-startTime), costs, firstObjectContact);
44
45                 firstObjectContact = false;
46
47                 
48
49             } catch (org.omg.CORBA.SystemException JavaDoc e) {
50
51                 System.out.println("system exception received: "+e);
52                                 e.printStackTrace();
53             } catch (Throwable JavaDoc e) {
54
55                 System.out.println("exception received: "+e);
56
57                 e.printStackTrace();
58
59             }
60
61             try {
62
63                 if (Client.speed != 0) sleep((int) (Math.random() * Client.speed));
64
65             } catch (InterruptedException JavaDoc e) {
66
67             }
68
69         }
70
71     }
72
73 }
74
75
Popular Tags