5
5
import java .io .IOException ;
6
6
import java .rmi .AlreadyBoundException ;
7
7
import java .rmi .NotBoundException ;
8
+ import java .rmi .RMISecurityManager ;
8
9
import java .rmi .registry .LocateRegistry ;
9
10
import java .rmi .registry .Registry ;
10
11
import java .util .ArrayList ;
@@ -36,12 +37,30 @@ public class Client1 {
36
37
private static ArrayList <Integer > localIDS ; // ids of local processes
37
38
38
39
public static void main (String [] args ) throws AlreadyBoundException , NotBoundException , IOException , InterruptedException {
39
- Registry registry = LocateRegistry .getRegistry ("localhost" , Constant .RMI_PORT );
40
+ /*if (System.getSecurityManager() == null) {
41
+ System.setSecurityManager(new RMISecurityManager());
42
+ }*/
43
+ //Registry registry = LocateRegistry.getRegistry("localhost", Constant.RMI_PORT);
44
+ Registry registry = LocateRegistry .createRegistry (Constant .RMI_PORT );
40
45
41
46
// "clients" files contain the name of the remote processes used
42
47
BufferedReader br = new BufferedReader (new FileReader ("tests/clients3.txt" ));
43
48
String line = "" ;
44
- numProc = registry .list ().length ;
49
+ numProc = 0 ; // added later
50
+ while ((line = br .readLine ()) != null ) {
51
+ String [] split_line = line .split (" " );
52
+ if (Integer .parseInt (split_line [1 ]) == 1 ){
53
+ registry .bind ("//localhost:" +Constant .RMI_PORT +"/" +split_line [0 ], new RemoteEntityImpl ());
54
+ }
55
+ /*else{
56
+ registry.bind("//145.94.185.243:"+Constant.RMI_PORT+"/"+split_line[0], new RemoteEntityImpl());
57
+ }*/
58
+ numProc ++;
59
+ }
60
+ br .close ();
61
+ br = new BufferedReader (new FileReader ("tests/clients3.txt" ));
62
+ line = "" ;
63
+ //numProc = registry.list().length;
45
64
localProc = 0 ;
46
65
int i = 0 ;
47
66
local = new int [numProc ];
@@ -58,6 +77,9 @@ public static void main(String[] args) throws AlreadyBoundException, NotBoundExc
58
77
}
59
78
br .close ();
60
79
setRegistry ();
80
+ System .out .println ("Press enter to continue" );
81
+ Scanner scan = new Scanner (System .in );
82
+ scan .nextLine ();
61
83
System .out .println ("Client1 started" );
62
84
}
63
85
@@ -66,7 +88,10 @@ public static void setRegistry() throws NotBoundException, NumberFormatException
66
88
RMI_IDS = new IRemoteEntity [numProc ]; // the remote process array is instantiated
67
89
Thread [] myThreads = new Thread [localProc ]; // and localProc number of threads are created
68
90
for (int i =0 ; i <numProc ; i ++){
69
- RMI_IDS [i ] = (IRemoteEntity ) registry .lookup (registry .list ()[i ]);
91
+ if (local [i ]==1 )
92
+ RMI_IDS [i ] = (IRemoteEntity ) registry .lookup (registry .list ()[i ]);
93
+ else
94
+ RMI_IDS [i ] = (IRemoteEntity ) java .rmi .Naming .lookup ("//145.94.185.243:" +Constant .RMI_PORT +"/Client" +(i +1 ));
70
95
}
71
96
72
97
// "messages" files contain the messages to be sent and are constructed in the following way
0 commit comments