Mercurial > hg > Members > nobuyasu > jungle-network
comparison src/jungle/test/bbs/NetworkJungleBulletinBoard.java @ 56:ccfe9b5e8f11
bug LogUpdateCodeSegment
author | one |
---|---|
date | Sun, 14 Jul 2013 21:26:49 +0900 |
parents | 61b2de3f7730 |
children | 1bfd13f831ea |
comparison
equal
deleted
inserted
replaced
55:25edf76b65dc | 56:ccfe9b5e8f11 |
---|---|
1 package jungle.test.bbs; | 1 package jungle.test.bbs; |
2 | 2 |
3 import java.io.IOException; | 3 import java.io.IOException; |
4 import java.nio.ByteBuffer; | 4 import java.nio.ByteBuffer; |
5 import java.util.Date; | |
5 import java.util.concurrent.atomic.AtomicInteger; | 6 import java.util.concurrent.atomic.AtomicInteger; |
6 | 7 |
7 import alice.jungle.codesegment.HashLogUpdateCodeSegment; | 8 import alice.jungle.codesegment.HashLogUpdateCodeSegment; |
8 import alice.jungle.core.NetworkDefaultJungle; | 9 import alice.jungle.core.NetworkDefaultJungle; |
9 import alice.jungle.datasegment.store.operations.DefaultTreeOperationLogContainer; | 10 import alice.jungle.datasegment.store.operations.DefaultTreeOperationLogContainer; |
75 editor = either.b(); | 76 editor = either.b(); |
76 Either<Error,JungleTreeEditor> result = editor.success(); | 77 Either<Error,JungleTreeEditor> result = editor.success(); |
77 if(result.isA()){ | 78 if(result.isA()){ |
78 throw new IllegalStateException(); | 79 throw new IllegalStateException(); |
79 } | 80 } |
81 final long timestamp = new Date().getTime(); | |
80 /* Put DataSegment */ | 82 /* Put DataSegment */ |
81 try { | 83 try { |
82 putTreeOperationLog((NetworkDefaultJungleTreeEditor)editor); | 84 putTreeOperationLog((NetworkDefaultJungleTreeEditor)editor, timestamp); |
83 } catch (IOException e1) { | 85 } catch (IOException e1) { |
84 e1.printStackTrace(); | 86 e1.printStackTrace(); |
85 } | 87 } |
86 | 88 |
87 tree = jungle.getTreeByName(_name); | 89 tree = jungle.getTreeByName(_name); |
95 NodeEditor e = new NodeEditor(){ | 97 NodeEditor e = new NodeEditor(){ |
96 public <T extends EditableNode<T>> Either<Error, T> edit(T _e){ | 98 public <T extends EditableNode<T>> Either<Error, T> edit(T _e){ |
97 _e = _e.getAttributes().put("author",ByteBuffer.wrap(_author.getBytes())).b(); | 99 _e = _e.getAttributes().put("author",ByteBuffer.wrap(_author.getBytes())).b(); |
98 _e = _e.getAttributes().put("mes",ByteBuffer.wrap(_initMessage.getBytes())).b(); | 100 _e = _e.getAttributes().put("mes",ByteBuffer.wrap(_initMessage.getBytes())).b(); |
99 _e = _e.getAttributes().put("key",ByteBuffer.wrap(_editKey.getBytes())).b(); | 101 _e = _e.getAttributes().put("key",ByteBuffer.wrap(_editKey.getBytes())).b(); |
102 ByteBuffer tBuffer = ByteBuffer.allocate(16); | |
103 _e = _e.getAttributes().put("timestamp",tBuffer.putLong(timestamp)).b(); | |
100 return DefaultEither.newB(_e); | 104 return DefaultEither.newB(_e); |
101 } | 105 } |
102 }; | 106 }; |
103 | 107 |
104 either = editor.edit(root.add(0),e); | 108 either = editor.edit(root.add(0),e); |
107 } | 111 } |
108 editor = either.b(); | 112 editor = either.b(); |
109 editor.success(); | 113 editor.success(); |
110 /* Put DataSegment */ | 114 /* Put DataSegment */ |
111 try { | 115 try { |
112 putTreeOperationLog((NetworkDefaultJungleTreeEditor)editor); | 116 putTreeOperationLog((NetworkDefaultJungleTreeEditor)editor, timestamp); |
113 } catch (IOException e1) { | 117 } catch (IOException e1) { |
114 e1.printStackTrace(); | 118 e1.printStackTrace(); |
115 } | 119 } |
116 | 120 |
117 } | 121 } |
134 either = editor.addNewChildAt(path,size); | 138 either = editor.addNewChildAt(path,size); |
135 if(either.isA()){ | 139 if(either.isA()){ |
136 throw new IllegalStateException(); | 140 throw new IllegalStateException(); |
137 } | 141 } |
138 editor = either.b(); | 142 editor = either.b(); |
143 final long timestamp = new Date().getTime(); | |
139 NodeEditor e = new NodeEditor(){ | 144 NodeEditor e = new NodeEditor(){ |
140 public <T extends EditableNode<T>> Either<Error, T> edit(T _e){ | 145 public <T extends EditableNode<T>> Either<Error, T> edit(T _e){ |
141 _e = _e.getAttributes().put("author",ByteBuffer.wrap(_author.getBytes())).b(); | 146 _e = _e.getAttributes().put("author",ByteBuffer.wrap(_author.getBytes())).b(); |
142 _e = _e.getAttributes().put("mes",ByteBuffer.wrap(_message.getBytes())).b(); | 147 _e = _e.getAttributes().put("mes",ByteBuffer.wrap(_message.getBytes())).b(); |
143 _e = _e.getAttributes().put("key",ByteBuffer.wrap(_editKey.getBytes())).b(); | 148 _e = _e.getAttributes().put("key",ByteBuffer.wrap(_editKey.getBytes())).b(); |
149 ByteBuffer tBuffer = ByteBuffer.allocate(16); | |
150 _e = _e.getAttributes().put("timestamp",tBuffer.putLong(timestamp)).b(); | |
144 return DefaultEither.newB(_e); | 151 return DefaultEither.newB(_e); |
145 } | 152 } |
146 }; | 153 }; |
147 path = path.add(size); | 154 path = path.add(size); |
148 either = editor.edit(path,e); | 155 either = editor.edit(path,e); |
150 throw new IllegalStateException(); | 157 throw new IllegalStateException(); |
151 } | 158 } |
152 editor = either.b(); | 159 editor = either.b(); |
153 either = editor.success(); | 160 either = editor.success(); |
154 try { | 161 try { |
155 putTreeOperationLog((NetworkDefaultJungleTreeEditor)editor); | 162 putTreeOperationLog((NetworkDefaultJungleTreeEditor)editor, timestamp); |
156 } catch (IOException e1) { | 163 } catch (IOException e1) { |
157 e1.printStackTrace(); | 164 e1.printStackTrace(); |
158 } | 165 } |
159 }while(either.isA()); | 166 }while(either.isA()); |
160 /* Put DataSegment */ | 167 /* Put DataSegment */ |
168 DefaultNodePath path = new DefaultNodePath(); | 175 DefaultNodePath path = new DefaultNodePath(); |
169 path = path.add(Integer.parseInt(_uuid)); | 176 path = path.add(Integer.parseInt(_uuid)); |
170 | 177 |
171 JungleTree tree = jungle.getTreeByName(_board); | 178 JungleTree tree = jungle.getTreeByName(_board); |
172 editor = tree.getTreeEditor(); | 179 editor = tree.getTreeEditor(); |
180 final long timestamp = new Date().getTime(); | |
173 NodeEditor e = new NodeEditor(){ | 181 NodeEditor e = new NodeEditor(){ |
174 public <T extends EditableNode<T>> Either<Error, T> edit(T _e){ | 182 public <T extends EditableNode<T>> Either<Error, T> edit(T _e){ |
175 _e = _e.getAttributes().put("author",ByteBuffer.wrap(_author.getBytes())).b(); | 183 _e = _e.getAttributes().put("author",ByteBuffer.wrap(_author.getBytes())).b(); |
176 _e = _e.getAttributes().put("mes",ByteBuffer.wrap(_message.getBytes())).b(); | 184 _e = _e.getAttributes().put("mes",ByteBuffer.wrap(_message.getBytes())).b(); |
177 _e = _e.getAttributes().put("key",ByteBuffer.wrap(_editKey.getBytes())).b(); | 185 _e = _e.getAttributes().put("key",ByteBuffer.wrap(_editKey.getBytes())).b(); |
186 ByteBuffer tBuffer = ByteBuffer.allocate(16); | |
187 _e = _e.getAttributes().put("timestamp",tBuffer.putLong(timestamp)).b(); | |
178 return DefaultEither.newB(_e); | 188 return DefaultEither.newB(_e); |
179 } | 189 } |
180 }; | 190 }; |
181 | 191 |
182 either = editor.edit(path,e); | 192 either = editor.edit(path,e); |
184 throw new IllegalStateException(); | 194 throw new IllegalStateException(); |
185 } | 195 } |
186 editor = either.b(); | 196 editor = either.b(); |
187 either = editor.success(); | 197 either = editor.success(); |
188 try { | 198 try { |
189 putTreeOperationLog((NetworkDefaultJungleTreeEditor)editor); | 199 putTreeOperationLog((NetworkDefaultJungleTreeEditor)editor, timestamp); |
190 } catch (IOException e1) { | 200 } catch (IOException e1) { |
191 e1.printStackTrace(); | 201 e1.printStackTrace(); |
192 } | 202 } |
193 }while(either.isA()); | 203 }while(either.isA()); |
194 } | 204 } |
211 }; | 221 }; |
212 | 222 |
213 return new IterableConverter<BoardMessage,Node>(chs,converter); | 223 return new IterableConverter<BoardMessage,Node>(chs,converter); |
214 } | 224 } |
215 | 225 |
216 private void putTreeOperationLog(NetworkDefaultJungleTreeEditor editor) throws IOException { | 226 private void putTreeOperationLog(NetworkDefaultJungleTreeEditor editor, long timestamp) throws IOException { |
217 String uuid = editor.getID(); | 227 String uuid = editor.getID(); |
218 String treeName = editor.getTreeName(); | 228 String treeName = editor.getTreeName(); |
219 String updaterName = editor.getUpdaterName(); | 229 String updaterName = editor.getUpdaterName(); |
220 String revision = editor.getRevision(); | 230 String revision = editor.getRevision(); |
221 Iterable<TreeOperation> log = editor.getTreeOperationLog(); | 231 Iterable<TreeOperation> log = editor.getTreeOperationLog(); |
222 putDataSegment(uuid, treeName, updaterName, log, revision); | 232 putDataSegment(uuid, treeName, updaterName, log, revision, timestamp); |
223 } | 233 } |
224 | 234 |
225 private void putDataSegment(String _uuid, String _treeName, String _updaterName, Iterable<TreeOperation> _log, String nextRevision) throws IOException { | 235 private void putDataSegment(String _uuid, String _treeName, String _updaterName, Iterable<TreeOperation> _log, String nextRevision, long timestamp) throws IOException { |
226 DefaultTreeOperationLogContainer container = new DefaultTreeOperationLogContainer(); | 236 DefaultTreeOperationLogContainer container = new DefaultTreeOperationLogContainer(); |
227 container.setTreeName(_treeName); | 237 container.setTreeName(_treeName); |
228 container.setUUID(_uuid); | 238 container.setUUID(_uuid); |
229 container.setUpdaterName(_updaterName); | 239 container.setUpdaterName(_updaterName); |
230 container.setRevision(nextRevision); | 240 container.setRevision(nextRevision); |
231 container.unconvert(_log); | 241 container.unconvert(_log); |
232 NullCodeSegmentForUpdate cs = new NullCodeSegmentForUpdate(); | 242 container.setTimeStamp(timestamp); |
243 HashLogUpdateCodeSegment cs = new HashLogUpdateCodeSegment(); | |
244 container.getHashLogString(); | |
233 cs.ods.put("log", container); | 245 cs.ods.put("log", container); |
234 new HashLogUpdateCodeSegment(container.getHashLogString()); | 246 cs.ods.put("logString", container.getHashLogString()); |
235 System.out.println("putDataSegment"); | 247 System.out.println("putDataSegment : "+container.getHashLogString()); |
236 System.out.println(container.getHashLogString()); | |
237 /* If this node is not Root node, push log to parent node's DS */ | 248 /* If this node is not Root node, push log to parent node's DS */ |
238 if(!_updaterName.equals("node0")) { | 249 if(!_updaterName.equals("node0")) { |
239 cs.ods.put("parent", "childLog", container); | 250 cs.ods.put("parent", "childLog", container); |
240 } | 251 } |
241 } | 252 } |