annotate src/main/java/christie/topology/node/TopologyNode.java @ 49:fd944876257b

add node and keepalive
author akahori
date Thu, 23 Aug 2018 09:29:05 +0900
parents
children 9922e6decbe8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
49
fd944876257b add node and keepalive
akahori
parents:
diff changeset
1 package christie.topology.node;
fd944876257b add node and keepalive
akahori
parents:
diff changeset
2
fd944876257b add node and keepalive
akahori
parents:
diff changeset
3 import christie.codegear.CodeGear;
fd944876257b add node and keepalive
akahori
parents:
diff changeset
4 import christie.codegear.CodeGearManager;
fd944876257b add node and keepalive
akahori
parents:
diff changeset
5 import christie.topology.HostMessage;
fd944876257b add node and keepalive
akahori
parents:
diff changeset
6 import christie.topology.manager.IncomingHosts;
fd944876257b add node and keepalive
akahori
parents:
diff changeset
7
fd944876257b add node and keepalive
akahori
parents:
diff changeset
8 import java.net.InetAddress;
fd944876257b add node and keepalive
akahori
parents:
diff changeset
9 import java.net.UnknownHostException;
fd944876257b add node and keepalive
akahori
parents:
diff changeset
10 import java.util.ArrayList;
fd944876257b add node and keepalive
akahori
parents:
diff changeset
11
fd944876257b add node and keepalive
akahori
parents:
diff changeset
12 public class TopologyNode extends CodeGear{
fd944876257b add node and keepalive
akahori
parents:
diff changeset
13
fd944876257b add node and keepalive
akahori
parents:
diff changeset
14 private final String manager;
fd944876257b add node and keepalive
akahori
parents:
diff changeset
15 private final String local;
fd944876257b add node and keepalive
akahori
parents:
diff changeset
16 private TopologyNodeConfig conf;
fd944876257b add node and keepalive
akahori
parents:
diff changeset
17 private CodeGear startCS;
fd944876257b add node and keepalive
akahori
parents:
diff changeset
18
fd944876257b add node and keepalive
akahori
parents:
diff changeset
19 public TopologyNode(TopologyNodeConfig conf, CodeGear startCS) {
fd944876257b add node and keepalive
akahori
parents:
diff changeset
20 this.conf = conf;
fd944876257b add node and keepalive
akahori
parents:
diff changeset
21 this.startCS = startCS;
fd944876257b add node and keepalive
akahori
parents:
diff changeset
22 this.manager = conf.getManagerKey();
fd944876257b add node and keepalive
akahori
parents:
diff changeset
23 this.local = conf.getLocalKey();
fd944876257b add node and keepalive
akahori
parents:
diff changeset
24 }
fd944876257b add node and keepalive
akahori
parents:
diff changeset
25
fd944876257b add node and keepalive
akahori
parents:
diff changeset
26 @Override
fd944876257b add node and keepalive
akahori
parents:
diff changeset
27 protected void run(CodeGearManager cgm) {
fd944876257b add node and keepalive
akahori
parents:
diff changeset
28 cgm.createRemoteDGM(manager, conf.getManagerHostName(), conf.getManagerPort());
fd944876257b add node and keepalive
akahori
parents:
diff changeset
29 String localHostName = null;
fd944876257b add node and keepalive
akahori
parents:
diff changeset
30 try {
fd944876257b add node and keepalive
akahori
parents:
diff changeset
31 localHostName = InetAddress.getLocalHost().getHostAddress();
fd944876257b add node and keepalive
akahori
parents:
diff changeset
32 } catch (UnknownHostException e) {
fd944876257b add node and keepalive
akahori
parents:
diff changeset
33 e.printStackTrace();
fd944876257b add node and keepalive
akahori
parents:
diff changeset
34 }
fd944876257b add node and keepalive
akahori
parents:
diff changeset
35 cgm.setup(new SaveCookie());
fd944876257b add node and keepalive
akahori
parents:
diff changeset
36 if (cgm.localPort == 0) {
fd944876257b add node and keepalive
akahori
parents:
diff changeset
37 // local test mode
fd944876257b add node and keepalive
akahori
parents:
diff changeset
38 localHostName = conf.getLocalKey();
fd944876257b add node and keepalive
akahori
parents:
diff changeset
39 }
fd944876257b add node and keepalive
akahori
parents:
diff changeset
40 getLocalDGM().put("config" , conf );
fd944876257b add node and keepalive
akahori
parents:
diff changeset
41
fd944876257b add node and keepalive
akahori
parents:
diff changeset
42 HostMessage host = new HostMessage(localHostName, cgm.localPort);
fd944876257b add node and keepalive
akahori
parents:
diff changeset
43 host.cookie = conf.cookie;
fd944876257b add node and keepalive
akahori
parents:
diff changeset
44 getDGM(manager).put("hostMessage", host);
fd944876257b add node and keepalive
akahori
parents:
diff changeset
45
fd944876257b add node and keepalive
akahori
parents:
diff changeset
46 getLocalDGM().put("_CLIST", new ArrayList<String>());
fd944876257b add node and keepalive
akahori
parents:
diff changeset
47 //getDGM(local).put("_CLIST", new ArrayList<String>());
fd944876257b add node and keepalive
akahori
parents:
diff changeset
48
fd944876257b add node and keepalive
akahori
parents:
diff changeset
49 cgm.setup(new IncomingAbstractHostName(conf));
fd944876257b add node and keepalive
akahori
parents:
diff changeset
50
fd944876257b add node and keepalive
akahori
parents:
diff changeset
51 cgm.setup(new IncomingReverseKey());
fd944876257b add node and keepalive
akahori
parents:
diff changeset
52
fd944876257b add node and keepalive
akahori
parents:
diff changeset
53 getLocalDGM().put("reverseCount", 0);
fd944876257b add node and keepalive
akahori
parents:
diff changeset
54
fd944876257b add node and keepalive
akahori
parents:
diff changeset
55 cgm.setup(new ConfigurationFinish(startCS));
fd944876257b add node and keepalive
akahori
parents:
diff changeset
56
fd944876257b add node and keepalive
akahori
parents:
diff changeset
57 }
fd944876257b add node and keepalive
akahori
parents:
diff changeset
58 }