annotate 4.tex @ 14:35f802ff2842 default tip

fix
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Fri, 24 Apr 2009 17:41:24 +0900
parents 624a45b40bfe
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 \section{ プログラミング例}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 Federated Lindaは以下の様にして通信を行う。
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 \begin{itemize}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 \item public PSXLinda open(String \_host,int \_port)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 Linda Serverに対し、接続を行う。引数はホスト名とポート番号をとる。返り値はタプルスペースの番号となる。
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 \item public PSXReply in(int id)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 タプルスペース番号より引数で指定したidのタプルの受け取りを要求する。
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 受け取りは、返値のPSXReplyをチェックすることにより非同期に行なう。
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 in では待ち合わせは行なわれない。Call back 形式でタプルを受け取る
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 ことも出来る。
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
16
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 \item public PSXReply out(int id, ByteBuffer data)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
18
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 引数で指定したidでByteBuffer内のデータを送信する。
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
20
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 \item public int sync(long mtimeout)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
22
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 接続しているLinda Serverとタプルの送受信のポーリングを行う。
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
24
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 \end{itemize}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
26
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 Protocol Engineとはタプルスペースを介してデータをやり取りするEngineである。
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 二つのサーバー間でやり取りを行う場合、以下のようなプログラムとなる。
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 \begin{verbatim}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 FederatedLinda fdl;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 PSXLinda getpsx;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 PSXLinda sendpsx;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 PSXReply in;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 ByteBuffer data = ByteBuffer.allocate(10);
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
35
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 //通信を初期化する
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 fdl = FederatedLinda.init();
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 //データを取ってくるホストと受け渡すホストとの接続開始
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 getpsx = fdl.open("cs100",10000);
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
40 sendpsx = fdl.open("cs101",10001);
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 //取ってくるホストからinを指定してデータを取得
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
42 in = getpsx.in(10)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
43 data = in.getData();
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
44 //受け渡すホストに対しデータとidを指定して同期
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
45 sendpsx.out(10,data);
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
46 fdl.sync();
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 \end{verbatim}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
48
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
49 callback のAPIも用意されていて、{\tt fdl.sync() } した時に、
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
50 {\tt in, rd} の結果が戻っていれば、そのcallback が実行される
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
51 ようになっている。
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
52