Mercurial > hg > Database > jungle-network
changeset 96:fcce7ca4adb9
Modified LogUpdateCodesegment
author | one |
---|---|
date | Mon, 18 Nov 2013 19:34:15 +0900 |
parents | dcd767b76f8d |
children | 11ad00323206 |
files | src/alice/jungle/persistence/PersistentJungleTree.java src/jungle/app/bbs/JungleManager.java src/jungle/app/bbs/codesegment/LogUpdateCodeSegment.java src/jungle/app/bbs/codesegment/StartBBSCodeSegment.java |
diffstat | 4 files changed, 37 insertions(+), 42 deletions(-) [+] |
line wrap: on
line diff
--- a/src/alice/jungle/persistence/PersistentJungleTree.java Mon Nov 18 17:08:17 2013 +0900 +++ b/src/alice/jungle/persistence/PersistentJungleTree.java Mon Nov 18 19:34:15 2013 +0900 @@ -44,5 +44,10 @@ return cs.getRoot(); } + @Override + public JungleTreeEditor getLocalTreeEditor() { + return getTreeEditor(); + } + }
--- a/src/jungle/app/bbs/JungleManager.java Mon Nov 18 17:08:17 2013 +0900 +++ b/src/jungle/app/bbs/JungleManager.java Mon Nov 18 19:34:15 2013 +0900 @@ -5,6 +5,7 @@ import java.util.Iterator; import alice.jungle.datasegment.store.container.DefaultTreeOperationLogContainer; +import alice.jungle.operations.NetworkTreeOperationLog; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.DefaultJungle; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.Jungle; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTree; @@ -83,14 +84,8 @@ return null; } - public static Either<Error, JungleTreeEditor> update(DefaultTreeOperationLogContainer container) { - DefaultTreeOperationLog log = null; - try { - log = container.convert(); - } catch (IOException e) { - e.printStackTrace(); - } - String treeName = container.getTreeName(); + public static Either<Error, JungleTreeEditor> update(NetworkTreeOperationLog netLog) { + String treeName = netLog.getTreeName(); Jungle jungle = JungleManager.getJungle(); if (jungle.getTreeByName(treeName) == null) { if(null == jungle.createNewTree(treeName)){ @@ -99,8 +94,10 @@ } JungleTree tree = jungle.getTreeByName(treeName); JungleTreeEditor editor = tree.getLocalTreeEditor(); - int pos = calculatePosition(tree.getRootNode(), container.getTimeStamp()); - Either<Error, JungleTreeEditor> either = JungleManager.edit(editor, log, pos); + + // int pos = calculatePosition(tree.getRootNode(), netLog.getTimeStamp()); + int pos = 0; + Either<Error, JungleTreeEditor> either = JungleManager.edit(editor, netLog, pos); if(either.isA()) { throw new IllegalStateException(); }
--- a/src/jungle/app/bbs/codesegment/LogUpdateCodeSegment.java Mon Nov 18 17:08:17 2013 +0900 +++ b/src/jungle/app/bbs/codesegment/LogUpdateCodeSegment.java Mon Nov 18 19:34:15 2013 +0900 @@ -2,6 +2,8 @@ +import java.util.List; + import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTreeEditor; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; @@ -9,44 +11,44 @@ import alice.codesegment.CodeSegment; import alice.datasegment.CommandType; import alice.datasegment.Receiver; -import alice.jungle.datasegment.HashSetDataSegment; -import alice.jungle.datasegment.store.container.DefaultTreeOperationLogContainer; +import alice.jungle.operations.NetworkTreeOperationLog; public class LogUpdateCodeSegment extends CodeSegment { - Receiver parentLog = ids.create(CommandType.PEEK); + Receiver log = ids.create(CommandType.PEEK); Receiver host = ids.create(CommandType.PEEK); - Receiver hashLog = ids.create(CommandType.PEEK); + Receiver clist = ids.create(CommandType.PEEK); + public LogUpdateCodeSegment() { - parentLog.setKey("parent", "log"); + log.setKey("log"); host.setKey("host"); - hashLog.setKey("hashLog"); + clist.setKey("_CLIST");; } public LogUpdateCodeSegment(int index) { - parentLog.setKey("parent", "log", index); + log.setKey("log", index); host.setKey("host"); - hashLog.setKey("hashLog"); + clist.setKey("_CLIST");; } public void run() { - int index = parentLog.index; -// String hostName = host.asString(); - DefaultTreeOperationLogContainer container = parentLog.asClass(DefaultTreeOperationLogContainer.class); - HashSetDataSegment ds = hashLog.asClass(HashSetDataSegment.class); - if(ds.hash.contains(container.getHashLogString())) { - ods.update("hashLog", ds); - new LogUpdateCodeSegment(index); - return; + int index = log.index; + NetworkTreeOperationLog netLog = log.asClass(NetworkTreeOperationLog.class); + String hostName = host.asString(); + @SuppressWarnings("unchecked") + List<String> list = clist.asClass(List.class); + if (!hostName.equals((log.from))) { + Either<Error, JungleTreeEditor> either = JungleManager.update(netLog); + if(either.isA()) { + throw new IllegalStateException(); + } } - Either<Error, JungleTreeEditor> either = JungleManager.update(container); - if(either.isA()) { - throw new IllegalStateException(); + for (String node : list) { + if (!node.equals(log.from)) { + ods.update(node, log.key, log.getVal()); + } } - ds.hash.add(container.getHashLogString()); - ods.update("hashLog", ds); - ods.put("log", container); new LogUpdateCodeSegment(index); } }
--- a/src/jungle/app/bbs/codesegment/StartBBSCodeSegment.java Mon Nov 18 17:08:17 2013 +0900 +++ b/src/jungle/app/bbs/codesegment/StartBBSCodeSegment.java Mon Nov 18 19:34:15 2013 +0900 @@ -71,16 +71,7 @@ } catch (Exception e) { e.printStackTrace(); } - - new ChildLogCheckCodeSegment(); - HashSetDataSegment hashLog = new HashSetDataSegment(); - ods.put("hashLog", hashLog); - - int num = new Integer(matcher.group(2)); - if (num != 0) { -// try {Thread.sleep(100);} catch(Exception e) { e.printStackTrace(); } - new LogUpdateCodeSegment(); - } + new LogUpdateCodeSegment(); } }