A LocalResource acts as a virtually seamless interface for a Till to a Channel.
Thus it provides the same calling interface as a CentralResource, except that
its operations are able toreturn the value <Fail> to represent a communication
failure.
\begin{vdm_al} class LocalResource
\end{vdm_al}
A LocalResource has only one instance variable: a reference to a Channel.
\begin{vdm_al} instancevariables
c : Channel := new Channel();
operations
\end{vdm_al}
The Create operation is used to initialize the Channel.
\begin{vdm_al} public LocalResource : Channel ==> LocalResource
LocalResource(nc) ==
c := nc;
\end{vdm_al}
The operation GetBalance shadows the corresponding operation in CentralResource.
The argument received by the method is converted into a value of type Channel`ReqData, andthen a request is constructed. This is sent to the channel andthen the Wait
operation is called.
\begin{vdm_al} public GetBalance : Account`AccountId ==> [nat]| <Fail>
GetBalance(accountId) == letreq = mk_Channel`Request(<GetBalance>,
{mk_Channel`AccountId(accountId)}) in
(c.SendRequest(req);
Wait(<GetBalance>));
\end{vdm_al}
The Wait operation waits for a particular response from the channel. If the
response isnilor does not match the expected result, a failure is signalled
(corresponding to a timeout in the Channel). Otherwise the data value in the
response is returned.
\begin{vdm_al}
Wait : Channel`Command ==> Channel`RespData | <Fail>
Wait(comm) ==
(c.Wait(); let resp = c.ReceiveResponse() in if resp = nil thenreturn <Fail> elseif resp.command <> comm thenreturn <Fail> elsereturn resp.data);
\end{vdm_al}
The remaining operations follow the same basic approach as that of GetBalance, and need no further explanation.
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.