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