-
Notifications
You must be signed in to change notification settings - Fork 0
/
StartRemotePeers.java
83 lines (67 loc) · 2.56 KB
/
StartRemotePeers.java
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
* CEN5501C Project2
* This is the program starting remote processes.
* This program was only tested on CISE SunOS environment.
* If you use another environment, for example, linux environment in CISE
* or other environments not in CISE, it is not guaranteed to work properly.
* It is your responsibility to adapt this program to your running environment.
*/
import java.io.*;
import java.util.*;
/*
* The StartRemotePeers class begins remote peer processes.
* It reads configuration file PeerInfo.cfg and starts remote peer processes.
* You must modify this program a little bit if your peer processes are written in C or C++.
* Please look at the lines below the comment saying IMPORTANT.
*/
public class StartRemotePeers {
public Vector<RemotePeerInfo> peerInfoVector;
public void getConfiguration()
{
String st;
int i1;
peerInfoVector = new Vector<RemotePeerInfo>();
try {
BufferedReader in = new BufferedReader(new FileReader("PeerInfo.cfg"));
while((st = in.readLine()) != null) {
String[] tokens = st.split("\\s+");
//System.out.println("tokens begin ----");
//for (int x=0; x<tokens.length; x++) {
// System.out.println(tokens[x]);
//}
//System.out.println("tokens end ----");
peerInfoVector.addElement(new RemotePeerInfo(tokens[0], tokens[1], tokens[2]));
}
in.close();
}
catch (Exception ex) {
System.out.println(ex.toString());
}
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
StartRemotePeers myStart = new StartRemotePeers();
myStart.getConfiguration();
// get current path
String path = System.getProperty("user.dir");
// start clients at remote hosts
for (int i = 0; i < myStart.peerInfoVector.size(); i++) {
RemotePeerInfo pInfo = (RemotePeerInfo) myStart.peerInfoVector.elementAt(i);
System.out.println("Start remote peer " + pInfo.peerId + " at " + pInfo.peerAddress );
// *********************** IMPORTANT *************************** //
// If your program is JAVA, use this line.
Runtime.getRuntime().exec("ssh " + pInfo.peerAddress + " cd " + path + "; java peerProcess " + pInfo.peerId);
// If your program is C/C++, use this line instead of the above line.
//Runtime.getRuntime().exec("ssh " + pInfo.peerAddress + " cd " + path + "; ./peerProcess " + pInfo.peerId);
}
System.out.println("Starting all remote peers has done." );
}
catch (Exception ex) {
System.out.println(ex);
}
}
}