comparison src/jungle/app/bbs/codesegment/ChildLogCheckCodeSegment.java @ 66:29127ac788a6

move some files
author one
date Tue, 20 Aug 2013 17:38:09 +0900
parents src/jungle/test/bbs/codesegment/ChildLogCheckCodeSegment.java@ebf42371454b
children 87ec5dd0dc27
comparison
equal deleted inserted replaced
65:ebf42371454b 66:29127ac788a6
1 package jungle.app.bbs.codesegment;
2
3
4
5 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTreeEditor;
6 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either;
7 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error;
8 import jungle.app.bbs.JungleManager;
9 import alice.codesegment.CodeSegment;
10 import alice.datasegment.CommandType;
11 import alice.datasegment.Receiver;
12 import alice.jungle.datasegment.HashSetDataSegment;
13 import alice.jungle.datasegment.store.operations.DefaultTreeOperationLogContainer;
14
15 public class ChildLogCheckCodeSegment extends CodeSegment {
16
17 Receiver host = ids.create(CommandType.PEEK);
18 Receiver childLog = ids.create(CommandType.TAKE);
19 Receiver hashLog = ids.create(CommandType.PEEK);
20
21 public ChildLogCheckCodeSegment() {
22 host.setKey("host");
23 childLog.setKey("local","childLog");
24 hashLog.setKey("hashLog");
25 }
26
27 public ChildLogCheckCodeSegment(int index) {
28 host.setKey("host");
29 childLog.setKey("local","childLog", index);
30 hashLog.setKey("hashLog");
31 }
32
33 public void run() {
34 int index = childLog.index;
35 String hostName = host.asString();
36 DefaultTreeOperationLogContainer container = childLog.asClass(DefaultTreeOperationLogContainer.class);
37 HashSetDataSegment ds = hashLog.asClass(HashSetDataSegment.class);
38 if(ds.hash.contains(container.getHashLogString())) {
39 ods.update("hashLog", ds);
40 new LogUpdateCodeSegment(index);
41 return;
42 }
43 Either<Error, JungleTreeEditor> either = JungleManager.update(container);
44 if(either.isA()) {
45 throw new IllegalStateException();
46 }
47 ds.hash.add(container.getHashLogString());
48 ods.update("hashLog", ds);
49 ods.put("log", container);
50 new ChildLogCheckCodeSegment(index);
51 if(!hostName.equals("node0")) {
52 ods.put("parent", "childLog", container);
53 }
54 }
55 }