8000 clients to support distributed communication (trial 1) · rpytel1/distributed-algorithms@0a9fa28 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0a9fa28

Browse files
author
LENOVO-PC\Vasilis
committed
clients to support distributed communication (trial 1)
1 parent 37563a2 commit 0a9fa28

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

Assignment3/src/assignment3/server/Client1.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.io.IOException;
55
import java.rmi.AlreadyBoundException;
66
import java.rmi.NotBoundException;
7+
import java.rmi.RemoteException;
78
import java.rmi.registry.LocateRegistry;
89
import java.rmi.registry.Registry;
910
import java.util.ArrayList;
@@ -31,7 +32,7 @@ public static void main(String[] args) throws AlreadyBoundException, NotBoundExc
3132
links = new HashMap<Integer, List<Link>>();
3233
initializeEdges();
3334
// "clients" files contain the name of the remote processes used
34-
BufferedReader br = new BufferedReader(new FileReader("tests/nodes1.txt"));
35+
BufferedReader br = new BufferedReader(new FileReader("tests/nodes2.txt"));
3536
String line = br.readLine();
3637
numProc = Integer.parseInt(line);
3738
localProc = 0;
@@ -48,7 +49,16 @@ public static void main(String[] args) throws AlreadyBoundException, NotBoundExc
4849
localIDS.add(i);
4950
}
5051
else{
51-
registry.bind("//145.94.233.58:"+Constant.RMI_PORT+"/"+split_line[0], new Node(i, new PriorityQueue<Link>(links.get(i))));
52+
boolean success = false;
53+
while (!success){
54+
try{
55+
registry.bind("//145.94.233.58:"+Constant.RMI_PORT+"/"+split_line[0], new Node(i, new PriorityQueue<Link>(links.get(i))));
56+
success = true;
57+
}
58+
catch (RemoteException e) {
59+
e.printStackTrace();
60+
}
61+
}
5262
local[i] = 0;
5363

5464
}
@@ -63,7 +73,7 @@ public static void main(String[] args) throws AlreadyBoundException, NotBoundExc
6373
}
6474

6575
public static void initializeEdges() throws IOException{
66-
BufferedReader br = new BufferedReader(new FileReader("tests/edges1.txt"));
76+
BufferedReader br = new BufferedReader(new FileReader("tests/edges2.txt"));
6777
String line;
6878
int node1;
6979
int node2;
@@ -118,7 +128,7 @@ public static void setRegistry() throws NotBoundException, NumberFormatException
118128
System.out.println("Press enter to continue");
119129
Scanner scan = new Scanner(System.in);
120130
scan.nextLine();
121-
myThreads[0].start();
131+
myThreads[0].start();
122132
myThreads[1].start();
123133
}
124134
}

Assignment3/src/assignment3/server/Client2.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,16 @@
44
import java.io.IOException;
55
import java.rmi.AlreadyBoundException;
66
import java.rmi.NotBoundException;
7+
import java.rmi.RemoteException;
78
import java.rmi.registry.LocateRegistry;
89
import java.rmi.registry.Registry;
910
import java.util.ArrayList;
11+
import java.util.PriorityQueue;
1012
import java.util.Scanner;
13+
14+
import assignment3.link.Link;
1115
import assignment3.node.IComponent;
16+
import assignment3.node.Node;
1217

1318
public class Client2 {
1419
private static IComponent[] RMI_IDS; // Array with the remote processes
@@ -48,7 +53,18 @@ public static void main(String[] args) throws AlreadyBoundException, NotBoundExc
4853
}
4954

5055
public static void setRegistry() throws NotBoundException, NumberFormatException, IOException{
51-
Registry registry = LocateRegistry.getRegistry("145.94.186.211", Constant.RMI_PORT);
56+
boolean success = false;
57+
Registry registry = null;
58+
while (!success){
59+
try{
60+
registry = LocateRegistry.getRegistry("145.94.186.211", Constant.RMI_PORT);
61+
success = true;
62+
}
63+
catch (RemoteException e) {
64+
e.printStackTrace();
65+
}
66+
}
67+
//Registry registry = LocateRegistry.getRegistry("145.94.186.211", Constant.RMI_PORT);
5268
RMI_IDS = new IComponent[numProc]; // the remote process array is instantiated
5369
Thread[] myThreads = new Thread[numProc]; // and numProc number of threads are created
5470
for(int i=0; i<numProc; i++){

0 commit comments

Comments
 (0)
0