2
|
1 package jp.ac.u_ryukyu.ie.cr.bbs.network.codesegment;
|
|
2
|
|
3 import alice.codesegment.CodeSegment;
|
|
4 import alice.datasegment.CommandType;
|
|
5 import alice.datasegment.Receiver;
|
|
6 import jp.ac.u_ryukyu.ie.cr.jungle.JungleTreeEditor;
|
|
7 import jp.ac.u_ryukyu.ie.cr.jungle.util.Either;
|
|
8 import jp.ac.u_ryukyu.ie.cr.jungle.util.Error;
|
|
9 import jp.ac.u_ryukyu.ie.cr.jungleNetwork.bbs.BulletinBoardJungleManager;
|
|
10 import jp.ac.u_ryukyu.ie.cr.jungleNetwork.operations.NetworkTreeOperationLog;
|
|
11
|
|
12 import java.util.List;
|
|
13
|
|
14 public class LogUpdateCodeSegment extends CodeSegment {
|
|
15
|
|
16 Receiver log = ids.create(CommandType.TAKE);
|
|
17 Receiver clist = ids.create(CommandType.PEEK);
|
|
18
|
|
19 public LogUpdateCodeSegment() {
|
|
20 log.setKey("log");
|
|
21 clist.setKey("_CLIST");;
|
|
22 }
|
|
23
|
|
24 public LogUpdateCodeSegment(int index) {
|
|
25 log.setKey("log", index);
|
|
26 clist.setKey("_CLIST");;
|
|
27 }
|
|
28
|
|
29 public void run() {
|
|
30 int index = log.index;
|
|
31 new jp.ac.u_ryukyu.ie.cr.jungleNetwork.bbs.codesegment.LogUpdateCodeSegment();
|
|
32 NetworkTreeOperationLog netLog = log.asClass(NetworkTreeOperationLog.class);
|
|
33 @SuppressWarnings("unchecked")
|
|
34 List<String> list = clist.asClass(List.class);
|
|
35 for (String node : list) {
|
|
36 if (!node.equals(log.from)) {
|
|
37 ods.put(node, log.key, log.getVal());
|
|
38 }
|
|
39 }
|
|
40 if (!log.from.equals("local")) {
|
|
41 Either<Error, JungleTreeEditor> either = BulletinBoardJungleManager.update(netLog);
|
|
42 if(either.isA()) {
|
|
43 new jp.ac.u_ryukyu.ie.cr.jungleNetwork.bbs.codesegment.LogUpdateCodeSegment(index);
|
|
44 throw new IllegalStateException();
|
|
45 }
|
|
46 }
|
|
47 }
|
|
48 }
|