2
2
import java .io .BufferedReader ;
3
3
import java .io .FileReader ;
4
4
import java .io .IOException ;
5
+ import java .rmi .AccessException ;
5
6
import java .rmi .AlreadyBoundException ;
6
7
import java .rmi .NotBoundException ;
7
8
import java .rmi .RemoteException ;
@@ -32,7 +33,7 @@ public static void main(String[] args) throws AlreadyBoundException, NotBoundExc
32
33
links = new HashMap <Integer , List <Link >>();
33
34
initializeEdges ();
34
35
// "clients" files contain the name of the remote processes used
35
- Buffe
10000
redReader br = new BufferedReader (new FileReader ("tests/nodes2 .txt" ));
36
+ BufferedReader br = new BufferedReader (new FileReader ("tests/nodes1 .txt" ));
36
37
String line = br .readLine ();
37
38
numProc = Integer .parseInt (line );
38
39
localProc = 0 ;
@@ -52,11 +53,13 @@ public static void main(String[] args) throws AlreadyBoundException, NotBoundExc
52
53
boolean success = false ;
53
54
while (!success ){
54
55
try {
55
- registry .bind ("//145.94.233.58 :" +Constant .RMI_PORT +"/" +split_line [0 ], new Node (i , new PriorityQueue <Link >(links .get (i ))));
56
+ registry .bind ("//145.94.234.109 :" +Constant .RMI_PORT +"/" +split_line [0 ], new Node (i , new PriorityQueue <Link >(links .get (i ))));
56
57
success = true ;
58
+ System .out .println (" Binding done for " + split_line [0 ]);
57
59
}
58
- catch (RemoteException e ) {
59
- e .printStackTrace ();
60
+ catch (Exception e ) {
61
+ //e.printStackTrace();
62
+ System .err .println ("Waiting for client 2..." );
60
63
}
61
64
}
62
65
local [i ] = 0 ;
@@ -65,15 +68,15 @@ public static void main(String[] args) throws AlreadyBoundException, NotBoundExc
65
68
i ++;
66
69
}
67
70
br .close ();
68
- System .out .println ("Press enter to continue" );
69
- Scanner scan = new Scanner (System .in );
70
- scan .nextLine ();
71
+ // System.out.println("Press enter to continue");
72
+ // Scanner scan = new Scanner(System.in);
73
+ // scan.nextLine();
71
74
setRegistry ();
72
75
System .out .println ("Client 1 started" );
73
76
}
74
77
75
78
public static void initializeEdges () throws IOException {
76
- BufferedReader br = new BufferedReader (new FileReader ("tests/edges2 .txt" ));
79
+ BufferedReader br = new BufferedReader (new FileReader ("tests/edges1 .txt" ));
77
80
String line ;
78
81
int node1 ;
79
82
int node2 ;
@@ -113,8 +116,19 @@ public static void setRegistry() throws NotBoundException, NumberFormatException
113
116
Registry registry = LocateRegistry .getRegistry ("localhost" , Constant .RMI_PORT );
114
117
RMI_IDS = new IComponent [numProc ]; // the remote process array is instantiated
115
118
Thread [] myThreads = new Thread [numProc ]; // and numProc number of threads are created
119
+ boolean success ;
116
120
for (int i =0 ; i <numProc ; i ++){
117
- RMI_IDS [i ] = (IComponent ) registry .lookup (registry .list ()[i ]);
121
+ success = false ;
122
+ while (!success ){
123
+ try {
124
+ RMI_IDS [i ] = (IComponent ) registry .lookup (registry .list ()[i ]);
125
+ success = true ;
126
+ System .out .println ("process " + i + " found in the registry" );
127
+ }
128
+ catch (Exception e ){
129
+ e .printStackTrace ();
130
+ }
131
+ }
118
132
}
119
133
120
134
for (int i =0 ; i <localProc ; i ++){
@@ -125,10 +139,22 @@ public static void setRegistry() throws NotBoundException, NumberFormatException
125
139
myThreads [i ] = new Thread (p ); // and a new thread is created
126
140
}
127
141
128
- System .out .println ("Press enter to continue" );
129
- Scanner scan = new Scanner (System .in );
130
- scan .nextLine ();
142
+ //System.out.println("Press enter to continue");
143
+ //Scanner scan = new Scanner(System.in);
144
+ //scan.nextLine();
145
+ for (int i =0 ; i <numProc ; i ++){
146
+ success = false ;
147
+ while (!success ){
148
+ try {
149
+ RMI_IDS [localIDS .get (i )].isAlive ();
150
+ success = true ;
151
+ }
152
+ catch (RemoteException e ){
153
+ System .err .println ("Client 2 not initialized its processes yet" );
154
+ //e.printStackTrace();
155
+ }
156
+ }
157
+ }
131
158
myThreads [0 ].start ();
132
- myThreads [1 ].start ();
133
159
}
134
160
}
0 commit comments