Mercurial > hg > Database > Alice
changeset 492:24e535123df7 dispose
add PrepareToClose CodeSegment
author | sugi |
---|---|
date | Thu, 11 Dec 2014 06:29:31 +0900 |
parents | 7d67bc538549 |
children | f3aae56b478f |
files | src/main/java/alice/topology/fix/FixTopology.java src/main/java/alice/topology/node/CloseRemoteDataSegment.java src/main/java/alice/topology/node/ConfigurationFinish.java src/main/java/alice/topology/node/PrepareToClose.java src/main/java/alice/topology/node/ReceiveCloseMessage.java |
diffstat | 5 files changed, 92 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/alice/topology/fix/FixTopology.java Wed Dec 10 20:31:09 2014 +0900 +++ b/src/main/java/alice/topology/fix/FixTopology.java Thu Dec 11 06:29:31 2014 +0900 @@ -56,6 +56,8 @@ LinkedList<HostMessage> connectionList = topology.get(lastJoinNodeName); // lastJoinedNode has one connection HostMessage parentNode = connectionList.poll(); + Parent p = manager.find(parentNode.absName); + p.decrement(); connectionList = topology.get(parentNode.absName); for (HostMessage node1 : connectionList) { @@ -86,6 +88,8 @@ node1.port = lastJoinNode.port; node1.absName = lastJoinNodeName; ods.put(node1.remoteAbsName, node1); + p = manager.find(lastJoinNodeName); + p.increment(); break; } } @@ -108,8 +112,6 @@ manager.replaceAndRemove(lostNodeName, lastJoinNodeName); } else { // disconnection node is lastJoinedNode - Parent p = manager.find(parentNode.absName); - p.decrement(); manager.remove(lostNodeName); }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/topology/node/CloseRemoteDataSegment.java Thu Dec 11 06:29:31 2014 +0900 @@ -0,0 +1,38 @@ +package alice.topology.node; + +import alice.codesegment.CodeSegment; +import alice.datasegment.CommandType; +import alice.datasegment.DataSegment; +import alice.datasegment.Receiver; +import alice.topology.manager.keeparive.ListManager; + +public class CloseRemoteDataSegment extends CodeSegment { + + private Receiver info = ids.create(CommandType.TAKE); + private Receiver info1 = ids.create(CommandType.TAKE); + private Receiver info2 = ids.create(CommandType.TAKE); + private Receiver info3 = ids.create(CommandType.TAKE); + + public CloseRemoteDataSegment() { + info.setKey("_CLOSEMESSEAGE"); + info1.setKey("_CLOSEREADY"); + info2.setKey("_CLOSEREADY"); + info3.setKey("_WAITINGLIST"); + } + + @Override + public void run() { + String managerKey = info.asString(); + if (info1.from.equals(managerKey)||info2.from.equals(managerKey)) { + if (DataSegment.contains(managerKey)) + DataSegment.get(managerKey).shutdown(); + + ListManager manager = info3.asClass(ListManager.class); + manager.deleteAll(managerKey); + ods.update(info1.key, manager); + } + + new ReceiveCloseMessage(CommandType.PEEK); + } + +}
--- a/src/main/java/alice/topology/node/ConfigurationFinish.java Wed Dec 10 20:31:09 2014 +0900 +++ b/src/main/java/alice/topology/node/ConfigurationFinish.java Thu Dec 11 06:29:31 2014 +0900 @@ -27,7 +27,7 @@ cs.done.setKey("manager", "start"); //new StartKeepAlive().execute(); - new ReceiveCloseMessage(); + new ReceiveCloseMessage(CommandType.PEEK); DisconnectEventManager.getInstance().register(DeleteConnection.class); DisconnectEventManager.getInstance().setKey(); return;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/topology/node/PrepareToClose.java Thu Dec 11 06:29:31 2014 +0900 @@ -0,0 +1,42 @@ +package alice.topology.node; + +import java.util.List; + +import alice.codesegment.CodeSegment; +import alice.datasegment.CommandType; +import alice.datasegment.DataSegment; +import alice.datasegment.DataSegmentManager; +import alice.datasegment.Receiver; + +public class PrepareToClose extends CodeSegment { + + private Receiver info = ids.create(CommandType.PEEK); + private Receiver info1 = ids.create(CommandType.TAKE); + + public PrepareToClose() { + info.setKey("_CLOSEMESSEAGE"); + info1.setKey("_CLIST"); + } + + @SuppressWarnings("unchecked") + @Override + public void run() { + String managerKey = info.asString(); + List<String> list = info1.asClass(List.class); + if (list.contains(managerKey)) { + list.remove(managerKey); + DataSegmentManager manager = DataSegment.get(managerKey); + manager.setSendError(false); + + ods.put(managerKey, "_CLOSEREADY", managerKey); + ods.put("_CLOSEREADY", managerKey); + ods.put(info1.key, list); + + new CloseRemoteDataSegment(); + } else { + // lost node is this node's parent + } + + } + +}
--- a/src/main/java/alice/topology/node/ReceiveCloseMessage.java Wed Dec 10 20:31:09 2014 +0900 +++ b/src/main/java/alice/topology/node/ReceiveCloseMessage.java Thu Dec 11 06:29:31 2014 +0900 @@ -2,29 +2,24 @@ import alice.codesegment.CodeSegment; import alice.datasegment.CommandType; -import alice.datasegment.DataSegment; import alice.datasegment.Receiver; public class ReceiveCloseMessage extends CodeSegment { - private Receiver info = ids.create(CommandType.TAKE); + private Receiver info; - public ReceiveCloseMessage() { + public ReceiveCloseMessage(CommandType type) { + info = ids.create(type); info.setKey("_CLOSEMESSEAGE"); } @Override public void run() { - String managerKey = info.asString(); - if (DataSegment.contains(managerKey)) { - DataSegment.get(managerKey).setSendError(false); - DataSegment.get(managerKey).shutdown(); - } else { - + if (info.type == CommandType.PEEK) { + new PrepareToClose(); + } else if (info.type == CommandType.TAKE){ + new ReceiveCloseMessage(CommandType.PEEK); } - - - new ReceiveCloseMessage(); } }