[
Back ]
-- inputoutput.rpd
-- michael chen
-- typedefs
type RType is integer; -- HTTP Server Request Type (varies latency)
type ProcessorRateType is integer;
OpenGraph : var RType := 0;
FetchPage : var RType := 0;
Highlight : var RType := 0;
PRate : var ProcessorRateType := 0;
sec : integer is 1;
min : integer is 60 * sec;
hr : integer is 60 * min;
-- services
type SQLService(type T) is interface
action in SQL_Response(Id : T);
out SQL_Command(Id : T);
end;
-- client modules
type WWWBrowser is interface
action in InResponse(), ExternalStart();
out Command(R : RType), Java_Execution();
behavior
begin
ExternalStart ||>
Command($FetchPage) after 1;
Command($OpenGraph) after 3;
Command($Highlight) after 23;;
InResponse ||> Java_Execution;;
end WWWBrowser;
type JavaBasedCollaboration is interface
action in InJava_Execution(), InJava_Protocol();
out Java_Object();
behavior
begin
InJava_Execution ||> Java_Object;;
end JavaBasedCollaboration;
-- client architecture
type Client is interface
action in InResponse(), InJava_Protocol(), ExternalStart();
out OutCommand(R : RType), OutJava_Object();
end Client;
architecture ClientArch() for Client is
W : WWWBrowser;
J : JavaBasedCollaboration;
connect
(?R in RType) W.Command(?R) ||> OutCommand(?R);
InResponse ||> W.InResponse;
J.Java_Object ||> OutJava_Object;
InJava_Protocol ||> J.InJava_Protocol;
W.Java_Execution ||> J.InJava_Execution;
ExternalStart ||> W.ExternalStart;
end ClientArch;
-- server modules
type HTTPServer is interface
action in InCommand(Id : Client; R : RType);
out Response(Id : Client);
requires
function Latency(R : RType; I : Integer) return integer;
behavior
begin
(?C in Client, ?R in RType, ?I in Integer)InCommand(?C, ?R) at ?I ||>
Response(?C) after Latency(?R, ?I);;
end HTTPServer;
type Res_Mang_Iface is interface
provides
function Latency(R : RType; I : Integer) return integer;
behavior
workload : var integer := 0;
ic : var integer := 0; -- internal clock
ad : var integer := 0; -- approximate delay
temp : var integer := 0;
function Latency(R : RType; I : Integer) return integer is
begin
if not($ic = I) then
workload := $workload - ($PRate * (I - $ic));
if ($workload < 0) then
workload := 0;
end if;
ic := I;
end if;
workload := $workload + R;
ad := $workload/ $PRate;
temp := $workload mod $PRate;
if ($temp = 0) then
return($ad);
end if;
return($ad + 1);
end;
end;
type SessionServer is interface
action in InJava_Object(Id : Client);
out Java_Protocol(Id : Client);
service CommandGiver : SQLService(Client);
behavior
begin
(?C in Client) InJava_Object(?C) ||> CommandGiver.SQL_Command(?C);;
(?C in Client) CommandGiver.SQL_Response(?C) ||> Java_Protocol(?C);;
end SessionServer;
type Postgres is interface
service CommandReceiver : dual SQLService(Client);
behavior
begin
(?C in Client) CommandReceiver.SQL_Command(?C) ||>
CommandReceiver.SQL_Response(?C);;
end Postgres;
-- server architecture
type Server is interface
action in InCommand(Id : Client; R : RType), InJava_Object(Id : Client);
out OutResponse(Id : Client), OutJava_Protocol(Id : Client);
end Server;
architecture ServerArch() for Server is
HTTP : HTTPServer;
SESS : SessionServer;
POST : Postgres;
RES : Res_Mang_Iface;
connect
(?C in Client, ?R in RType) InCommand(?C, ?R) ||> HTTP.InCommand(?C, ?R);
(?C in Client) HTTP.Response(?C) ||> OutResponse(?C);
(?C in Client) InJava_Object(?C) ||> SESS.InJava_Object(?C);
(?C in Client) SESS.Java_Protocol(?C) ||> OutJava_Protocol(?C);
SESS.CommandGiver to POST.CommandReceiver;
HTTP.Latency to RES.Latency;
end ServerArch;
-- driver interface
type Driver is interface
action out ExternalStart();
behavior
adv_file : file_type;
begin
start ||> IO.Open("ratefile", In_File, adv_file, '\n');
PRate := Value(Integer, IO.Get(adv_file));
FetchPage := Value(Integer, IO.Get(adv_file));
OpenGraph := Value(Integer, IO.Get(adv_file));
Highlight := Value(Integer, IO.Get(adv_file));
ExternalStart;;
end Driver;
-- advlrn super architecture
type Advlrn is interface
action in ExternalStart();
end;
architecture AdvlrnArch() for Advlrn
is
C1, C2 : Client is ClientArch();
S : Server is ServerArch();
connect
(?C in Client, ?R in RType) ?C.OutCommand(?R) ||> S.InCommand(?C, ?R);
(?C in Client) S.OutResponse(?C) ||> ?C.InResponse;
(?C in Client) ?C.OutJava_Object ||> S.InJava_Object(?C);
(?C in Client) S.OutJava_Protocol(?C) ||> ?C.InJava_Protocol;
ExternalStart ||> C1.ExternalStart || C2.ExternalStart;
end advlrn;
-- top level architecture
architecture top_level() return root is
D : Driver;
A : Advlrn is AdvlrnArch();
connect
D.ExternalStart ||> A.ExternalStart;
end;
[
Back ]