changeset 474:6a71732cd3ee dispose

add topology fix package
author sugi
date Sun, 30 Nov 2014 00:01:35 +0900
parents 041ec04d4d45
children fac27e395930
files src/main/java/alice/topology/fix/FixTopology.java src/main/java/alice/topology/fix/ReceiveDisconnectMessage.java
diffstat 2 files changed, 108 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/alice/topology/fix/FixTopology.java	Sun Nov 30 00:01:35 2014 +0900
@@ -0,0 +1,89 @@
+package alice.topology.fix;
+
+import java.util.HashMap;
+import java.util.LinkedList;
+
+import alice.codesegment.CodeSegment;
+import alice.daemon.ConnectionInfo;
+import alice.datasegment.CommandType;
+import alice.datasegment.Receiver;
+import alice.topology.HostMessage;
+
+public class FixTopology extends CodeSegment {
+
+    private Receiver info = ids.create(CommandType.TAKE); // disconnection nodeInfo
+    private Receiver info1 = ids.create(CommandType.TAKE); // all connection Info
+    private Receiver info2 = ids.create(CommandType.TAKE); // node count
+    private Receiver info3 = ids.create(CommandType.TAKE); // need to search parent node
+
+    public FixTopology() {
+        info.setKey("_DISCONNECT");
+        info1.setKey("topology");
+        info2.setKey("hostCount");
+        info3.setKey("nodeConnectionInfo");
+    }
+
+    @SuppressWarnings("unchecked")
+    @Override
+    public void run() {
+        ConnectionInfo disconnect = info.asClass(ConnectionInfo.class);
+
+        HashMap<String, HostMessage> nodeInfo = info3.asClass(HashMap.class);
+
+        // check
+        if (nodeInfo.containsKey(disconnect.nodeName)) {
+            HostMessage registered = nodeInfo.get(disconnect.nodeName);
+            // if information not match, FixTopology was change Information before.
+            if ((registered.name.equals(disconnect.addr)||registered.name.equals(disconnect.hostname))
+                    && (registered.port == disconnect.port)) {
+                int nodeNum = info2.asInteger() - 1; // get last joined node
+                String nodeName = "node"+nodeNum;
+                if (nodeName.equals(disconnect.nodeName)) {
+                    // if disconnect node equal last joined node, only do update topology information.
+
+
+                } else {
+                    // move last joined node to disconnect node position.
+                    HashMap<String, LinkedList<HostMessage>> topology = info1.asClass(HashMap.class);
+
+                    // send disconnect Message which connected to last joined node.
+                    LinkedList<HostMessage> list = topology.get(nodeName);
+                    // last joined node's list has only one node (parent)
+                    HostMessage host = list.getFirst();
+                    ods.put(host.absName, "_DISCONNECTREQUEST", "DISCONNECT");
+                    // remove last joined node information from parent and children list
+                    list = topology.get(host.absName);
+                    // parent list
+                    for (HostMessage node : list) {
+                        if (node.absName.equals(host.absName)) {
+                            list.remove(node);
+                            break;
+                        }
+                    }
+                    /*
+                     * children node
+                     * child node list has only last joined node. so list clear.
+                     */
+                    int child1 = nodeNum * 2 + 1;
+                    int child2 = child1;
+                    String[] children = {"node"+child1, "node"+child2};
+                    for (String name: children) {
+                        if (topology.containsKey(name))
+                            topology.get(name).clear();
+                    }
+
+
+                    // this list can see who connected disconnect node.
+                    //LinkedList<HostMessage> list = topology.get(disconnect.nodeName);
+
+                }
+            } else {
+
+            }
+
+        } else {
+            // in this case. Key was deleted by FixTopology
+        }
+
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/alice/topology/fix/ReceiveDisconnectMessage.java	Sun Nov 30 00:01:35 2014 +0900
@@ -0,0 +1,19 @@
+package alice.topology.fix;
+
+import alice.codesegment.CodeSegment;
+import alice.datasegment.CommandType;
+import alice.datasegment.Receiver;
+
+public class ReceiveDisconnectMessage extends CodeSegment {
+    private Receiver info = ids.create(CommandType.PEEK);
+
+    public ReceiveDisconnectMessage() {
+        info.setKey("_DISCONNECT");
+    }
+
+    @Override
+    public void run() {
+        new FixTopology();
+        new ReceiveDisconnectMessage();
+    }
+}