annotate src/alice/topology/node/StartTopologyNode.java @ 266:c0712e0b0a24

creating reconnect Manager
author sugi
date Fri, 16 Aug 2013 19:05:43 +0900
parents 7f7b3506bff9
children 9982e1c4f099
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
25
50c75cb3de60 implements TopologyNode
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 package alice.topology.node;
50c75cb3de60 implements TopologyNode
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2
50c75cb3de60 implements TopologyNode
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 import java.net.InetAddress;
175
d7816b9b72e9 minor change
e095732
parents: 173
diff changeset
4 import java.net.NetworkInterface;
d7816b9b72e9 minor change
e095732
parents: 173
diff changeset
5 import java.net.SocketException;
182
52a1fa5ba38b add filp api
e095732
parents: 175
diff changeset
6 import java.net.UnknownHostException;
175
d7816b9b72e9 minor change
e095732
parents: 173
diff changeset
7 import java.util.Enumeration;
25
50c75cb3de60 implements TopologyNode
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
8
50c75cb3de60 implements TopologyNode
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 import alice.codesegment.CodeSegment;
50c75cb3de60 implements TopologyNode
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 import alice.datasegment.DataSegment;
50c75cb3de60 implements TopologyNode
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 import alice.topology.HostMessage;
50c75cb3de60 implements TopologyNode
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
12
50c75cb3de60 implements TopologyNode
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 public class StartTopologyNode extends CodeSegment {
50c75cb3de60 implements TopologyNode
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
14
26
9c6b9e032338 implements TopologyNode
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 25
diff changeset
15 private TopologyNodeConfig conf;
46
1a498f436332 bug fix for time calculate
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
16 private CodeSegment startCS;
25
50c75cb3de60 implements TopologyNode
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
17
46
1a498f436332 bug fix for time calculate
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
18 public StartTopologyNode(TopologyNodeConfig conf, CodeSegment startCS) {
25
50c75cb3de60 implements TopologyNode
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 this.conf = conf;
46
1a498f436332 bug fix for time calculate
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
20 this.startCS = startCS;
25
50c75cb3de60 implements TopologyNode
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 }
50c75cb3de60 implements TopologyNode
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
22
50c75cb3de60 implements TopologyNode
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 @Override
50c75cb3de60 implements TopologyNode
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 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
25 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
26 String localHostName = null;
175
d7816b9b72e9 minor change
e095732
parents: 173
diff changeset
27 try {
182
52a1fa5ba38b add filp api
e095732
parents: 175
diff changeset
28 localHostName = InetAddress.getLocalHost().getHostName();
52a1fa5ba38b add filp api
e095732
parents: 175
diff changeset
29 } catch (UnknownHostException e) {
175
d7816b9b72e9 minor change
e095732
parents: 173
diff changeset
30 e.printStackTrace();
d7816b9b72e9 minor change
e095732
parents: 173
diff changeset
31 }
182
52a1fa5ba38b add filp api
e095732
parents: 175
diff changeset
32
95
7982324d4329 "setKey" move in the instance
sugi
parents: 46
diff changeset
33 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
34 ods.put("manager", "host", host);
25
50c75cb3de60 implements TopologyNode
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
35
266
c0712e0b0a24 creating reconnect Manager
sugi
parents: 258
diff changeset
36 IncomingAbstractHostName cs = new IncomingAbstractHostName(host);
258
7f7b3506bff9 client can get connection list setkey(_CLIST);
sugi
parents: 183
diff changeset
37 cs.absName.setKey("local", "host");
28
98ab26e09a98 Configuration Manager work and implements reverseKey
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 27
diff changeset
38
98ab26e09a98 Configuration Manager work and implements reverseKey
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 27
diff changeset
39 IncomingReverseKey cs2 = new IncomingReverseKey();
98ab26e09a98 Configuration Manager work and implements reverseKey
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 27
diff changeset
40 cs2.reverseKey.setKey("local", "reverseKey");
98ab26e09a98 Configuration Manager work and implements reverseKey
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 27
diff changeset
41 cs2.reverseCount.setKey("local", "reverseCount");
98ab26e09a98 Configuration Manager work and implements reverseKey
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 27
diff changeset
42
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
43 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
44
46
1a498f436332 bug fix for time calculate
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
45 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
46 cs3.reverseCount.setKey("local", "reverseCount");
98ab26e09a98 Configuration Manager work and implements reverseKey
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 27
diff changeset
47 cs3.configNodeNum.setKey("local", "configNodeNum");
25
50c75cb3de60 implements TopologyNode
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
48 }
50c75cb3de60 implements TopologyNode
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
49
183
75150396681c use synchronizedList
e095732
parents: 182
diff changeset
50 @SuppressWarnings("unused")
175
d7816b9b72e9 minor change
e095732
parents: 173
diff changeset
51 private String getIPAddress() throws SocketException {
d7816b9b72e9 minor change
e095732
parents: 173
diff changeset
52 Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
d7816b9b72e9 minor change
e095732
parents: 173
diff changeset
53
d7816b9b72e9 minor change
e095732
parents: 173
diff changeset
54 while(interfaces.hasMoreElements()){
d7816b9b72e9 minor change
e095732
parents: 173
diff changeset
55 NetworkInterface network = interfaces.nextElement();
d7816b9b72e9 minor change
e095732
parents: 173
diff changeset
56 Enumeration<InetAddress> addresses = network.getInetAddresses();
d7816b9b72e9 minor change
e095732
parents: 173
diff changeset
57
d7816b9b72e9 minor change
e095732
parents: 173
diff changeset
58 while(addresses.hasMoreElements()){
d7816b9b72e9 minor change
e095732
parents: 173
diff changeset
59 String address = addresses.nextElement().getHostAddress();
d7816b9b72e9 minor change
e095732
parents: 173
diff changeset
60 if(!"127.0.0.1".equals(address) && !"0.0.0.0".equals(address)){
d7816b9b72e9 minor change
e095732
parents: 173
diff changeset
61 return address;
d7816b9b72e9 minor change
e095732
parents: 173
diff changeset
62 }
d7816b9b72e9 minor change
e095732
parents: 173
diff changeset
63 }
d7816b9b72e9 minor change
e095732
parents: 173
diff changeset
64 }
d7816b9b72e9 minor change
e095732
parents: 173
diff changeset
65 return "127.0.0.1";
d7816b9b72e9 minor change
e095732
parents: 173
diff changeset
66 }
d7816b9b72e9 minor change
e095732
parents: 173
diff changeset
67
25
50c75cb3de60 implements TopologyNode
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
68 }