changeset 43:34ac359f20f1

Writed programming using Alice
author Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
date Wed, 29 Jan 2014 21:11:36 +0900
parents 585196deaace
children 618adf0a9b2b
files paper/chapter3.tex paper/master_paper.pdf
diffstat 2 files changed, 15 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/paper/chapter3.tex	Wed Jan 29 18:41:30 2014 +0900
+++ b/paper/chapter3.tex	Wed Jan 29 21:11:36 2014 +0900
@@ -102,8 +102,7 @@
 以下のコードにCodeSegmentの例を示す.
 \begin{lstlisting}[frame=lrbt,label=src:syslog_nfconntrack,caption=CodeSegmentの実行,numbers=left]
 public class TestCodeSegment extends CodeSegment {
-  // DataSegment
-  public Receiver ds = ids.create(CommandType.TAKE);
+  public Receiver arg1 = ids.create(CommandType.TAKE);
   
   public TestCodeSegment() {
   }
@@ -120,17 +119,26 @@
 
   public static void main(String[] args) {
     CodeSegment cs = new TestCodeSegment();
-    cs.ds.setKey("local", "count");
+    cs.arg1.setKey("local", "count"); // setKey API
     cs.ods.update("local", "count", 0);
   }
 }
 \end{lstlisting}
-このプログラムは, 数字を1から10まで出力を行い終了する.
+これは, 数字を1から10まで出力を行い終了するプログラムである.
 コードの説明を行う.
 まずTestCodeSegmentというCodeSegmentのインスタンスcsを生成する.
-csにはdsというReceiverクラスのフィールドを保持している.
-このdsがDataSegmentになる.
-次に\verb|ds.setKey|
+csはarg1というReceiverクラスのフィールドを保持しており, Receiverクラスは
+DataSegmentを受けとるためのクラスである.
+arg1に対しsetKey APIを使うことで, 使用したいDataSegmentのキー"count"を登録することができる.
+これによりキー"count"に対してデータが登録された場合, そのデータを受け取りcsの計算が自動で始まる.
+データの登録は\verb|ods.update|により行える.
+上記のコード20行目ではupdateにより"count"をキーとして数値の0を登録している.
+updateがされるとcsの計算が始まり別スレッドにより8行目からの処理が行われる.
+
+updateによりキー"count"に登録された数値0はReceiverであるdsを使って取ることができる.
+8行目から14行目では\verb|ds.asInteger()|により, "count"に登録したデータの中身を受け取りインクリメントし
+最後には\verb|ods.update|を行っている.
+新たなTestCodeSegmentも生成しており, これはインクリメントされた"count"がupdateされることで実行される.
 
 
 % Alice の他サーバノードへの"log"のputの問題
Binary file paper/master_paper.pdf has changed