Mercurial > hg > Database > jungle-network
annotate src/jungle/test/bbs/codesegment/ChildLogCheckCodeSegment.java @ 58:4851344e120e
fix bug LogUpdateCodeSegment and ChildLogCheckCodeSegment
author | one |
---|---|
date | Mon, 15 Jul 2013 10:13:34 +0900 |
parents | 1bfd13f831ea |
children | 8a532ca5df80 |
rev | line source |
---|---|
50 | 1 package jungle.test.bbs.codesegment; |
2 | |
3 import java.io.IOException; | |
56 | 4 import java.util.Iterator; |
50 | 5 |
6 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTree; | |
7 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTreeEditor; | |
56 | 8 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.Node; |
9 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; | |
10 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultNodePath; | |
50 | 11 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.DefaultTreeOperationLog; |
56 | 12 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.DefaultEither; |
13 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.DefaultError; | |
50 | 14 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; |
15 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; | |
16 import jungle.test.bbs.JungleManager; | |
17 import alice.codesegment.CodeSegment; | |
18 import alice.datasegment.CommandType; | |
19 import alice.datasegment.Receiver; | |
52 | 20 import alice.jungle.codesegment.HashLogUpdateCodeSegment; |
21 import alice.jungle.datasegment.HashSetDataSegment; | |
50 | 22 import alice.jungle.datasegment.store.operations.DefaultTreeOperationLogContainer; |
23 | |
24 public class ChildLogCheckCodeSegment extends CodeSegment { | |
25 | |
52 | 26 Receiver host = ids.create(CommandType.PEEK); |
50 | 27 Receiver childLog = ids.create(CommandType.TAKE); |
52 | 28 Receiver hashLog = ids.create(CommandType.PEEK); |
50 | 29 |
30 public ChildLogCheckCodeSegment() { | |
51 | 31 host.setKey("host"); |
32 childLog.setKey("local","childLog"); | |
52 | 33 hashLog.setKey("hashLog"); |
50 | 34 } |
58
4851344e120e
fix bug LogUpdateCodeSegment and ChildLogCheckCodeSegment
one
parents:
57
diff
changeset
|
35 |
4851344e120e
fix bug LogUpdateCodeSegment and ChildLogCheckCodeSegment
one
parents:
57
diff
changeset
|
36 public ChildLogCheckCodeSegment(int index) { |
4851344e120e
fix bug LogUpdateCodeSegment and ChildLogCheckCodeSegment
one
parents:
57
diff
changeset
|
37 host.setKey("host"); |
4851344e120e
fix bug LogUpdateCodeSegment and ChildLogCheckCodeSegment
one
parents:
57
diff
changeset
|
38 childLog.setKey("local","childLog", index); |
4851344e120e
fix bug LogUpdateCodeSegment and ChildLogCheckCodeSegment
one
parents:
57
diff
changeset
|
39 hashLog.setKey("hashLog"); |
4851344e120e
fix bug LogUpdateCodeSegment and ChildLogCheckCodeSegment
one
parents:
57
diff
changeset
|
40 } |
4851344e120e
fix bug LogUpdateCodeSegment and ChildLogCheckCodeSegment
one
parents:
57
diff
changeset
|
41 |
50 | 42 |
43 public void run() { | |
51 | 44 System.out.println("--ChildLogCheckCodeSegment--"); |
58
4851344e120e
fix bug LogUpdateCodeSegment and ChildLogCheckCodeSegment
one
parents:
57
diff
changeset
|
45 int index = childLog.index; |
4851344e120e
fix bug LogUpdateCodeSegment and ChildLogCheckCodeSegment
one
parents:
57
diff
changeset
|
46 HashSetDataSegment ds = hashLog.asClass(HashSetDataSegment.class); |
51 | 47 String hostName = host.asString(); |
50 | 48 DefaultTreeOperationLogContainer container = childLog.asClass(DefaultTreeOperationLogContainer.class); |
49 DefaultTreeOperationLog log = null; | |
50 try { | |
51 log = container.convert(); | |
52 } catch (IOException e) { | |
53 e.printStackTrace(); | |
54 } | |
51 | 55 String treeName = container.getTreeName(); |
56 if (JungleManager.getJungle().getTreeByName(treeName) == null) { | |
57 if(null == JungleManager.getJungle().createNewTree(treeName)){ | |
58 throw new IllegalStateException(); | |
59 } | |
60 } | |
61 JungleTree tree = JungleManager.getJungle().getTreeByName(treeName); | |
50 | 62 JungleTreeEditor editor = tree.getTreeEditor(); |
56 | 63 Either<DefaultError, Integer> e = checkTimeStamp(tree.getRootNode(), container.getTimeStamp()); |
64 Either<Error, JungleTreeEditor> either; | |
58
4851344e120e
fix bug LogUpdateCodeSegment and ChildLogCheckCodeSegment
one
parents:
57
diff
changeset
|
65 if(e.isA()) { |
57 | 66 either = JungleManager.edit(editor, log, container.getPosition()); |
56 | 67 } else { |
58
4851344e120e
fix bug LogUpdateCodeSegment and ChildLogCheckCodeSegment
one
parents:
57
diff
changeset
|
68 either = JungleManager.edit(editor, log, e.b()); |
56 | 69 } |
50 | 70 if(either.isA()) { |
71 throw new IllegalStateException(); | |
72 } | |
73 editor = either.b(); | |
74 either = editor.success(); | |
75 if(either.isA()) { | |
76 throw new IllegalStateException(); | |
52 | 77 } |
78 ds.hash.add(container.getHashLogString()); | |
79 ods.update("hashLog", ds); | |
50 | 80 ods.put("log", container); |
58
4851344e120e
fix bug LogUpdateCodeSegment and ChildLogCheckCodeSegment
one
parents:
57
diff
changeset
|
81 new ChildLogCheckCodeSegment(index); |
51 | 82 if(!hostName.equals("node0")) { |
83 ods.put("parent", "childLog", container); | |
84 } | |
50 | 85 } |
86 | |
56 | 87 private DefaultEither<DefaultError, Integer> checkTimeStamp(Node node, long newNodeTimeStamp) { |
88 int count = 0; | |
89 long childTimeStamp = 0; | |
90 for(Iterator<Node> iter = node.getChildren().iterator();iter.hasNext();) { | |
91 Node n = iter.next(); | |
92 if(n.getAttributes().get("timestamp") == null) { | |
93 return DefaultEither.newA(new DefaultError()); | |
94 } | |
95 if(n.getAttributes().get("timestamp") != null) { | |
96 childTimeStamp = n.getAttributes().get("timestamp").getLong(); | |
97 if (newNodeTimeStamp < childTimeStamp) { | |
98 break; | |
99 } | |
100 } | |
101 count++; | |
102 } | |
103 return DefaultEither.newB(count); | |
104 } | |
50 | 105 } |