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;
|
|
14 import alice.jungle.datasegment.store.operations.DefaultTreeOperationLogContainer;
|
|
15
|
|
16 public class ChildLogCheckCodeSegment extends CodeSegment {
|
|
17
|
|
18 Receiver childLog = ids.create(CommandType.TAKE);
|
51
|
19 Receiver host = ids.create(CommandType.PEEK);
|
50
|
20
|
|
21 public ChildLogCheckCodeSegment() {
|
51
|
22 host.setKey("host");
|
|
23 childLog.setKey("local","childLog");
|
50
|
24 }
|
|
25
|
|
26 public void run() {
|
51
|
27 System.out.println("--ChildLogCheckCodeSegment--");
|
|
28 String hostName = host.asString();
|
50
|
29 DefaultTreeOperationLogContainer container = childLog.asClass(DefaultTreeOperationLogContainer.class);
|
|
30 DefaultTreeOperationLog log = null;
|
|
31 try {
|
|
32 log = container.convert();
|
|
33 } catch (IOException e) {
|
|
34 e.printStackTrace();
|
|
35 }
|
51
|
36 String treeName = container.getTreeName();
|
|
37 if (JungleManager.getJungle().getTreeByName(treeName) == null) {
|
|
38 if(null == JungleManager.getJungle().createNewTree(treeName)){
|
|
39 throw new IllegalStateException();
|
|
40 }
|
|
41 }
|
|
42 JungleTree tree = JungleManager.getJungle().getTreeByName(treeName);
|
50
|
43 JungleTreeEditor editor = tree.getTreeEditor();
|
|
44 Either<Error, JungleTreeEditor> either = JungleManager.edit(editor, log);
|
|
45 if(either.isA()) {
|
|
46 throw new IllegalStateException();
|
|
47 }
|
|
48 editor = either.b();
|
|
49 either = editor.success();
|
|
50 if(either.isA()) {
|
|
51 throw new IllegalStateException();
|
|
52 }
|
|
53 ods.put("log", container);
|
|
54 new ChildLogCheckCodeSegment();
|
51
|
55 if(!hostName.equals("node0")) {
|
|
56
|
|
57 ods.put("parent", "childLog", container);
|
|
58 }
|
50
|
59 }
|
|
60
|
|
61
|
|
62 }
|