annotate paper/implementation.tex @ 0:420c2d37b2bf

Initial revision
author fuchita
date Tue, 12 Feb 2008 17:18:57 +0900
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
1 \chapter{実装}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
2
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
3 ここではFederated Linda の実装について説明する。実装したのは type2 であ
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
4 る。
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
5
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
6 \section{type2の実装}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
7
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
8 Federated Linda は本研究室で開発された非同期型Linda\cite{linda}をベー
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
9 スに開発した。type 2 では Linda Server と Protocol Engine は別プロセスと
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
10 して実装する。Protocol Engine では Linda Server との通信を クライアントに
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
11 提供されている Linda API を用いて行う。
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
12
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
13 タプルのIDは、{\tt 16bit}の整数値を用いている。タプルのデータは任意の文字列であ
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
14 る。Linda Server は C で記述されており、クライアントは C, Perl, Python,
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
15 Ruby にて記述可能。以下、Linda Server と クライアントへ提供している
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
16 Linda API の説明をし、分散プログラムの主要素である Local Access,
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
17 Protocol Engine, Link Configuration の実装について説明する。
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
18
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
19 \subsection{Linda Server}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
20
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
21 Linda Server は C で記述している。タプルスペースはメモリ上のキューとして
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
22 実装されている。タプルスペースには1から65535までのIDが割り当てられており、
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
23 タプルは指定されたIDへのキューへ格納される。
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
24
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
25 %% タプルの図は入れる?
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
26
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
27 %% in/rd の非同期の説明
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
28 非同期型 Linda Server の特徴として、タプルを要求するコマンド (in, read,
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
29 wait\_read) などを実行する際のコマンド実行の保留が挙げられる。クライアン
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
30 トからタプルを要求するコマンドを受け取ると、Linda Server は指定されたID
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
31 にタプルがあるかどうかを調べる。ある場合にはそのコマンドを即実行するが、
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
32 無い 場合には、コマンド実行の保留を行う。その後、そのIDへタプルが書き込
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
33 まれた( out された) 時に 保留されたコマンドを実行する。(図\ref{async-in}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
34 参照)。このコマンド実行の保留により、コマンド実行の待ちやクライアントが
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
35 Linda Server へタプルの有無を問い合わせたりすることなく、非同期通信を行
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
36 うことができる。
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
37
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
38 \begin{figure}[htp]
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
39 \begin{center}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
40 \includegraphics[width=13cm]{fig/async-in.eps}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
41 \caption{タプルがない場合の in コマンドの実行}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
42 \label{async-in}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
43 \end{center}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
44 \end{figure}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
45
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
46 プログラムは {\tt ldserv} という名前で提供されている。
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
47 起動方法は以下の通りである。``-p''オプションでポート番号を指定している。
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
48
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
49 %% ldserv の起動方法など
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
50 \begin{verbatim}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
51 $ ldserv -p 10000
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
52 \end{verbatim}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
53
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
54 %% もうちょい説明が欲しぃ
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
55
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
56 \subsection{Federated Linda API} %% Local Access に入れてもいい??
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
57
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
58 Federated Linda の通信は非同期に行われる。in, read, out などのコマンドの関数
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
59 を呼び出した時点では通信は行われず、それらのコマンドを一時的にキュー
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
60 ({\tt COMMAND}キュー)へ蓄える。蓄えたコマンドは、タプルやコマンドの送受信を行
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
61 う関数({\tt sync()})が呼ばれた時点で一斉に各 Linda Server へ送信される。このと
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
62 き、Linda Server から送信されたタプルの受信も行う。受信されたタプルは
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
63 {\tt REPLY}キューへ蓄えられ、データを取りだす関数({\tt reply()})で取り出される。
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
64 {\tt COMMAND} キューと {\tt REPLY} キューは API により隠蔽されており、直接は見えない。
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
65
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
66 Federated Linda ではクライアントプログラムへの API として C, Perl,
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
67 Python, Ruby で実装したインターフェースを提供している。クライアントプロ
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
68 グラムはこれらの中から好きな言語を選んで記述することになる。提供している
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
69 API は、C言語とその他のスクリプト言語との間で若干の違いがある。スクリプ
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
70 ト言語ではオブジェクト指向を意識して実装したため、このような違いが出てい
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
71 る。
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
72
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
73 C言語とスクリプト言語に分けて API の説明を行う。
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
74
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
75 \subsubsection{C言語のAPI}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
76
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
77 C言語で提供している主な関数群は以下の通りである。
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
78
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
79 %% CのAPIの説明
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
80 \begin{itemize}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
81 \item {\tt open\_linda(hostname,port)}\\
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
82 Linda Server へ接続する。引数としてホスト名({\tt hostname})とポート番号
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
83 ({\tt port})をとる。返り値はタプルスペースの番号
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
84 \item {\tt psx\_in(ts\_id,tuple\_id)}\\
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
85 指定したIDのタプルの受け取り要求をするコマンド {\tt in} を {\tt COMMAND}キュー
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
86 へ入れる。引数としてコマンドを送るタプルスペースの番号({\tt ts\_id})と受け
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
87 取るタプルのID({\tt tuple\_id})をとる。返り値として{\tt psx\_reply()}でタプル
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
88 を取り出すときに用いるユニークな番号が返る。受け取ったタプルは、タ
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
89 プルスペース上からは削除される。
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
90 \item {\tt psx\_rd(ts\_id,tuple\_id)}\\
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
91 指定したIDのタプルの受け取り要求をするコマンド {\tt read} を{\tt COMMAND}キュー
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
92 へ入れる。引数としてコマンドを送るタプルスペースの番号({\tt ts\_id})と受け
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
93 取るタプルのID({\tt tuple\_id})をとる。返り値として{\tt psx\_reply()}でタプル
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
94 を取り出すときに用いるユニークな番号が返る。受け取ったタプルは、タ
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
95 プルスペース上に残る。
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
96 \item {\tt psx\_wait\_rd(ts\_id,tuple\_id)}\\
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
97 {\tt psx\_rd()}と似ているが、タプルスペース上での挙動に違いがある。タプル
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
98 スペースにタプルがあった場合、現在あるタプルではなく、新規に{\tt out}され
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
99 たタプルに対して{\tt read}を行う。それ以外は同じ挙動である。
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
100 \item {\tt psx\_out(ts\_id, tuple\_id, data)}\\
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
101 指定したIDのタプルの書き込み要求をするコマンド {\tt out} を{\tt COMMAND}キュー
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
102 へ入れる。引数としてコマンドを送るタプルスペースの番号({\tt ts\_id})と書き
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
103 込むタプルのID({\tt tuple\_id})をとる。
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
104 \item {\tt psx\_ck(ts\_id,tuple\_id)}\\
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
105 指定したIDのタプルの有無の確認をするコマンド {\tt check} を{\tt COMMAND}キュー
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
106 へ入れる。引数としてコマンドを送るタプルスペースの番号({\tt ts\_id})と受け
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
107 取るタプルのID({\tt tuple\_id})をとる。返り値として{\tt psx\_reply()}でタプル
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
108 を取り出すときに用いるユニークな番号が返る。タプルのデータ部分には
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
109 タプルスペース上にあるタプルのサイズが入る。指定したIDのタプルが無
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
110 ければ {\tt 0} となる。
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
111 \item {\tt psx\_sync\_n()}\\
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
112 接続している全Linda Server とタプルの送受信を行う。{\tt COMMAND}キューに
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
113 溜まったコマンドを送信し、Linda Server からのタプルを {\tt REPLY} キュー
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
114 へ入れる
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
115 \item {\tt psx\_reply(uid)}\\
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
116 {\tt REPLY}キューにあるタプルを取りだす。取り出す際に、{\tt in},
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
117 {\tt read}コマンドが返した番号を引数としてとる。返り値はタプル。取り出したタプルからデー
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
118 タやタプル情報(IDやデータサイズ)を取り出す関数群も用意している。
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
119 \end{itemize}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
120
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
121 まず {\tt open\_linda} を用いて Linda Server へ接続する。この時返る値が Linda
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
122 Server の ID になる(Tuple Space ID)。この値とタプルのIDを用いて{\tt psx\_in,
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
123 psx\_rd, psx\_out}などのコマンドを発行する。{\tt psx\_in} や {\tt psx\_rd, psx\_ck}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
124 はユニークな番号を返す。この番号は {\tt psx\_reply} の引数として使用し、どの
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
125 {\tt psx\_in, psx\_rd}の返答を取り出すかを指定するためのものである。通信は
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
126 {\tt psx\_sync\_n}でのみ発生する。
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
127 %まず open\_linda を用いて Linda Server へ接続する。この時返る値が Linda
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
128 % ^^^^^ こういうのは {\tt } とか \verb+...+ みたいなのを使って
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
129 % type writer font にする
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
130
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
131 これらのAPIを用いた通信はポーリング型の形を取る。具体的なポーリングベー
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
132 スのプログラミング例は Local Access の説明で述べる。
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
133
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
134 \subsubsection{Perl, Python, Ruby の API}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
135
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
136 %% Perl, Python, Ruby で提供したクラスなどの説明
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
137
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
138 Perl, Python, Ruby は C の API を拡張して実装している。提供しているモジュー
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
139 ルは{\tt FederatedLinda, Linda, Reply}というクラスで構成されている(図
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
140 \ref{LWLClass}参照)。各スクリプト言語で同じ名前を用いて実装している。
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
141
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
142
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
143 %% FederatedLinda クラスや Reply クラスを、図を入れて説明
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
144
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
145 \begin{figure}[htbp]
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
146 \begin{center}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
147 \includegraphics[width=15cm]{fig/flinda-class-dig.eps}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
148 \caption{Perl, Python, Ruby で拡張したLinda API のクラス図}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
149 \label{LWLClass}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
150 \end{center}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
151 \end{figure}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
152
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
153 %% 各クラスの説明。
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
154 %% FederatedLinda.open() で Linda インスタンス生成、
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
155 %% Linda.in(), Linda.rd() で Reply インスタンスが返るとか
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
156 %% FederatedLinda.sync() で通信
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
157
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
158 \begin{itemize}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
159 \item {\tt FederatedLinda} - {\tt open} や {\tt sync} など、通信やその接
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
160 続切断を行うクラス。1プロセスに1インスタンスのみ生成される。
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
161 \begin{description}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
162 \item[~{\tt open(hostname, port)}]{\tt Linda} インスタンスを返す。引数としてホスト名
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
163 ポート番号を取る。
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
164 \item[~{\tt sync()}] 接続している全Linda Serverと通信を行う。
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
165 \end{description}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
166 \item {\tt Linda} -
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
167 インスタンスを生成する際に Linda Server と接続する。メンバとしてタ
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
168 プルスペースのIDを保持する({\tt tsid})
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
169 \begin{description}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
170 \item[~{\tt In(tid)}]{\tt in} コマンドを発行する。引数としてタプルID({\tt
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
171 tid})を取る。返
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
172 り値は、その応答となる{\tt Reply}のインスタンス。
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
173 \item[~{\tt Rd(tid)}]{\tt read }コマンドを発行する。引数としてタプル
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
174 ID({\tt tid})を取る。返り値は、その応答となる{\tt Reply}のインスタンス。
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
175 \item[~{\tt WaitRd(tid)}]{\tt wait\_rd} コマンドを発行する。引数としてタプ
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
176 ルID({\tt tid})を取る。返り値は、その応答となる{\tt Reply}のインスタンス。
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
177 \item[~{\tt Out(tid, data)}]{\tt out}コマンドを発行する。引数としてタプル
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
178 {\tt ID(tid)}と送信するデータを取る。
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
179 \item[~{\tt Ck(tid)}]{\tt check} コマンドを発行する。引数としてタプル
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
180 ID({\tt tid})を取る。返り値は、その応答となる{\tt Reply}のインスタンス。
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
181 \item[~{\tt getid()}]タプルID 65535 の値を取得する。この値はLinda Server内部で
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
182 クライアント数をカウントした値である。
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
183 \item[~{\tt close()}]Linda Server との接続を閉じる。
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
184 \end{description}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
185 \item {\tt Reply} -
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
186 Linda Server から受け取ったタプルを取得するためのクラス。
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
187 \begin{description}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
188 \item[~{\tt reply()}]受け取ったタプルを取得する。タプルをまだ受け取っていなかっ
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
189 たら{\tt null(None)}を返す。
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
190 \end{description}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
191 \end{itemize}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
192
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
193 Linda Server への接続は {\tt FederatedLinda} インスタンスの {\tt open} メソッドを使
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
194 う。引数として接続したいLinda Serverのホスト名とポート番号を取る。{\tt open}は
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
195 {\tt Linda}インスタンスが返す。また、Linda Serverとの通信は{\tt sync}メソッドで行う。
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
196 {\tt in, read, out}などのコマンドは、{\tt Linda}インスタンスのメンバ関数から行う。
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
197 {\tt in, read}などのタプルを受け取るコマンドは、{\tt Reply}インスタンスを返す。Linda
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
198 Serverからのタプルを取り出したいときは、{\tt Reply}の{\tt reply}メソッドを用いる。
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
199
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
200 %% 次の「Federated Linda を用いたプログラミング」に入れてもいいかも?
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
201 \section{Local Access to Protocol}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
202
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
203 %% Client プログラムでの Linda API の使いかた
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
204 %% Protocol Engine の使い分け方(タプルIDの切り替え)
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
205 %% 非同期な Linda API の有効的な使いかた。??
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
206 %% ポーリング型のプログラミングを強調
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
207
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
208 ``Local Access''はプロトコルへアクセスするAPIである。APIの内容は先に説明
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
209 したので、ここではクライアントプログラムにおける Linda API を用いたプロ
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
210 グラミングについて説明する。まず最初に、Linda API を使ったクライアントの
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
211 ポーリング型のプログラミングについて説明する。次に、タプルスペースを
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
212 介した Protocol Engine へのアクセスについて、その利便性について説明する。
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
213
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
214 \subsection{ポーリング型のプログラミングスタイル}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
215
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
216 Federated Linda の通信は非同期に行われる。これはポーリング型のプログ
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
217 ラミングスタイルで記述されることが期待されているということでもある。
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
218 Linda API を用いるプログラムではメインループが一度回ると、{\tt sync()}が一回呼
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
219 ばれるようなプログラミングスタイルになる。これは、通信が起こる回数を減ら
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
220 すことと、通信箇所を明確にすることを目的としている。
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
221
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
222 以下にPerlで記述したプログラミング例を挙げる。
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
223
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
224 \begin{center}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
225 \begin{itembox}[l]{ポーリング型のプログラミング例}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
226 \begin{verbatim}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
227 # Linda Server と接続する
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
228 $linda = FederatedLinda->open($hostname, $portnumber);
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
229 # タプルスペースの TUPLE_ID へタプルの取得を要求する
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
230 $rep = $linda->in($TUPLE_ID);
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
231 # メインループ
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
232 while (1) {
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
233 #
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
234 # 通信以外の処理
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
235 #
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
236 if (($data = $rep->reply()) > 0) { # 応答が来ていたら
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
237 # 繰り返しIDに対してタプルの取得要求を出す
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
238 $rep = $linda->in($TUPLE_ID);
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
239
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
240 #
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
241 # 受け取ったデータの処理を記述
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
242 #
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
243 print $data;
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
244 }
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
245 # コマンドやタプルの一斉送受信
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
246 FederatedLinda->sync();
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
247 }
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
248 \end{verbatim}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
249 \end{itembox}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
250 \end{center}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
251
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
252 この例は {\tt \$TUPLE\_ID} で指定されたタプルスペースのタプルを取得し、標準出
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
253 力へ書き出すプログラムである。基本的な流れは以下のようになっている。まず
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
254 Linda Server へ接続する。次に、使用するタプルスペースへ {\tt in} する。
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
255 この {\tt in }
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
256 はその後の {\tt sync()} が実行されるまで Linda Server へは送信されない。メイン
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
257 ループ内は3つのパートに分かれる。まずは``通信以外の処理''では、クライア
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
258 ントの処理を行う。ここでデータのin, read, out 等を実行してもよい。次に
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
259 {\tt reply()} で in/read した時の応答が受け取ったかを確認。受け取っていたなら
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
260 ({\tt if} 内が実行され)受け取ったデータの処理を行う。そして最後に{\tt sync()}を呼
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
261 んで通信を行う。
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
262
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
263 この例は基本的なプログラミングである。しかし、メインループ内で {\tt sync()} は
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
264 一度だけ呼ぶ事、{\tt reply()} でデータの受信を確認する事など、ポーリングを意識
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
265 したプログラミングの特徴を表している。
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
266
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
267 また、{\tt reply()} のデータ取り出し時や {\tt sync()} の通信時で``待ち''に入る事はな
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
268 い。よって、通信以外の処理が待たされることはないが、逆に通信以外の処理で
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
269 ``待ち''が入ると、通信が滞る。通信以外の処理においても``待ち''が入らない
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
270 ようなスタイルを取る必要がある。
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
271
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
272 \subsection{Protocol Engine へのアクセス}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
273
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
274 クライアントプログラムは使用する Protocol Engine とはタプルスペースを介
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
275 してデータをやり取りする。データのやり取りは Linda をベースにした in,
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
276 read, out という分かりやすいモデルになっている。
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
277
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
278 Protocol Engine への依存は低い。実際、タプルIDを各プロトコル毎に割り当て
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
279 ることにより、使用するプロトコルを切替えるということもできる。この場合、
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
280 in, read, out などのコマンドで指定する タプルID を変更するだけでいい。
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
281
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
282 以下に例を挙げる(図\ref{select_protocol}参照)。
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
283
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
284 \begin{figure}[htp]
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
285 \begin{center}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
286 \includegraphics[width=8cm]{fig/select_protocol.eps}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
287 \caption{使用するプロトコルの切替え}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
288 \label{select_protocol}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
289 \end{center}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
290 \end{figure}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
291
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
292 この図の場合、タプルIDの 10000 番を Distance Vector 型 Routing Protocol
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
293 に、タプルID 10001 番を Broad Cast Protocol に割り当てている。クライアン
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
294 トプログラム(Client Application)は、in, read, out するときの引数として渡す
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
295 タプルIDを 10000 すると Distance Vector 型 Routing Protocol を用いたデー
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
296 タ転送を行い、 10001 すると全タプルスペースへ Broad Cast することになる。
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
297
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
298 プロトコルへのアクセスは in, read, out などの単純なコマンドで行われるの
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
299 で分かりやすい。また、プロトコル切替えが容易であるので、多数のプロトコル
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
300 を用いたプログラムを記述しやすい。
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
301
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
302 \section{Protocol Engine}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
303
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
304 %% プロトコルエンジンの書きかた
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
305 %% Replyを受け取ってから、再び同じタプルIDにin/rdするとか
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
306 %% プログラミングのパターンなどをソース(擬似?)を入れて説明
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
307 %% 複数のタプルスペースへのアクセスをどう制御するか?とか
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
308
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
309 type 2 では Protocol Engine は Linda API を用いて実装する。よって実装の
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
310 スタイル自体は Local Access to Protocol にて説明した通りである。そしてそ
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
311 の API を用いて分散アルゴリズムを実装する。分散アルゴリズムは多種多様あ
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
312 り、またその実装方法も多い。しかし、タプルのやり取りの部分はやタプルIDの
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
313 使いかたなどは共通しているので、その部分を説明する。
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
314
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
315 以下にマルチキャストを行うプロトコルのメインループの例を挙げる。
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
316
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
317 この例では、{\tt \$TUPLE\_ID\_CONNECT, \$TUPLE\_ID\_SEND,
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
318 \$TUPLE\_ID\_RECV} の3つのタプルIDを使用している。また、接続先の Linda
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
319 Server を配列を用いて管理している。
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
320
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
321 {\tt \$TUPLE\_ID\_CONNECT}に投入されたタプルは新しく接続する Linda Server の
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
322 ホスト名とポート番号が入っており、{\tt getTuplespace()} 内 で
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
323 {\tt FederatedLinda->open()} している。
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
324
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
325 {\tt \$TUPLE\_ID\_SEND}に投入されたタプルは、マルチキャストしたいデータを含
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
326 んでいる。よって、自分が接続している全Linda Server の{\tt \$TUPLE\_ID\_RECV}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
327 へタプルを投入する。クライアントは、データを送りたいときは
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
328 {\tt \$TUPLE\_ID\_SEND}へタプルを{\tt out}し、受け取りたいときは、
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
329 {\tt \$TUPLE\_ID\_RECV}へ{\tt in}する。
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
330
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
331 \begin{center}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
332 \begin{itembox}[l]{マルチキャストのプロトコルの例}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
333 \begin{verbatim}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
334 @tuplespaces # マルチキャストする相手の Linda インスタンス
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
335 $linda # 自分が担当する Linda
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
336 # メインループ
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
337 while (1) {
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
338 # 接続に変更があった場合の処理
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
339 if (($data = $ConnectRep->reply()) > 0) {
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
340 $ConnectRep = $linda->in($TUPLE_ID_CONNECT);
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
341 # $dataから接続相手を得て、@tuplespaces へ加える
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
342 @tuplespaces = (@tuplespaces, getTuplespace($data));
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
343 }
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
344 # マルチキャスト
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
345 if (($data = $MultiCastRep->reply()) > 0) {
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
346 # 繰り返しIDに対してタプルの取得要求を出す
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
347 $MultiCastRep = $linda->in($TUPLE_ID_MULTICAST);
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
348 # 全タプルスペースへデータを送信
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
349 foreach $t (@tuplespaces) {
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
350 $t->out($TUPLE_ID_RECV, $data);
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
351 }
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
352 }
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
353 FederatedLinda->sync();
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
354 }
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
355 \end{verbatim}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
356 \end{itembox}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
357 \end{center}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
358
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
359 この例では 自分が担当する Linda Server の二つのタプルID(
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
360 {\tt \$TUPLE\_ID\_CONNECT, \$TUPLE\_ID\_SEND})に {\tt in} をしており、それぞれの
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
361 タプルIDで取り扱われるデータを分けている。また、クライアントのデータ送信・
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
362 受信をそれぞれ {\tt \$TUPLE\_ID\_SEND, \$TUPLE\_ID\_RECV} へ割り当てている。
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
363 このようにタプルID毎に取り扱うデータを決めておき、そのIDからのデータを受
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
364 け取ったら、対応する処理を行うということができる。当然タプルのデータ部に
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
365 プロトコル独自のヘッダなどを入れて、それで行う処理を選択することもできる。
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
366 しかしその場合はデータ自身がその Protocol Engine に依存するので、他の
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
367 Protocol Engine では使えなくなる。
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
368
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
369 よって、様々な Protocol Engine で使われるデータなどは、その処理の選択は
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
370 タプルID毎に行うといいだろう。そうでない場合は同一タプルIDを使うとう手段
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
371 もある。
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
372
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
373 \section{Link Configuration}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
374
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
375 %% タプルスペースとの接続について
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
376 %% コネクションをどう管理するか。
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
377 %% トポロジ生成について。XMLによる生成。Graffle
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
378
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
379 Linda Server 間は Protocol Engine で接続される。その接続の形を規定するの
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
380 が Link Configuration である。Link Configuration ではタプルスペース間を
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
381 どのように接続するかを XML で記述しており、それを基にネットワークを構築
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
382 する。
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
383
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
384 図\ref{linkconfig_xml}では Configurator というプロセスが 接続状態を表し
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
385 た XML を Linda Server へ投入し、そのXMLを元にトポロジを構築している。
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
386 このXMLを投入するプロセスはクライアントプログラムでも Protocol Engine で
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
387 もよい。
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
388
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
389 \begin{figure}[htp]
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
390 \begin{center}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
391 \includegraphics[width=13cm]{fig/lc.eps}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
392 \caption{Configuratorによるトポロジ形成}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
393 \label{linkconfig_xml}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
394 \end{center}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
395 \end{figure}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
396
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
397 Link Configuration では、取り扱う XML のパーサとトポロジの接続の状態を
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
398 表したデータ構造、接続を行う関数などをプロトコルとして Protocol Engine
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
399 へ組み込めるように、モジュールとして提供している。以下ではその説明を行う。
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
400
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
401
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
402 \subsection{トポロジを表すXML}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
403
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
404 まず、トポロジを規定するXMLについて説明する。このXMLの形式は独自に定めた
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
405 ものである。
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
406
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
407 以下に挙げる例は、ノード数 4 で、Ring トポロジを表した XML である。この
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
408 例を用いて XML の形式を説明する。
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
409
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
410 \begin{center}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
411 \begin{itembox}[l]{Ring トポロジを表す XML例}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
412 \begin{verbatim}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
413 <graph name = "Ring">
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
414 <node label = "lindaA" tsid = "localhost:10000">
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
415 <destination label = "lindaC"/>
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
416 <destination label = "lindaB"/>
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
417 </node>
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
418 <node label = "lindaB" tsid = "localhost:10002">
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
419 <destination label = "lindaD"/>
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
420 <destination label = "lindaA"/>
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
421 </node>
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
422 <node label = "lindaC" tsid = "localhost:10003">
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
423 <destination label = "lindaD"/>
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
424 <destination label = "lindaA"/>
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
425 </node>
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
426 <node label = "lindaD" tsid = "localhost:10004">
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
427 <destination label = "lindaB"/>
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
428 <destination label = "lindaC"/>
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
429 </node>
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
430 </graph>
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
431 \end{verbatim}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
432 \end{itembox}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
433 \end{center}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
434
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
435 各タグの説明をする。
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
436
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
437 \begin{itemize}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
438 \item {\tt graph} - トポロジを表すルートタグ
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
439 \begin{description}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
440 \item [~{\tt name}] - トポロジの名前などを表す。任意
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
441 \end{description}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
442 \item {\tt node} - Linda Server を表すタグ。子要素として、接続先を表した
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
443 {\tt desitination} タグを持つ。
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
444 \begin{description}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
445 \item [~{\tt label}] - ノードに付けられたラベル。この属性を元に接続状況を調べる。
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
446 \item [~{\tt tsid}] - Linda Server のタプルスペースID。どのタプルスペースがこのノー
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
447 ドを担当するかを表す。
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
448 \end{description}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
449 \item {\tt destination} - 接続先を表すタグ。
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
450 \begin{description}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
451 \item [~{\tt label}] - 接続先のラベル。XML内のどの {\tt node} タグに対応するかを表す。
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
452 \end{description}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
453 \end{itemize}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
454
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
455 このXMLは非常に単純な構造をしている。まずルートタグの下には各 Linda
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
456 Server を表す {\tt node} タグがある。この {\tt node} タグには各々個別の名
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
457 前({\tt lable}属性)が付けられている。また、そのノードを担当する Linda
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
458 Server のタプルスペースID({\tt tsid}属性)が付いている。接続状況などは
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
459 {\tt lable} を用いて表される。{\tt node} タグは子として {\tt
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
460 destination} タグを持つ。{\tt destination} タグは、{\tt node} がどのノー
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
461 ドと接続するかを表している。あて先は {\tt lable}属性を用いて表される。
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
462 {\tt node} タグで定義されていない {\tt lable} や、親の {\tt lable} を指定
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
463 することはできない。{\tt destination} はあて先を表しており、単方向グラフ
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
464 になっている。
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
465
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
466 このXMLは Protocol Engine が解析することになる。Protocol Engine に組み込
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
467 むパーサと自身が接続する相手先を取得するモジュールを提供している。次では
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
468 その説明を行う。
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
469
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
470 \subsection{接続を行うモジュール}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
471
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
472 Link Configuration では Link Configuration の XML を変換するパーサと、変
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
473 換されたデータ構造を表すクラスを提供している。図\ref{LinkConfig-class}に
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
474 そのクラス図を示す。
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
475
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
476 \begin{figure}[htb]
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
477 \begin{center}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
478 \includegraphics[width=13cm]{fig/LinkConfig-class-dig.eps}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
479 \end{center}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
480 \caption{LinkConfiguration のクラス図}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
481 \label{LinkConfig-class}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
482 \end{figure}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
483
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
484 提供するクラスは、{\tt LinkConfigParser, LinkConfiguration, NodeInfo} の3つで
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
485 ある。これらのメンバとメソッドの説明を以下に示す。
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
486
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
487 \begin{itemize}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
488 \item {\tt LinkConfigParser} - XMLを解析し、その結果である {\tt
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
489 LinkConfiguration} インスタンスを返す
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
490 \begin{description}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
491 \item [~{\tt parseLinkConfig(tsid, xmltext)}] - XMLを解析する。引数として自分のタ
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
492 プルスペース ID({\tt tsid})、解析するXML({\tt xmltext})を取る。解析結果
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
493 の {\tt LinkConfiguration} インスタンスを返す。
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
494 \end{description}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
495 \item {\tt LinkConfiguration} - 各ノードの接続を表すクラス。
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
496 \begin{description}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
497 \item [~{\tt tsid}] - タプルスペースID
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
498 \item [~{\tt lable}] - 自分が担当するタプルスペースのラベル
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
499 \item [~{\tt linklist}] - XMLで示された全ノードの接続をハッシュとして保持。キーと
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
500 してラベルを使用。値は {\tt NodeInfo} インスタンス。
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
501 \item [~{\tt getDstlist(label)}] - 引数で渡したラベルのノードが接続する相
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
502 手のラベルの配列を取得
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
503 \end{description}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
504 \item {\tt NodeInfo} - ノードを表すクラス
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
505 \begin{description}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
506 \item [~{\tt tsid}] - ノードを担当するタプルスペースのID
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
507 \item [~{\tt lable}] - ノードのラベル
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
508 \item [~{\tt dstlist}] - ノードが接続するノードのラベルのリスト
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
509 \end{description}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
510 \end{itemize}
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
511
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
512 これらのクラスを使い、XMLより自分が接続する相手先のタプルスペースIDの一
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
513 覧を取得し、{\tt FederatedLinda.open} を行うことになる。{\tt Linda} クラスの管理は各
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
514 プログラムに任せる。また、{\tt LinkConfiguration} インスタンスを複数持つことに
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
515 より、一つの Protocol Engine で別々のトポロジに参加することも可能である。
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
516
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
517 %% 足りない部分(動的に接続を管理)にも触れる >> できれば作りたい
420c2d37b2bf Initial revision
fuchita
parents:
diff changeset
518