diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/christie/topology/node/TopologyNode.java	Thu Aug 23 09:29:05 2018 +0900
@@ -0,0 +1,58 @@
+package christie.topology.node;
+
+import christie.codegear.CodeGear;
+import christie.codegear.CodeGearManager;
+import christie.topology.HostMessage;
+import christie.topology.manager.IncomingHosts;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.ArrayList;
+
+public class TopologyNode extends CodeGear{
+
+    private final String manager;
+    private final String local;
+    private TopologyNodeConfig conf;
+    private CodeGear startCS;
+
+    public TopologyNode(TopologyNodeConfig conf, CodeGear startCS) {
+        this.conf = conf;
+        this.startCS = startCS;
+        this.manager = conf.getManagerKey();
+        this.local = conf.getLocalKey();
+    }
+
+    @Override
+    protected void run(CodeGearManager cgm) {
+        cgm.createRemoteDGM(manager, conf.getManagerHostName(), conf.getManagerPort());
+        String localHostName = null;
+        try {
+            localHostName = InetAddress.getLocalHost().getHostAddress();
+        } catch (UnknownHostException e) {
+            e.printStackTrace();
+        }
+        cgm.setup(new SaveCookie());
+        if (cgm.localPort == 0) {
+            // local test mode
+            localHostName = conf.getLocalKey();
+        }
+        getLocalDGM().put("config" , conf );
+
+        HostMessage host = new HostMessage(localHostName, cgm.localPort);
+        host.cookie = conf.cookie;
+        getDGM(manager).put("hostMessage", host);
+
+        getLocalDGM().put("_CLIST", new ArrayList<String>());
+        //getDGM(local).put("_CLIST", new ArrayList<String>());
+
+        cgm.setup(new IncomingAbstractHostName(conf));
+
+        cgm.setup(new IncomingReverseKey());
+
+        getLocalDGM().put("reverseCount", 0);
+
+        cgm.setup(new ConfigurationFinish(startCS));
+
+    }
+}