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);
|
49
|
21 public String location = "local";
|
39
|
22
|
47
|
23 public LogUpdateCodeSegment() {
|
|
24 host.setKey("host",0);
|
39
|
25 }
|
|
26
|
49
|
27 public LogUpdateCodeSegment(String _location) {
|
|
28 location = _location;
|
|
29 host.setKey("local","host",0);
|
|
30 }
|
|
31
|
34
|
32 public void run() {
|
42
|
33 int index = arg1.index;
|
47
|
34 String h = host.asString();
|
40
|
35 DefaultTreeOperationLogContainer container = arg1.asClass(DefaultTreeOperationLogContainer.class);
|
47
|
36 if(updaterIsMe(h, container)) {
|
|
37 LogUpdateCodeSegment updateCS = new LogUpdateCodeSegment();
|
49
|
38 updateCS.arg1.setKey(location, "log", index+1);
|
|
39 if(location.equals("local") && !iAmRootNode(h)) {
|
|
40 ods.put("parent", "log", container);
|
|
41 }
|
42
|
42 return;
|
|
43 }
|
40
|
44 DefaultTreeOperationLog log = null;
|
|
45 try {
|
|
46 log = container.convert();
|
|
47 } catch (IOException e) {
|
|
48 e.printStackTrace();
|
|
49 }
|
43
|
50 JungleTree tree = JungleManager.getJungle().getTreeByName("boards");
|
40
|
51 JungleTreeEditor editor = tree.getTreeEditor();
|
43
|
52 Either<Error, JungleTreeEditor> either = JungleManager.edit(editor, log);
|
40
|
53 if(either.isA()) {
|
|
54 throw new IllegalStateException();
|
|
55 }
|
|
56 editor = either.b();
|
46
|
57 either = editor.success();
|
|
58 if(either.isA()) {
|
|
59 throw new IllegalStateException();
|
|
60 }
|
49
|
61 if(location.equals("local")) {
|
|
62 NetworkDefaultJungleTreeEditor nEditor = (NetworkDefaultJungleTreeEditor) editor;
|
|
63 container.setRevision(Long.parseLong(nEditor.getRevision()));
|
|
64 container.setUpdaterName(nEditor.getUpdaterName());
|
|
65 }
|
|
66 ods.put("log", container);
|
47
|
67 LogUpdateCodeSegment updateCS = new LogUpdateCodeSegment();
|
49
|
68 updateCS.arg1.setKey(location, "log", index+1);
|
34
|
69 }
|
42
|
70
|
47
|
71 private boolean updaterIsMe(String host, DefaultTreeOperationLogContainer container) {
|
|
72 return host.equals(container.getServerName());
|
42
|
73 }
|
|
74
|
49
|
75 private boolean iAmRootNode(String h) {
|
|
76 return h.equals("node0");
|
|
77 }
|
|
78
|
42
|
79
|
|
80
|
34
|
81 }
|