Information Technology Reference
In-Depth Information
client expects its ports to be connected properly and communicates the data via
its ports.
For simplicity, a client only operates one search at a time. Nevertheless, the
user can issue multiple concurrent search requests. The requests are buffered and
served in an arbitrary order (due to the nondeterministic scheduling policy) one
at a time.
class
ClientImp ( store : StoreClientPerspective , req : outport , ans: inport)
1
inside
Peer
implements
Client
begin
2
with
User
op
search (
in
key : Data
out
result :Data) ==
4
var
found : Boolean ;
5
raise event
openCS
<
req , ans
>
(key ; found );
6
if
(found)
then
7
req . write (key ;);
8
ans.take(; result );
9
! store .add(key , result )
10
end
;
11
raise event
closeCS
<
req , ans
>
()
12
end
13
To obtain the result of the search, the client uses a synchronous call to the
ans
port. The update regarding the new data is sent to the data-store asynchronously
! store .add(key, result )
. Using asynchronous communication the client can already
continue execution while the data-store is busy processing the changes. The client
is a passive object, i.e., it does not specify a
run
method.
The server object is active in the sense that it starts its operation upon cre-
ation. The active behavior is specified in the
run
method. This involves read-
ing data requests from the
req
port and delivering the results on the
ans
port.
To repeat the process, the
run
method issues an asynchronous self call before
termination.
class
ServerImp ( store : StoreServerPerspective , req : inport , ans: outport)
1
inside
Peer
implements
Server
2
begin
3
op
run ==
4
var
key ,
result : Data ;
5
raise event
openSS
<
req , ans
>
();
6
req . take (; key );
7
store . find (key; result );
8
ans . write ( result ;) ;
9
raise event
closeSS
<
req , ans
>
();
10
!run()
11
end
12
By raising the event
openSS
<
req,ans
>
()
, a server announces its availability to the
broker. This synchronous event returns whenever a request is made for some
data on this server. Having provided the ports along the event, the server ob-
ject expects to be connected to the requesting client, and reads the key to the