1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package jgroup.test.performance;
20
21 import java.io.FileOutputStream;
22 import java.io.PrintWriter;
23 import java.rmi.registry.LocateRegistry;
24 import java.rmi.registry.Registry;
25 import java.util.Calendar;
26 import java.util.GregorianCalendar;
27
28 import jgroup.util.Abort;
29 import jgroup.util.Network;
30
31
32
33
34
35
36
37
38
39 public class RMIClient
40 extends Thread
41 {
42
43
44
45
46
47
48
49
50 public static void main(String[] argv)
51 throws Exception
52 {
53 String hostname = null;
54 int port = Registry.REGISTRY_PORT;
55
56 for (int i = 0 ; i < argv.length ; i++) {
57 if (argv[i].equals("-rport")) {
58 if ((i + 1) == argv.length) {
59 System.err.println("Options -rport must be followed by a port number");
60 usage();
61 return;
62 }
63 try {
64 port = Integer.parseInt(argv[++i]);
65 } catch (Exception e) {
66 System.err.println("Value " + argv[i] + " is not a number");
67 usage();
68 return;
69 }
70 } else if (argv[i].startsWith("-")) {
71 System.err.println("Unknown option " + argv[i]);
72 usage();
73 } else {
74 if (hostname != null) {
75 System.err.println("Hostfile already specified");
76 usage();
77 return;
78 }
79 hostname = argv[i];
80 }
81 }
82
83 RMIClient client = new RMIClient();
84 Object[] objs = new Object[] { hostname, new Integer(port) };
85 client.start(objs);
86 }
87
88 private static void usage()
89 {
90 Abort.usage("Usage: rmispeedclient <hostname> [-rport <port number>]");
91 }
92
93
94
95
96
97
98 SpeedTest test;
99
100
101 boolean completed = false;
102
103
104
105
106
107
108
109
110
111
112 public RMIClient()
113 {
114 }
115
116
117
118
119
120
121
122
123
124 public void start(Object[] args)
125 throws Exception
126 {
127
128 if (args == null || args.length != 2)
129 throw new IllegalArgumentException("Arguments required: String");
130 String hostname = (String) args[0];
131 int port = ((Integer) args[1]).intValue();
132
133
134 Registry reg = LocateRegistry.getRegistry(hostname);
135 test = (SpeedTest) reg.lookup("Jgroup/SpeedTest");
136 System.out.println("Obtained remote reference: " + test);
137
138 this.start();
139 }
140
141
142
143
144 public synchronized void run()
145 {
146 try {
147
148 PrintWriter out = null;
149 try {
150 GregorianCalendar gc = new GregorianCalendar();
151 String name = "client." + Network.getLocalHostName() + gc.get(Calendar.YEAR) +
152 gc.get(Calendar.MONTH) + gc.get(Calendar.DAY_OF_MONTH) +
153 "-" + gc.get(Calendar.HOUR_OF_DAY) + gc.get(Calendar.MINUTE)+".log";
154 out = new PrintWriter(new FileOutputStream(name));
155 } catch (Exception e) {
156 e.printStackTrace();
157 }
158
159
160 ClientTest.test1(test, out);
161 ClientTest.test2(test, out);
162
163
164 out.close();
165 completed = true;
166 notify();
167 } catch (Exception e) {
168 e.printStackTrace();
169 }
170 }
171
172
173
174
175 public synchronized void halt()
176 {
177 while (!completed)
178 try { wait(); } catch (Exception e) { }
179 }
180
181 }
182