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
| public class DistTutorial {
public DistTutorial(int bindport, InetSocketAddress bootaddress, Environment env) throws Exception {
NodeIdFactory nidFactory = new RandomNodeIdFactory(env);
PastryNodeFactory factory = new SocketPastryNodeFactory(nidFactory, bindport, env);
NodeHandle bootHandle = ((SocketPastryNodeFactory)factory).getNodeHandle(bootaddress);
PastryNode node = factory.newNode(bootHandle);
synchronized(node) {
while(!node.isReady() && !node.joinFailed()) {
node.wait(500);
if (node.joinFailed()) {
throw new IOException("Could not join the FreePastry ring. Reason:"+node.joinFailedReason());
}
}
}
System.out.println("Finished creating new node "+node);
}
public static void main(String[] args) throws Exception {
Environment env = new Environment();
env.getParameters().setString("nat_search_policy","never");
try {
int bindport = Integer.parseInt(args[0]);
InetAddress bootaddr = InetAddress.getByName(args[1]);
int bootport = Integer.parseInt(args[2]);
InetSocketAddress bootaddress = new InetSocketAddress(bootaddr,bootport);
DistTutorial dt = new DistTutorial(bindport, bootaddress, env);
} catch (Exception e) {
System.out.println("Usage:");
System.out.println("java [-cp FreePastry-<version>.jar] rice.tutorial.lesson1.DistTutorial localbindport bootIP bootPort");
System.out.println("example java rice.tutorial.DistTutorial 9001 pokey.cs.almamater.edu 9001");
throw e;
}
}
} |