Mercurial > hg > Database > Alice
annotate src/alice/topology/node/StartTopologyNode.java @ 175:d7816b9b72e9 working
minor change
author | e095732 |
---|---|
date | Thu, 24 Jan 2013 21:23:16 +0900 |
parents | 23d6a775a643 |
children | 52a1fa5ba38b |
rev | line source |
---|---|
25 | 1 package alice.topology.node; |
2 | |
3 import java.net.InetAddress; | |
175 | 4 import java.net.NetworkInterface; |
5 import java.net.SocketException; | |
6 import java.util.Enumeration; | |
25 | 7 |
8 import alice.codesegment.CodeSegment; | |
9 import alice.datasegment.DataSegment; | |
10 import alice.topology.HostMessage; | |
11 | |
12 public class StartTopologyNode extends CodeSegment { | |
13 | |
26 | 14 private TopologyNodeConfig conf; |
46 | 15 private CodeSegment startCS; |
25 | 16 |
46 | 17 public StartTopologyNode(TopologyNodeConfig conf, CodeSegment startCS) { |
25 | 18 this.conf = conf; |
46 | 19 this.startCS = startCS; |
25 | 20 } |
21 | |
22 @Override | |
23 public void run() { | |
34
ca079a730d0b
added method to OutputDataSegment and Receiver, to convert type from Value to Class<?> without MessagePack
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
30
diff
changeset
|
24 DataSegment.connect("manager", "", conf.managerHostName, conf.managerPort); |
ca079a730d0b
added method to OutputDataSegment and Receiver, to convert type from Value to Class<?> without MessagePack
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
30
diff
changeset
|
25 String localHostName = null; |
175 | 26 //localHostName = InetAddress.getLocalHost().getHostName(); |
27 try { | |
28 localHostName = getIPAddress(); | |
29 } catch (SocketException e) { | |
30 e.printStackTrace(); | |
31 } | |
95 | 32 HostMessage host = new HostMessage(localHostName, conf.localPort); |
34
ca079a730d0b
added method to OutputDataSegment and Receiver, to convert type from Value to Class<?> without MessagePack
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
30
diff
changeset
|
33 ods.put("manager", "host", host); |
25 | 34 |
95 | 35 new IncomingAbstractHostName(); |
28
98ab26e09a98
Configuration Manager work and implements reverseKey
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
27
diff
changeset
|
36 |
98ab26e09a98
Configuration Manager work and implements reverseKey
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
27
diff
changeset
|
37 IncomingReverseKey cs2 = new IncomingReverseKey(); |
98ab26e09a98
Configuration Manager work and implements reverseKey
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
27
diff
changeset
|
38 cs2.reverseKey.setKey("local", "reverseKey"); |
98ab26e09a98
Configuration Manager work and implements reverseKey
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
27
diff
changeset
|
39 cs2.reverseCount.setKey("local", "reverseCount"); |
98ab26e09a98
Configuration Manager work and implements reverseKey
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
27
diff
changeset
|
40 |
34
ca079a730d0b
added method to OutputDataSegment and Receiver, to convert type from Value to Class<?> without MessagePack
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
30
diff
changeset
|
41 ods.put("local", "reverseCount", 0); |
28
98ab26e09a98
Configuration Manager work and implements reverseKey
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
27
diff
changeset
|
42 |
46 | 43 ConfigurationFinish cs3 = new ConfigurationFinish(startCS); |
28
98ab26e09a98
Configuration Manager work and implements reverseKey
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
27
diff
changeset
|
44 cs3.reverseCount.setKey("local", "reverseCount"); |
98ab26e09a98
Configuration Manager work and implements reverseKey
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
27
diff
changeset
|
45 cs3.configNodeNum.setKey("local", "configNodeNum"); |
25 | 46 } |
47 | |
175 | 48 private String getIPAddress() throws SocketException { |
49 Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces(); | |
50 | |
51 while(interfaces.hasMoreElements()){ | |
52 NetworkInterface network = interfaces.nextElement(); | |
53 Enumeration<InetAddress> addresses = network.getInetAddresses(); | |
54 | |
55 while(addresses.hasMoreElements()){ | |
56 String address = addresses.nextElement().getHostAddress(); | |
57 if(!"127.0.0.1".equals(address) && !"0.0.0.0".equals(address)){ | |
58 return address; | |
59 } | |
60 } | |
61 } | |
62 return "127.0.0.1"; | |
63 } | |
64 | |
25 | 65 } |