Mercurial > hg > Members > tatsuki > Alice
comparison src/main/java/alice/topology/node/StartTopologyNode.java @ 345:8f71c3e6f11d
Change directory structure Maven standard
author | sugi |
---|---|
date | Wed, 16 Apr 2014 18:26:07 +0900 |
parents | |
children | 5ceb1c4db167 |
comparison
equal
deleted
inserted
replaced
344:9f97ec18f8c5 | 345:8f71c3e6f11d |
---|---|
1 package alice.topology.node; | |
2 | |
3 import java.net.InetAddress; | |
4 import java.net.NetworkInterface; | |
5 import java.net.SocketException; | |
6 import java.net.UnknownHostException; | |
7 import java.util.Enumeration; | |
8 | |
9 import alice.codesegment.CodeSegment; | |
10 import alice.datasegment.DataSegment; | |
11 import alice.topology.HostMessage; | |
12 | |
13 public class StartTopologyNode extends CodeSegment { | |
14 | |
15 private TopologyNodeConfig conf; | |
16 private CodeSegment startCS; | |
17 | |
18 public StartTopologyNode(TopologyNodeConfig conf, CodeSegment startCS) { | |
19 this.conf = conf; | |
20 this.startCS = startCS; | |
21 } | |
22 | |
23 @Override | |
24 public void run() { | |
25 DataSegment.connect("manager", "", conf.managerHostName, conf.managerPort, false); | |
26 String localHostName = null; | |
27 try { | |
28 localHostName = InetAddress.getLocalHost().getHostName(); | |
29 } catch (UnknownHostException e) { | |
30 e.printStackTrace(); | |
31 } | |
32 | |
33 HostMessage host = new HostMessage(localHostName, conf.localPort); | |
34 ods.put("manager", "host", host); | |
35 | |
36 IncomingAbstractHostName cs = new IncomingAbstractHostName(host); | |
37 cs.absName.setKey("local", "host"); | |
38 | |
39 IncomingReverseKey cs2 = new IncomingReverseKey(); | |
40 cs2.reverseKey.setKey("local", "reverseKey"); | |
41 cs2.reverseCount.setKey("local", "reverseCount"); | |
42 | |
43 ods.put("local", "reverseCount", 0); | |
44 | |
45 ConfigurationFinish cs3 = new ConfigurationFinish(startCS); | |
46 cs3.reverseCount.setKey("local", "reverseCount"); | |
47 cs3.configNodeNum.setKey("local", "configNodeNum"); | |
48 | |
49 } | |
50 | |
51 @SuppressWarnings("unused") | |
52 private String getIPAddress() throws SocketException { | |
53 Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces(); | |
54 | |
55 while(interfaces.hasMoreElements()){ | |
56 NetworkInterface network = interfaces.nextElement(); | |
57 Enumeration<InetAddress> addresses = network.getInetAddresses(); | |
58 | |
59 while(addresses.hasMoreElements()){ | |
60 String address = addresses.nextElement().getHostAddress(); | |
61 if(!"127.0.0.1".equals(address) && !"0.0.0.0".equals(address)){ | |
62 return address; | |
63 } | |
64 } | |
65 } | |
66 return "127.0.0.1"; | |
67 } | |
68 | |
69 } |