Mercurial > hg > Members > nobuyasu > jungle-network
comparison src/jungle/app/bbs/NetworkJungleBulletinBoard.java @ 93:75cf01a430a6
Added LocalTreeEditor
author | one |
---|---|
date | Fri, 15 Nov 2013 12:23:59 +0900 |
parents | e95faa202b4f |
children |
comparison
equal
deleted
inserted
replaced
92:e95faa202b4f | 93:75cf01a430a6 |
---|---|
1 package jungle.app.bbs; | 1 package jungle.app.bbs; |
2 | 2 |
3 import java.io.IOException; | |
4 import java.nio.ByteBuffer; | 3 import java.nio.ByteBuffer; |
5 import java.util.Date; | 4 import java.util.Date; |
6 import java.util.concurrent.atomic.AtomicInteger; | 5 import java.util.concurrent.atomic.AtomicInteger; |
7 | 6 |
8 import alice.jungle.core.NetworkDefaultJungle; | 7 import alice.jungle.core.NetworkDefaultJungle; |
9 import alice.jungle.datasegment.store.container.DefaultTreeOperationLogContainer; | |
10 import alice.jungle.persistence.AliceJournal; | 8 import alice.jungle.persistence.AliceJournal; |
11 import alice.jungle.transaction.NetworkDefaultJungleTreeEditor; | |
12 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.Jungle; | 9 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.Jungle; |
13 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTree; | 10 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTree; |
14 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTreeEditor; | 11 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTreeEditor; |
15 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.Children; | 12 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.Children; |
16 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.Node; | 13 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.Node; |
17 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultNodePath; | 14 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultNodePath; |
18 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultTreeEditor; | 15 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultTreeEditor; |
19 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.TreeOperation; | |
20 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.EditableNode; | 16 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.EditableNode; |
21 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.NodeEditor; | 17 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.NodeEditor; |
22 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction.DefaultTreeNode; | |
23 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.DefaultTraverser; | 18 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.DefaultTraverser; |
24 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.DefaultEither; | 19 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.DefaultEither; |
25 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; | 20 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; |
26 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; | 21 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; |
27 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.IterableConverter; | 22 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.IterableConverter; |
28 import jungle.app.bbs.codesegment.HashLogUpdateCodeSegment; | |
29 | 23 |
30 public class NetworkJungleBulletinBoard implements BulletinBoard | 24 public class NetworkJungleBulletinBoard implements BulletinBoard |
31 { | 25 { |
32 private final Jungle jungle; | 26 private final Jungle jungle; |
33 | 27 |
77 Either<Error,JungleTreeEditor> result = editor.success(); | 71 Either<Error,JungleTreeEditor> result = editor.success(); |
78 if(result.isA()){ | 72 if(result.isA()){ |
79 throw new IllegalStateException(); | 73 throw new IllegalStateException(); |
80 } | 74 } |
81 final long timestamp = new Date().getTime(); | 75 final long timestamp = new Date().getTime(); |
82 /* Put DataSegment */ | 76 |
83 try { | |
84 putTreeOperationLog((NetworkDefaultJungleTreeEditor)editor,timestamp); | |
85 } catch (IOException e1) { | |
86 e1.printStackTrace(); | |
87 } | |
88 | 77 |
89 tree = jungle.getTreeByName(_name); | 78 tree = jungle.getTreeByName(_name); |
90 editor = tree.getTreeEditor(); | 79 editor = tree.getTreeEditor(); |
91 either = editor.addNewChildAt(root,0); | 80 either = editor.addNewChildAt(root,0); |
92 if(either.isA()){ | 81 if(either.isA()){ |
109 if(either.isA()){ | 98 if(either.isA()){ |
110 throw new IllegalStateException(); | 99 throw new IllegalStateException(); |
111 } | 100 } |
112 editor = either.b(); | 101 editor = either.b(); |
113 editor.success(); | 102 editor.success(); |
114 /* Put DataSegment */ | |
115 try { | |
116 putTreeOperationLog((NetworkDefaultJungleTreeEditor)editor, timestamp); | |
117 } catch (IOException e1) { | |
118 e1.printStackTrace(); | |
119 } | |
120 | 103 |
121 } | 104 } |
122 | 105 |
123 public void createBoardMessage(final String _board,final String _author,final String _message,final String _editKey) | 106 public void createBoardMessage(final String _board,final String _author,final String _message,final String _editKey) |
124 { | 107 { |
155 if(either.isA()){ | 138 if(either.isA()){ |
156 throw new IllegalStateException(); | 139 throw new IllegalStateException(); |
157 } | 140 } |
158 editor = either.b(); | 141 editor = either.b(); |
159 either = editor.success(); | 142 either = editor.success(); |
160 try { | 143 |
161 NetworkDefaultJungleTreeEditor<DefaultTreeNode> netEditor = (NetworkDefaultJungleTreeEditor<DefaultTreeNode>) editor; | |
162 putTreeOperationLog(netEditor, timestamp); | |
163 } catch (IOException e1) { | |
164 e1.printStackTrace(); | |
165 } | |
166 }while(either.isA()); | 144 }while(either.isA()); |
167 /* Put DataSegment */ | 145 /* Put DataSegment */ |
168 } | 146 } |
169 | 147 |
170 public void editMessage(String _board,String _uuid,final String _author,final String _message,final String _editKey) | 148 public void editMessage(String _board,String _uuid,final String _author,final String _message,final String _editKey) |
191 if(either.isA()){ | 169 if(either.isA()){ |
192 throw new IllegalStateException(); | 170 throw new IllegalStateException(); |
193 } | 171 } |
194 editor = either.b(); | 172 editor = either.b(); |
195 either = editor.success(); | 173 either = editor.success(); |
196 try { | |
197 putTreeOperationLog((NetworkDefaultJungleTreeEditor)editor, timestamp); | |
198 } catch (IOException e1) { | |
199 e1.printStackTrace(); | |
200 } | |
201 if(!either.isA()) { | 174 if(!either.isA()) { |
202 return; | 175 return; |
203 } | 176 } |
204 } | 177 } |
205 | 178 |
223 }; | 196 }; |
224 | 197 |
225 return new IterableConverter<BoardMessage,Node>(chs,converter); | 198 return new IterableConverter<BoardMessage,Node>(chs,converter); |
226 } | 199 } |
227 | 200 |
228 private void putTreeOperationLog(NetworkDefaultJungleTreeEditor<DefaultTreeNode> editor, long timestamp) throws IOException { | |
229 String uuid = editor.getID(); | |
230 String treeName = editor.getTreeName(); | |
231 String updaterName = editor.getID(); | |
232 String revision = editor.getRevision(); | |
233 Iterable<TreeOperation> log = editor.getTreeOperationLog(); | |
234 putDataSegment(uuid, treeName, updaterName, log, revision, timestamp); | |
235 } | |
236 | |
237 private void putDataSegment(String _uuid, String _treeName, String _updaterName, Iterable<TreeOperation> _log, String nextRevision,long timestamp) throws IOException { | |
238 DefaultTreeOperationLogContainer container = new DefaultTreeOperationLogContainer(); | |
239 container.setTreeName(_treeName); | |
240 container.setUUID(_uuid); | |
241 container.setUpdaterName(_updaterName); | |
242 container.setRevision(nextRevision); | |
243 container.unconvert(_log); | |
244 container.setTimeStamp(timestamp); | |
245 HashLogUpdateCodeSegment cs = new HashLogUpdateCodeSegment(); | |
246 cs.ods.put("log", container); | |
247 cs.ods.put("logString", container.getHashLogString()); | |
248 /* If this node is not Root node, push log to parent node's DS */ | |
249 if(!_updaterName.equals("node0")) { | |
250 cs.ods.put("parent", "childLog", container); | |
251 } | |
252 } | |
253 | 201 |
254 | 202 |
255 private static class BoardMessageImpl implements BoardMessage | 203 private static class BoardMessageImpl implements BoardMessage |
256 { | 204 { |
257 private final String author; | 205 private final String author; |