-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAccounts1.lf
45 lines (39 loc) · 1.07 KB
/
Accounts1.lf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
target C {
coordination: decentralized,
keepalive: true
}
import IntWebSocketServer from "lib/IntWebSocketServer.lf"
reactor ACIDAccountManager(STA: time = 0) {
input in1: int
input in2: int
output out: int
state balance: int = 0
reaction(in1, in2) -> out {=
if (in1->is_present) {
lf_print("in1 transaction: %d", in1->value);
self->balance += in1->value;
}
if (in2->is_present) {
lf_print("in2 transaction: %d", in2->value);
self->balance += in2->value;
}
lf_set(out, self->balance);
lf_print("**** Balance: %d", self->balance);
=}
}
federated reactor {
w1 = new IntWebSocketServer(
hostport=8080,
initial_file = {= LF_SOURCE_DIRECTORY LF_FILE_SEPARATOR "Bank1.html" =})
w2 = new IntWebSocketServer(
hostport=8081,
initial_file = {= LF_SOURCE_DIRECTORY LF_FILE_SEPARATOR "Bank2.html" =})
a1 = new ACIDAccountManager()
a2 = new ACIDAccountManager()
w1.received ~> a1.in1
w2.received ~> a2.in2
w1.received ~> a2.in1
w2.received ~> a1.in2
a1.out ~> w1.response
a2.out ~> w2.response
}