8000 Distributed trial 2 · rpytel1/distributed-algorithms@c330bb2 · GitHub
[go: up one dir, main page]

Skip to content

Commit c330bb2

Browse files
author
LENOVO-PC\Vasilis
10000 committed
Distributed trial 2
1 parent 0a9fa28 commit c330bb2

File tree

4 files changed

+70
-24
lines changed

4 files changed

+70
-24
lines changed

Assignment3/src/assignment3/node/IComponent.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public interface IComponent extends Remote {
1414
public void receiveReport(Message message, Link link) throws RemoteException ;
1515
public void receiveChangeRoot(Message message, Link link) throws RemoteException ;
1616
public void setEntities(IComponent[] entities) throws RemoteException ;
17-
public void wakeUp() throws RemoteException ;
17+
public void wakeUp() throws RemoteException;
18+
public void isAlive() throws RemoteException;
1819

1920
}

Assignment3/src/assignment3/node/Node.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,4 +516,9 @@ public synchronized void receiveChangeRoot(Message message, Link link) throws Re
516516
public void setEntities(IComponent[] entities) throws RemoteException {
517517
nodes = entities;
518518
}
519+
520+
@Override
521+
public void isAlive() throws RemoteException{
522+
System.out.println("Node "+ id+ " is up");
523+
}
519524
}

Assignment3/src/assignment3/server/Client1.java

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import java.io.BufferedReader;
33
import java.io.FileReader;
44
import java.io.IOException;
5+
import java.rmi.AccessException;
56
import java.rmi.AlreadyBoundException;
67
import java.rmi.NotBoundException;
78
import java.rmi.RemoteException;
@@ -32,7 +33,7 @@ public static void main(String[] args) throws AlreadyBoundException, NotBoundExc
3233
links = new HashMap<Integer, List<Link>>();
3334
initializeEdges();
3435
// "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"));
3637
String line = br.readLine();
3738
numProc = Integer.parseInt(line);
3839
localProc = 0;
@@ -52,11 +53,13 @@ public static void main(String[] args) throws AlreadyBoundException, NotBoundExc
5253
boolean success = false;
5354
while (!success){
5455
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))));
5657
success = true;
58+
System.out.println(" Binding done for " + split_line[0]);
5759
}
58-
catch (RemoteException e) {
59-
e.printStackTrace();
60+
catch (Exception e) {
61+
//e.printStackTrace();
62+
System.err.println("Waiting for client 2...");
6063
}
6164
}
6265
local[i] = 0;
@@ -65,15 +68,15 @@ public static void main(String[] args) throws AlreadyBoundException, NotBoundExc
6568
i++;
6669
}
6770
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();
7174
setRegistry();
7275
System.out.println("Client 1 started");
7376
}
7477

7578
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"));
7780
String line;
7881
int node1;
7982
int node2;
@@ -113,8 +116,19 @@ public static void setRegistry() throws NotBoundException, NumberFormatException
113116
Registry registry = LocateRegistry.getRegistry("localhost", Constant.RMI_PORT);
114117
RMI_IDS = new IComponent[numProc]; // the remote process array is instantiated
115118
Thread[] myThreads = new Thread[numProc]; // and numProc number of threads are created
119+
boolean success;
116120
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+
}
118132
}
119133

120134
for(int i=0; i<localProc; i++){
@@ -125,10 +139,22 @@ public static void setRegistry() throws NotBoundException, NumberFormatException
125139
myThreads[i] = new Thread(p); // and a new thread is created
126140
}
127141

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+
}
131158
myThreads[0].start();
132-
myThreads[1].start();
133159
}
134160
}

Assignment3/src/assignment3/server/Client2.java

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import java.io.BufferedReader;
33
import java.io.FileReader;
44
import java.io.IOException;
5+
import java.rmi.AccessException;
56
import java.rmi.AlreadyBoundException;
67
import java.rmi.NotBoundException;
78
import java.rmi.RemoteException;
@@ -25,7 +26,7 @@ public class Client2 {
2526
public static void main(String[] args) throws AlreadyBoundException, NotBoundException, IOException, InterruptedException {
2627

2728
// "clients" files contain the name of the remote processes used
28-
BufferedReader br = new BufferedReader(new FileReader("tests/nodes.txt"));
29+
BufferedReader br = new BufferedReader(new FileReader("tests/nodes1.txt"));
2930
String line = br.readLine();
3031
numProc = Integer.parseInt(line);
3132
localProc = 0;
@@ -45,9 +46,9 @@ public static void main(String[] args) throws AlreadyBoundException, NotBoundExc
4546
i++;
4647
}
4748
br.close();
48-
System.out.println("Press enter to continue");
49-
Scanner scan = new Scanner(System.in);
50-
scan.nextLine();
49+
//System.out.println("Press enter to continue");
50+
//Scanner scan = new Scanner(System.in);
51+
//scan.nextLine();
5152
setRegistry();
5253
System.out.println("Client 2 started");
5354
}
@@ -57,7 +58,8 @@ public static void setRegistry() throws NotBoundException, NumberFormatException
5758
Registry registry = null;
5859
while (!success){
5960
try{
60-
registry = LocateRegistry.getRegistry("145.94.186.211", Constant.RMI_PORT);
61+
registry = LocateRegistry.getRegistry("145.94.184.129", Constant.RMI_PORT);
62+
System.out.println("registry is up");
6163
success = true;
6264
}
6365
catch (RemoteException e) {
@@ -68,7 +70,18 @@ public static void setRegistry() throws NotBoundException, NumberFormatException
6870
RMI_IDS = new IComponent[numProc]; // the remote process array is instantiated
6971
Thread[] myThreads = new Thread[numProc]; // and numProc number of threads are created
7072
for(int i=0; i<numProc; i++){
71-
RMI_IDS[i] = (IComponent) registry.lookup(registry.list()[i]);
73+
success = false;
74+
while(!success){
75+
try{
76+
RMI_IDS[i] = (IComponent) registry.lookup(registry.list()[i]);
77+
success = true;
78+
System.out.println("process " + i + " found");
79+
}
80+
catch(Exception e){
81+
//e.printStackTrace();
82+
System.err.println("Waiting for client 1...");
83+
}
84+
}
7285
}
7386

7487
for(int i=0; i<localProc; i++){
@@ -78,9 +91,10 @@ public static void setRegistry() throws NotBoundException, NumberFormatException
7891
myThreads[i] = new Thread(p); // and a new thread is created
7992
}
8093

81-
System.out.println("Press enter to continue");
82-
Scanner scan = new Scanner(System.in);
83-
scan.nextLine();
84-
for (int i = 0; i < localProc; i+=2) myThreads[i].start();
94+
//System.out.println("Press enter to continue");
95+
//Scanner scan = new Scanner(System.in);
96+
//scan.nextLine();
97+
//for (int i = 0; i < localProc; i+=2) myThreads[i].start();
98+
while(true){}
8599
}
86100
}

0 commit comments

Comments
 (0)
0