#INCLUDE "o3_server_protocol.inc" #USE "utils" --{{{ client PROC client (VAL INT n, my.processor, SHARED COMMS c) --{{{ INT logical.time: SEQ logical.time := 0 WHILE TRUE SEQ --{{{ wait n seconds TIMER tim: INT t: SEQ tim ? t tim ? AFTER t PLUS (n*1000000) logical.time := logical.time PLUS n --}}} CLAIM c --{{{ transact business with server VAL []BYTE hello IS " Hello from client ": VAL []BYTE where IS " on processor ": VAL INT field IS (SIZE hello) + (5*n): BOOL any: SEQ c[request] ! integer; logical.time; 0 -- This is a 2-way c[reply] ? any -- client-server c[request] ! string; BYTE (SIZE hello)::hello; field -- transaction, c[reply] ? any -- just to demonstrate c[request] ! integer; n; 0 -- that we can do it. c[reply] ? any c[request] ! string; BYTE (SIZE where)::where; 0 -- The messages back c[reply] ? any -- from the server c[request] ! integer; my.processor; 0 -- are discarded. c[reply] ? any c[request] ! end.transaction --}}} --}}} : --}}} --{{{ service PROC service (COMMS c, CHAN OF BYTE out) --{{{ --{{{ COMMENT note --This performs a single client-server transaction. It is application --specific (see the file "server_protocol.inc" which defines the protocols). --It is a 2-way transaction just to demonstrate that we can do it. --}}} BOOL transacting: SEQ transacting := TRUE WHILE transacting c[request] ? CASE BYTE size: [255]BYTE s: INT field: string; size::s; field SEQ out.string ([s FOR INT size], field, out) c[reply] ! TRUE INT i: INT field: integer; i; field SEQ out.number (i, field, out) c[reply] ! TRUE end.transaction SEQ out.string ("*n", 0, out) transacting := FALSE --}}} : --}}} --{{{ server PROC server (SHARED COMMS c, CHAN OF BYTE out) --{{{ WHILE TRUE GRANT c service (c, out) --}}} : --}}} --{{{ distributed.system PROC distributed.system (CHAN OF BYTE keyboard, screen, error) --{{{ --{{{ table defining the configuration of the distributed system VAL INT max.clients.per.processor IS 10: VAL []INT n.clients IS [4, 2, 8, 5, 3, 4]: -- number of clients per processor --}}} --{{{ client.processor PROC client.processor (VAL INT my.processor, n.clients, SHARED COMMS c) --{{{ PAR n = 0 FOR max.clients.per.processor IF n < n.clients client (n + 1, my.processor, c) TRUE SKIP --}}} : --}}} --{{{ server.processor PROC server.processor (SHARED COMMS c, CHAN OF BYTE out) --{{{ server (c, out) --}}} : --}}} --{{{ distributed processor network VAL INT n.client.processors IS SIZE n.clients: SHARED COMMS link: PAR PAR n = 0 FOR n.client.processors client.processor (n, n.clients[n], link) server.processor (link, screen) --}}} --}}} : --}}}