Mercurial > hg > Database > jungle-network
comparison src/jungle/app/bbs/codesegment/LogUpdateCodeSegment.java @ 96:fcce7ca4adb9
Modified LogUpdateCodesegment
author | one |
---|---|
date | Mon, 18 Nov 2013 19:34:15 +0900 |
parents | 87ec5dd0dc27 |
children | 11ad00323206 |
comparison
equal
deleted
inserted
replaced
95:dcd767b76f8d | 96:fcce7ca4adb9 |
---|---|
1 package jungle.app.bbs.codesegment; | 1 package jungle.app.bbs.codesegment; |
2 | 2 |
3 | 3 |
4 | |
5 import java.util.List; | |
4 | 6 |
5 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTreeEditor; | 7 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTreeEditor; |
6 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; | 8 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; |
7 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; | 9 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; |
8 import jungle.app.bbs.JungleManager; | 10 import jungle.app.bbs.JungleManager; |
9 import alice.codesegment.CodeSegment; | 11 import alice.codesegment.CodeSegment; |
10 import alice.datasegment.CommandType; | 12 import alice.datasegment.CommandType; |
11 import alice.datasegment.Receiver; | 13 import alice.datasegment.Receiver; |
12 import alice.jungle.datasegment.HashSetDataSegment; | 14 import alice.jungle.operations.NetworkTreeOperationLog; |
13 import alice.jungle.datasegment.store.container.DefaultTreeOperationLogContainer; | |
14 | 15 |
15 public class LogUpdateCodeSegment extends CodeSegment { | 16 public class LogUpdateCodeSegment extends CodeSegment { |
16 | 17 |
17 Receiver parentLog = ids.create(CommandType.PEEK); | 18 Receiver log = ids.create(CommandType.PEEK); |
18 Receiver host = ids.create(CommandType.PEEK); | 19 Receiver host = ids.create(CommandType.PEEK); |
19 Receiver hashLog = ids.create(CommandType.PEEK); | 20 Receiver clist = ids.create(CommandType.PEEK); |
21 | |
20 | 22 |
21 public LogUpdateCodeSegment() { | 23 public LogUpdateCodeSegment() { |
22 parentLog.setKey("parent", "log"); | 24 log.setKey("log"); |
23 host.setKey("host"); | 25 host.setKey("host"); |
24 hashLog.setKey("hashLog"); | 26 clist.setKey("_CLIST");; |
25 } | 27 } |
26 | 28 |
27 public LogUpdateCodeSegment(int index) { | 29 public LogUpdateCodeSegment(int index) { |
28 parentLog.setKey("parent", "log", index); | 30 log.setKey("log", index); |
29 host.setKey("host"); | 31 host.setKey("host"); |
30 hashLog.setKey("hashLog"); | 32 clist.setKey("_CLIST");; |
31 } | 33 } |
32 | 34 |
33 public void run() { | 35 public void run() { |
34 int index = parentLog.index; | 36 int index = log.index; |
35 // String hostName = host.asString(); | 37 NetworkTreeOperationLog netLog = log.asClass(NetworkTreeOperationLog.class); |
36 DefaultTreeOperationLogContainer container = parentLog.asClass(DefaultTreeOperationLogContainer.class); | 38 String hostName = host.asString(); |
37 HashSetDataSegment ds = hashLog.asClass(HashSetDataSegment.class); | 39 @SuppressWarnings("unchecked") |
38 if(ds.hash.contains(container.getHashLogString())) { | 40 List<String> list = clist.asClass(List.class); |
39 ods.update("hashLog", ds); | 41 if (!hostName.equals((log.from))) { |
40 new LogUpdateCodeSegment(index); | 42 Either<Error, JungleTreeEditor> either = JungleManager.update(netLog); |
41 return; | 43 if(either.isA()) { |
44 throw new IllegalStateException(); | |
45 } | |
42 } | 46 } |
43 Either<Error, JungleTreeEditor> either = JungleManager.update(container); | 47 for (String node : list) { |
44 if(either.isA()) { | 48 if (!node.equals(log.from)) { |
45 throw new IllegalStateException(); | 49 ods.update(node, log.key, log.getVal()); |
50 } | |
46 } | 51 } |
47 ds.hash.add(container.getHashLogString()); | |
48 ods.update("hashLog", ds); | |
49 ods.put("log", container); | |
50 new LogUpdateCodeSegment(index); | 52 new LogUpdateCodeSegment(index); |
51 } | 53 } |
52 } | 54 } |