-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCongressClient.java
More file actions
63 lines (58 loc) · 2.02 KB
/
CongressClient.java
File metadata and controls
63 lines (58 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import java.rmi.*;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.util.Random;
public class CongressClient {
public static void main(String[] args) throws Exception {
//main argument : (int) port => the port to locate the RMI registry
int port = 9811;
try{
port = Integer.valueOf(args[0]);
}
catch (IndexOutOfBoundsException e){
System.out.println("usage: java CongressClient port");
System.exit(1);
}
CongressService serverObj = null;
Remote remoteObj;
try {
Registry r = LocateRegistry.getRegistry(port);
remoteObj = r.lookup("CONGRESS-SERVER");
serverObj = (CongressService) remoteObj;
}
catch (UnknownHostException e){
e.printStackTrace();
System.exit(1);
}
catch (RemoteException e){
System.out.println("Connection failed.");
System.exit(1);
}
int i;
int day;
int session;
int participationSlot;
int speakerId = 1000;
Random randomGen = new Random();
for(i = 0; i < 40; i++){
day = randomGen.nextInt(3) + 1;
session = randomGen.nextInt(12) + 1;
participationSlot = randomGen.nextInt(5) + 1;
serverObj.registerSpeaker("Speaker " + speakerId, day, session, participationSlot);
speakerId++;
}
for(i = 0; i < 40; i++){
day = randomGen.nextInt(3) + 1;
session = randomGen.nextInt(12) + 1;
serverObj.registerSpeakerOnAnyParticipationSlot("Speaker " + speakerId, day, session);
speakerId++;
}
for(i = 0; i < 40; i++){
day = randomGen.nextInt(3) + 1;
serverObj.registerSpeakerOnAnySession("Speaker " + speakerId, day);
speakerId++;
}
String congressSchedule = serverObj.getSchedule();
System.out.println(congressSchedule);
}
}