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