Mercurial > hg > Database > Alice
changeset 404:fee3efd9257d dispose
add node when application status running
author | sugi |
---|---|
date | Mon, 23 Jun 2014 18:12:57 +0900 |
parents | 539b7f5772c7 |
children | c817721af5ec |
files | src/main/java/alice/topology/HostMessage.java src/main/java/alice/topology/manager/ComingServiceHosts.java src/main/java/alice/topology/manager/StartTopologyManager.java src/main/java/alice/topology/node/ConfigurationFinish.java src/main/java/alice/topology/node/IncomingConnectionInfo.java src/main/java/alice/topology/node/IncomingReverseKey.java src/main/java/alice/topology/node/Start.java src/main/java/alice/topology/node/StartTopologyNode.java |
diffstat | 8 files changed, 39 insertions(+), 34 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/alice/topology/HostMessage.java Mon Jun 23 15:53:33 2014 +0900 +++ b/src/main/java/alice/topology/HostMessage.java Mon Jun 23 18:12:57 2014 +0900 @@ -10,6 +10,7 @@ public String connectionName; public String reverseName; public String absName; + public String parentAbsName; public HostMessage() { } public HostMessage(String name, int port) {
--- a/src/main/java/alice/topology/manager/ComingServiceHosts.java Mon Jun 23 15:53:33 2014 +0900 +++ b/src/main/java/alice/topology/manager/ComingServiceHosts.java Mon Jun 23 18:12:57 2014 +0900 @@ -1,6 +1,6 @@ package alice.topology.manager; -import java.util.ArrayList; +import java.util.HashMap; import org.msgpack.type.ValueFactory; @@ -14,13 +14,13 @@ Receiver info = ids.create(CommandType.TAKE); Receiver info1 = ids.create(CommandType.TAKE); - Receiver info2 = ids.create(CommandType.TAKE); + Receiver info2 = ids.create(CommandType.TAKE); // HashMap int BINATY_TREE = 2; public ComingServiceHosts(){ info.setKey("host"); info1.setKey("hostCount"); - info2.setKey("parentList"); + info2.setKey("nodeConnectionInfo"); } @Override @@ -28,7 +28,7 @@ HostMessage host = info.asClass(HostMessage.class); int comingHostCount = info1.asInteger(); @SuppressWarnings("unchecked") - ArrayList<HostMessage> parentList = info2.asClass(ArrayList.class); + HashMap<String, HostMessage> parentInfo = info2.asClass(HashMap.class); String nodeName = "node"+comingHostCount; // Manager connect to Node DataSegment.connect(nodeName, "", host.name, host.port); @@ -38,21 +38,23 @@ for (int i=1;i < BINATY_TREE+1; i++) { int num = 2 * comingHostCount+i; HostMessage newHost = new HostMessage(host.name, host.port, "parent", "child"+(i-1)); - newHost.absName = nodeName; - String absName = "node"+num; - parentList.add(num, newHost); - ods.put(absName, newHost); + newHost.parentAbsName = nodeName; + newHost.absName = "node"+num; + parentInfo.put(newHost.absName, newHost); + ods.put(newHost.absName, newHost); } if (comingHostCount!=0) { - HostMessage parentInfo = parentList.get(comingHostCount); - HostMessage newHost = new HostMessage(host.name, host.port, parentInfo.reverseName, "parent"); - ods.put(parentInfo.absName, newHost); + HostMessage parent = parentInfo.get(nodeName); + HostMessage newHost = new HostMessage(host.name, host.port, parent.reverseName, parent.connectionName); + ods.put(parent.parentAbsName, newHost); } - ods.put("parentList", parentList); + ods.put("nodeConnectionInfo", parentInfo); ods.put(nodeName, ValueFactory.createNilValue()); if (comingHostCount==0) ods.put("start", ValueFactory.createNilValue()); + + this.recycle(); } }
--- a/src/main/java/alice/topology/manager/StartTopologyManager.java Mon Jun 23 15:53:33 2014 +0900 +++ b/src/main/java/alice/topology/manager/StartTopologyManager.java Mon Jun 23 18:12:57 2014 +0900 @@ -83,10 +83,9 @@ cs3.done.setKey("local", "done"); } else { System.out.println("mode -t"); - ArrayList<HostMessage> parentList = new ArrayList<HostMessage>(); - parentList.add(new HostMessage()); + HashMap<String,HostMessage> parentInfo = new HashMap<String,HostMessage>(); int cominghostCount = 0; - ods.put("parentList", parentList); + ods.put("nodeConnectionInfo", parentInfo); ods.put("hostCount", cominghostCount); new ComingServiceHosts(); }
--- a/src/main/java/alice/topology/node/ConfigurationFinish.java Mon Jun 23 15:53:33 2014 +0900 +++ b/src/main/java/alice/topology/node/ConfigurationFinish.java Mon Jun 23 18:12:57 2014 +0900 @@ -19,12 +19,11 @@ @Override public void run() { if (reverseCount.getVal().equals(configNodeNum.getVal())) { - + ods.put("manager", "done", ValueFactory.createNilValue()); Start cs = new Start(startCS); + cs.runningFlag.setKey("local", "running"); cs.done.setKey("manager", "start"); - - new NewConnection(); return; }
--- a/src/main/java/alice/topology/node/IncomingConnectionInfo.java Mon Jun 23 15:53:33 2014 +0900 +++ b/src/main/java/alice/topology/node/IncomingConnectionInfo.java Mon Jun 23 18:12:57 2014 +0900 @@ -15,13 +15,13 @@ private List<String> connectionList; private String absName; private int count; - + public IncomingConnectionInfo(String absName, int count) { this.absName = absName; this.count = count; this.connectionList = new ArrayList<String>(); } - + public IncomingConnectionInfo(String absName, int count, List<String> connectionList) { this.absName = absName; this.count = count; @@ -32,18 +32,17 @@ public void run() { if (this.hostInfo.getVal() == null) { ods.put("local", "configNodeNum", count); - this.recycle(); - return; + IncomingConnectionInfo cs = new IncomingConnectionInfo(absName, count, connectionList); + cs.hostInfo.setKey("manager", absName); + } else { + HostMessage hostInfo = this.hostInfo.asClass(HostMessage.class); + DataSegment.connect(hostInfo.connectionName, hostInfo.reverseName, hostInfo.name, hostInfo.port); + ods.put(hostInfo.connectionName, "reverseKey", hostInfo.reverseName); + connectionList.add(hostInfo.connectionName); + ods.update("_CLIST", connectionList); + IncomingConnectionInfo cs = new IncomingConnectionInfo(absName, ++count, connectionList); + cs.hostInfo.setKey("manager", absName); } - - HostMessage hostInfo = this.hostInfo.asClass(HostMessage.class); - DataSegment.connect(hostInfo.connectionName, hostInfo.reverseName, hostInfo.name, hostInfo.port); - ods.put(hostInfo.connectionName, "reverseKey", hostInfo.reverseName); - connectionList.add(hostInfo.connectionName); - ods.update("_CLIST", connectionList); - IncomingConnectionInfo cs = new IncomingConnectionInfo(absName, ++count, connectionList); - cs.hostInfo.setKey("manager", absName); - } }
--- a/src/main/java/alice/topology/node/IncomingReverseKey.java Mon Jun 23 15:53:33 2014 +0900 +++ b/src/main/java/alice/topology/node/IncomingReverseKey.java Mon Jun 23 18:12:57 2014 +0900 @@ -4,7 +4,6 @@ import alice.datasegment.CommandType; import alice.datasegment.DataSegment; import alice.datasegment.Receiver; -import org.msgpack.type.Value; public class IncomingReverseKey extends CodeSegment { @@ -13,15 +12,15 @@ @Override public void run() { - String reverseKey = ((Value)this.reverseKey.getVal()).asRawValue().getString(); + String reverseKey = this.reverseKey.asString(); String from = this.reverseKey.from; DataSegment.getAccept(from).reverseKey = reverseKey; + //new CheckRunning(); int reverseCount = this.reverseCount.asInteger(); reverseCount++; ods.update("local", "reverseCount", reverseCount); - IncomingReverseKey cs = new IncomingReverseKey(); cs.reverseKey.setKey("local", "reverseKey"); cs.reverseCount.setKey("local", "reverseCount");
--- a/src/main/java/alice/topology/node/Start.java Mon Jun 23 15:53:33 2014 +0900 +++ b/src/main/java/alice/topology/node/Start.java Mon Jun 23 18:12:57 2014 +0900 @@ -9,8 +9,11 @@ public class Start extends CodeSegment { public Receiver done = ids.create(CommandType.PEEK); + public Receiver runningFlag = ids.create(CommandType.TAKE); + private Logger logger = Logger.getLogger(Start.class); private CodeSegment startCS; + public Start(CodeSegment startCS) { this.startCS = startCS; @@ -19,8 +22,10 @@ @Override public void run() { logger.info("Configuration finished."); + if (startCS == null) return; + ods.update(runningFlag.key, true); startCS.execute(); }
--- a/src/main/java/alice/topology/node/StartTopologyNode.java Mon Jun 23 15:53:33 2014 +0900 +++ b/src/main/java/alice/topology/node/StartTopologyNode.java Mon Jun 23 18:12:57 2014 +0900 @@ -18,6 +18,7 @@ @Override public void run() { + ods.put("running", false); DataSegment.connect("manager", "", conf.getManagerHostName(), conf.getManagerPort()); String localHostName = null; try {