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