-
Notifications
You must be signed in to change notification settings - Fork 0
/
Accounts8.lf
53 lines (44 loc) · 1.46 KB
/
Accounts8.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
46
47
48
49
50
51
52
53
target C {
coordination: decentralized,
keepalive: true
}
import IntWebSocketServer from "lib/IntWebSocketServer.lf"
import AccountManagerWithRecovery from "lib/AccountManagerWithRecovery.lf"
reactor Balance(STA: time = forever) {
input tr1: int
input tr2: int
output balance: int
state b: int = 0
reaction(tr1, tr2) -> balance {=
if (tr1->is_present) self->b += tr1->value;
if (tr2->is_present) self->b += tr2->value;
lf_set(balance, self->b);
lf_print("==== True balance at time " PRINTF_TIME " is %d", lf_time_logical_elapsed(), self->b);
=}
}
federated reactor(true_balance_period: time = 10 s) {
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 AccountManagerWithRecovery(STA = 30 ms, true_balance_period = true_balance_period)
a2 = new AccountManagerWithRecovery(STA = 30 ms, true_balance_period = true_balance_period)
b = new Balance()
b2 = new Balance()
w1.received -> a1.local
w2.received -> a1.remote
w1.received -> a2.remote
w2.received -> a2.local
a1.out -> w1.response
a2.out -> w2.response
a1.actual -> b.tr1
a2.actual -> b.tr2
a1.actual -> b2.tr1
a2.actual -> b2.tr2
b.balance -> a1.true_balance after true_balance_period
b2.balance -> a2.true_balance after true_balance_period
}