34
|
1 package alice.jungle.codesegment;
|
|
2
|
40
|
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;
|
34
|
11 import alice.codesegment.CodeSegment;
|
|
12 import alice.datasegment.CommandType;
|
|
13 import alice.datasegment.Receiver;
|
40
|
14 import alice.jungle.datasegment.store.operations.DefaultTreeOperationLogContainer;
|
46
|
15 import alice.jungle.transaction.NetworkDefaultJungleTreeEditor;
|
34
|
16
|
|
17 public class LogUpdateCodeSegment extends CodeSegment {
|
|
18
|
42
|
19 public Receiver arg1 = ids.create(CommandType.PEEK);
|
47
|
20 public Receiver host = ids.create(CommandType.PEEK);
|
39
|
21
|
47
|
22 public LogUpdateCodeSegment() {
|
|
23 host.setKey("host",0);
|
39
|
24 }
|
|
25
|
34
|
26 public void run() {
|
42
|
27 System.out.println("--LogUpdateCodeSegment--");
|
|
28 int index = arg1.index;
|
47
|
29 String h = host.asString();
|
40
|
30 DefaultTreeOperationLogContainer container = arg1.asClass(DefaultTreeOperationLogContainer.class);
|
47
|
31 if(updaterIsMe(h, container)) {
|
|
32 LogUpdateCodeSegment updateCS = new LogUpdateCodeSegment();
|
|
33 updateCS.arg1.setKey("log", index+1);
|
42
|
34 return;
|
|
35 }
|
40
|
36 DefaultTreeOperationLog log = null;
|
|
37 try {
|
|
38 log = container.convert();
|
|
39 } catch (IOException e) {
|
|
40 e.printStackTrace();
|
|
41 }
|
43
|
42 JungleTree tree = JungleManager.getJungle().getTreeByName("boards");
|
40
|
43 JungleTreeEditor editor = tree.getTreeEditor();
|
43
|
44 Either<Error, JungleTreeEditor> either = JungleManager.edit(editor, log);
|
40
|
45 if(either.isA()) {
|
|
46 throw new IllegalStateException();
|
|
47 }
|
|
48 editor = either.b();
|
46
|
49 either = editor.success();
|
|
50 if(either.isA()) {
|
|
51 throw new IllegalStateException();
|
|
52 }
|
47
|
53 LogUpdateCodeSegment updateCS = new LogUpdateCodeSegment();
|
|
54 updateCS.arg1.setKey("log", index+1);
|
34
|
55 }
|
42
|
56
|
47
|
57 private boolean updaterIsMe(String host, DefaultTreeOperationLogContainer container) {
|
|
58 return host.equals(container.getServerName());
|
42
|
59 }
|
|
60
|
|
61
|
|
62
|
34
|
63 }
|