annotate src/jungle/test/bbs/codesegment/ChildLogCheckCodeSegment.java @ 53:f47a02368099

implemented timestamp in DefaultTreeOperationLogContainer
author one
date Sun, 14 Jul 2013 16:13:37 +0900
parents 61b2de3f7730
children ccfe9b5e8f11
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
50
459b50f1a6ee add ChildLogCheckCodeSegment.
one
parents:
diff changeset
1 package jungle.test.bbs.codesegment;
459b50f1a6ee add ChildLogCheckCodeSegment.
one
parents:
diff changeset
2
459b50f1a6ee add ChildLogCheckCodeSegment.
one
parents:
diff changeset
3 import java.io.IOException;
459b50f1a6ee add ChildLogCheckCodeSegment.
one
parents:
diff changeset
4
459b50f1a6ee add ChildLogCheckCodeSegment.
one
parents:
diff changeset
5 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTree;
459b50f1a6ee add ChildLogCheckCodeSegment.
one
parents:
diff changeset
6 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTreeEditor;
459b50f1a6ee add ChildLogCheckCodeSegment.
one
parents:
diff changeset
7 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.DefaultTreeOperationLog;
459b50f1a6ee add ChildLogCheckCodeSegment.
one
parents:
diff changeset
8 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either;
459b50f1a6ee add ChildLogCheckCodeSegment.
one
parents:
diff changeset
9 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error;
459b50f1a6ee add ChildLogCheckCodeSegment.
one
parents:
diff changeset
10 import jungle.test.bbs.JungleManager;
459b50f1a6ee add ChildLogCheckCodeSegment.
one
parents:
diff changeset
11 import alice.codesegment.CodeSegment;
459b50f1a6ee add ChildLogCheckCodeSegment.
one
parents:
diff changeset
12 import alice.datasegment.CommandType;
459b50f1a6ee add ChildLogCheckCodeSegment.
one
parents:
diff changeset
13 import alice.datasegment.Receiver;
52
61b2de3f7730 add HashSetDataSegment and HashLogUpdateCodeSegment.
one
parents: 51
diff changeset
14 import alice.jungle.codesegment.HashLogUpdateCodeSegment;
61b2de3f7730 add HashSetDataSegment and HashLogUpdateCodeSegment.
one
parents: 51
diff changeset
15 import alice.jungle.datasegment.HashSetDataSegment;
50
459b50f1a6ee add ChildLogCheckCodeSegment.
one
parents:
diff changeset
16 import alice.jungle.datasegment.store.operations.DefaultTreeOperationLogContainer;
459b50f1a6ee add ChildLogCheckCodeSegment.
one
parents:
diff changeset
17
459b50f1a6ee add ChildLogCheckCodeSegment.
one
parents:
diff changeset
18 public class ChildLogCheckCodeSegment extends CodeSegment {
459b50f1a6ee add ChildLogCheckCodeSegment.
one
parents:
diff changeset
19
52
61b2de3f7730 add HashSetDataSegment and HashLogUpdateCodeSegment.
one
parents: 51
diff changeset
20 Receiver host = ids.create(CommandType.PEEK);
50
459b50f1a6ee add ChildLogCheckCodeSegment.
one
parents:
diff changeset
21 Receiver childLog = ids.create(CommandType.TAKE);
52
61b2de3f7730 add HashSetDataSegment and HashLogUpdateCodeSegment.
one
parents: 51
diff changeset
22 Receiver hashLog = ids.create(CommandType.PEEK);
50
459b50f1a6ee add ChildLogCheckCodeSegment.
one
parents:
diff changeset
23
459b50f1a6ee add ChildLogCheckCodeSegment.
one
parents:
diff changeset
24 public ChildLogCheckCodeSegment() {
51
9e782b4eb06e add HashSetConvertDataSegment
one
parents: 50
diff changeset
25 host.setKey("host");
9e782b4eb06e add HashSetConvertDataSegment
one
parents: 50
diff changeset
26 childLog.setKey("local","childLog");
52
61b2de3f7730 add HashSetDataSegment and HashLogUpdateCodeSegment.
one
parents: 51
diff changeset
27 hashLog.setKey("hashLog");
50
459b50f1a6ee add ChildLogCheckCodeSegment.
one
parents:
diff changeset
28 }
459b50f1a6ee add ChildLogCheckCodeSegment.
one
parents:
diff changeset
29
459b50f1a6ee add ChildLogCheckCodeSegment.
one
parents:
diff changeset
30 public void run() {
51
9e782b4eb06e add HashSetConvertDataSegment
one
parents: 50
diff changeset
31 System.out.println("--ChildLogCheckCodeSegment--");
9e782b4eb06e add HashSetConvertDataSegment
one
parents: 50
diff changeset
32 String hostName = host.asString();
50
459b50f1a6ee add ChildLogCheckCodeSegment.
one
parents:
diff changeset
33 DefaultTreeOperationLogContainer container = childLog.asClass(DefaultTreeOperationLogContainer.class);
459b50f1a6ee add ChildLogCheckCodeSegment.
one
parents:
diff changeset
34 DefaultTreeOperationLog log = null;
459b50f1a6ee add ChildLogCheckCodeSegment.
one
parents:
diff changeset
35 try {
459b50f1a6ee add ChildLogCheckCodeSegment.
one
parents:
diff changeset
36 log = container.convert();
459b50f1a6ee add ChildLogCheckCodeSegment.
one
parents:
diff changeset
37 } catch (IOException e) {
459b50f1a6ee add ChildLogCheckCodeSegment.
one
parents:
diff changeset
38 e.printStackTrace();
459b50f1a6ee add ChildLogCheckCodeSegment.
one
parents:
diff changeset
39 }
51
9e782b4eb06e add HashSetConvertDataSegment
one
parents: 50
diff changeset
40 String treeName = container.getTreeName();
9e782b4eb06e add HashSetConvertDataSegment
one
parents: 50
diff changeset
41 if (JungleManager.getJungle().getTreeByName(treeName) == null) {
9e782b4eb06e add HashSetConvertDataSegment
one
parents: 50
diff changeset
42 if(null == JungleManager.getJungle().createNewTree(treeName)){
9e782b4eb06e add HashSetConvertDataSegment
one
parents: 50
diff changeset
43 throw new IllegalStateException();
9e782b4eb06e add HashSetConvertDataSegment
one
parents: 50
diff changeset
44 }
9e782b4eb06e add HashSetConvertDataSegment
one
parents: 50
diff changeset
45 }
9e782b4eb06e add HashSetConvertDataSegment
one
parents: 50
diff changeset
46 JungleTree tree = JungleManager.getJungle().getTreeByName(treeName);
50
459b50f1a6ee add ChildLogCheckCodeSegment.
one
parents:
diff changeset
47 JungleTreeEditor editor = tree.getTreeEditor();
459b50f1a6ee add ChildLogCheckCodeSegment.
one
parents:
diff changeset
48 Either<Error, JungleTreeEditor> either = JungleManager.edit(editor, log);
459b50f1a6ee add ChildLogCheckCodeSegment.
one
parents:
diff changeset
49 if(either.isA()) {
459b50f1a6ee add ChildLogCheckCodeSegment.
one
parents:
diff changeset
50 throw new IllegalStateException();
459b50f1a6ee add ChildLogCheckCodeSegment.
one
parents:
diff changeset
51 }
459b50f1a6ee add ChildLogCheckCodeSegment.
one
parents:
diff changeset
52 editor = either.b();
459b50f1a6ee add ChildLogCheckCodeSegment.
one
parents:
diff changeset
53 either = editor.success();
459b50f1a6ee add ChildLogCheckCodeSegment.
one
parents:
diff changeset
54 if(either.isA()) {
459b50f1a6ee add ChildLogCheckCodeSegment.
one
parents:
diff changeset
55 throw new IllegalStateException();
52
61b2de3f7730 add HashSetDataSegment and HashLogUpdateCodeSegment.
one
parents: 51
diff changeset
56 }
61b2de3f7730 add HashSetDataSegment and HashLogUpdateCodeSegment.
one
parents: 51
diff changeset
57 HashSetDataSegment ds = hashLog.asClass(HashSetDataSegment.class);
61b2de3f7730 add HashSetDataSegment and HashLogUpdateCodeSegment.
one
parents: 51
diff changeset
58 ds.hash.add(container.getHashLogString());
61b2de3f7730 add HashSetDataSegment and HashLogUpdateCodeSegment.
one
parents: 51
diff changeset
59 ods.update("hashLog", ds);
50
459b50f1a6ee add ChildLogCheckCodeSegment.
one
parents:
diff changeset
60 ods.put("log", container);
459b50f1a6ee add ChildLogCheckCodeSegment.
one
parents:
diff changeset
61 new ChildLogCheckCodeSegment();
51
9e782b4eb06e add HashSetConvertDataSegment
one
parents: 50
diff changeset
62 if(!hostName.equals("node0")) {
9e782b4eb06e add HashSetConvertDataSegment
one
parents: 50
diff changeset
63 ods.put("parent", "childLog", container);
9e782b4eb06e add HashSetConvertDataSegment
one
parents: 50
diff changeset
64 }
50
459b50f1a6ee add ChildLogCheckCodeSegment.
one
parents:
diff changeset
65 }
459b50f1a6ee add ChildLogCheckCodeSegment.
one
parents:
diff changeset
66
459b50f1a6ee add ChildLogCheckCodeSegment.
one
parents:
diff changeset
67
459b50f1a6ee add ChildLogCheckCodeSegment.
one
parents:
diff changeset
68 }