comparison paper/chapter3.tex @ 48:6553b7a3717c

Modified chapter3
author Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
date Fri, 31 Jan 2014 09:31:57 +0900
parents b303f22d8b0d
children 7b595f4b341e
comparison
equal deleted inserted replaced
47:b303f22d8b0d 48:6553b7a3717c
236 送受信が可能である. 236 送受信が可能である.
237 237
238 238
239 \section{ログのシリアライズ} 239 \section{ログのシリアライズ}
240 Jungleの具体的な分散実装について述べる. 240 Jungleの具体的な分散実装について述べる.
241 Jungleの分散実装はデータ編集のログを他のサーバに送ることで行うことを第3章で説明した.
242 実装にあたり, 解決しなければならない問題はまず, ログをDataSegmentで扱える形にすることである. 241 実装にあたり, 解決しなければならない問題はまず, ログをDataSegmentで扱える形にすることである.
243 そのためには, @Messageアノテーションを付けたログのクラスの作成を行わなければならない. 242 そのためには, @Messageアノテーションを付けたログのクラスの作成を行わなければならない.
244 243
245 244
246 \subsection{TreeOperationLogの} 245 \subsection{TreeOperationLogのシリアライズ}
247 TreeOperationLogの仕様は次の通りである. 246 TreeOperationLogをシリアライズ可能な形にするにあたって気をつけなければならないのが, フィールドを
248 \begin{lstlisting}[frame=lrbt,label=src:treeoperationlog,aption=TreeOperationLogの仕様,numbers=left] 247 シリアライズ可能にする部分である.
248 TreeOperationLogはTreeOperationをいくつも保持し, TreeOperationはNodePathとNodeOperationを保持するものであった.
249 そのため, これら全てシリアライズ可能な形にしなければならない.
250
251 基本的にこれらの実装は, フィールドを全てプリミティブなものだけにすればよい.
252 MessagePackはListを扱うこともできるため, TreeOperationLogで継承されていたIterableの挙動もListを使うことで
253 実装を行うことができた.
254
255
256 このInterfaceをimplementsしつつシリアライズを行えるクラスとしてNetworkTreeOperationLogを実装した.
257 NetworkTreeOperationLogでは次のフィールドを保持する(\ref{src:nettreeoplog}).
258 \begin{lstlisting}[frame=lrbt,label=src:nettreeoplog,caption=NetworkTreeOperationLogの実装,numbers=left]
259 @Message
260 public class NetworkTreeOperationLog implements TreeOperationLog
261 {
262 public LinkedList<NetworkTreeOperation> list;
263 public int size;
264 String uuid;
265 String treeName;
266 long timestamp;
267 : // 実装が続いていく
268 \end{lstlisting}
269
270
271
272
273 TreeOperationLogの仕様はInterfaceにより定義される.
274 \begin{lstlisting}[frame=lrbt,label=src:treeoperationlog,caption=TreeOperationLogの仕様,numbers=left]
249 public interface TreeOperationLog extends Iterable<TreeOperation> 275 public interface TreeOperationLog extends Iterable<TreeOperation>
250 { 276 {
251 public TreeOperationLog add(NodePath _p,NodeOperation _op); 277 public TreeOperationLog add(NodePath _p,NodeOperation _op);
252 public TreeOperationLog append(TreeOperationLog _log); 278 public TreeOperationLog append(TreeOperationLog _log);
253 public int length(); 279 public int length();
254 } 280 }
255 \end{lstlisting} 281 \end{lstlisting}
256 IterableとしてTreeOperationを保持しているクラスがTreeOperationLogである. 282 \verb|Iterable<TreeOperationLog>|を継承しているクラスがTreeOperationLogとなる.
283 次にTreeOperationの仕様と, NodeOperation, NodePath の仕様について以下に示す
284 \begin{lstlisting}[frame=lrbt,label=src:treeop,caption=TreeOperationの仕様,numbers=left]
285 public interface TreeOperation
286 {
287 public NodePath getNodePath();
288 public NodeOperation getNodeOperation();
289 }
290 \end{lstlisting}
291
292 \begin{lstlisting}[frame=lrbt,label=src:nodeop,caption=NodeOperationの仕様,numbers=left]
293 public interface NodeOperation
294 {
295 public Command getCommand();
296 public <T extends EditableNode<T>> Either<Error,T> invoke(T _target);
297
298 public int getPosition();
299 public String getKey();
300 public ByteBuffer getValue();
301 }
302 \end{lstlisting}
303
304 \begin{lstlisting}[frame=lrbt,label=src:nodepath,caption=Nodepathの仕様,numbers=left]
305 public interface NodePath extends Iterable<Integer>
306 {
307 public NodePath add(int _pos);
308 public Pair<Integer,NodePath> pop();
309 public int size();
310 }
311 \end{lstlisting}
312
313
314
257 315
258 316
259 317
260 318
261 % TreeOperationLog に木の名前の情報がない 319 % TreeOperationLog に木の名前の情報がない