-
Notifications
You must be signed in to change notification settings - Fork 0
/
Bootstrap.java
87 lines (78 loc) · 1.8 KB
/
Bootstrap.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
84
85
86
87
import java.net.InetAddress;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
/**
* Class Bootstrap is used to connect a new peer to an existing peer in the
* system
*
* @author vaibhavgandhi
*
*/
public class Bootstrap extends UnicastRemoteObject implements
BootstrapInterface {
/**
* Global variables
*/
private static final long serialVersionUID = 1L;
String bootstrapNode_ip;
/**
* Constructor
*
* @throws RemoteException
*/
protected Bootstrap() throws RemoteException {
super();
bootstrapNode_ip = null;
}
/**
* Set the bootstrap IP address
*
* @param ip
* ip address
*/
public void setIPAddress(String ip) {
bootstrapNode_ip = ip;
System.out.println("IP of new Bootstrap Node: " + bootstrapNode_ip);
}
/**
* Get the bootstrap IP address
*
* @param incoming
* ip of node that tried to access bootstrap ip
* @return bootstrap ip
*/
public String getIPAddress(String incoming) {
System.out.println("Attempting to connect by " + incoming);
return bootstrapNode_ip;
}
/**
* Get random coordinate
*
* @return a coordinate
*/
public double getRandomCoordinate() {
int min = 1;
int max = 9;
return (double) (min + (Math.random() * ((max - min) + 1)));
}
/**
* main
*
* @param args
*/
public static void main(String args[]) {
try {
Bootstrap bs = new Bootstrap();
Registry r = LocateRegistry.createRegistry(21291);
r.bind("Bootstrap Server", bs);
System.out.println("Server alive!");
System.out.println("Server ip: "
+ InetAddress.getLocalHost().getHostAddress());
} catch (Exception e) {
System.out.println("Error while creating Bootstrap Server");
e.printStackTrace();
}
}
}