forked from elkoDev/Cirrina-UseCases
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.pkl
More file actions
124 lines (121 loc) · 3.6 KB
/
Copy pathmain.pkl
File metadata and controls
124 lines (121 loc) · 3.6 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
amends
"https://raw.githubusercontent.com/CollaborativeStateMachines/Cirrina/refs/heads/develop/src/main/resources/pkl/csm/csml.pkl"
local n = 6
collaborativeStateMachine {
stateMachines {
["arbitrator"] {
transient {
["forks"] = "std:repeat(false, \(n))"
["waiting"] = "std:repeat(false, \(n))"
}
states {
["serving"] = new Initial {
static { ["count"] = "0" }
on {
["hungry"] {
yields {
new Match {
cases {
new Case {
of = "!(forks[$id] || forks[($id + 1) % 6])"
yields {
new Eval { expression = "forks[$id] = forks[($id + 1) % 6] = true" }
new Emit { event { topic = "acquire" }; target = "$id.toString()" }
}
}
}
default = new Eval { expression = "waiting[$id] = true" }
}
}
}
["release"] {
yields {
new Eval { expression = "forks[$id] = forks[($id + 1) % 6] = false" }
new Emit {
event = new Internal { topic = "test"; data { ["nid"] = "($id + 5) % 6" } }
}
new Emit {
event = new Internal { topic = "test"; data { ["nid"] = "($id + 1) % 6" } }
}
}
}
["test"] {
yields {
new Match {
cases {
new Case {
of = "waiting[$nid] && !(forks[$nid] || forks[($nid + 1) % 6])"
yields {
new Eval {
expression =
"waiting[$nid] = false; forks[$nid] = forks[($nid + 1) % 6] = true"
}
new Emit { event { topic = "acquire" }; target = "$nid.toString()" }
}
}
}
}
}
}
}
}
}
}
["philosopher"] {
states {
["hungry"] = new Initial {
entry {
new Emit { event { topic = "hungry"; data { ["id"] = "id" } }; target = "'arbitrator'" }
}
on {
["acquire"] { to = "eating" }
}
}
["eating"] {
static { ["meals"] = "0" }
after {
["eating"] = new Timeout {
delay = "std:randomAround(10,2)"
triggers = new Emit { event = new Internal { topic = "ate" } }
}
}
on {
["ate"] {
to = "thinking"
yields {
new Eval { expression = "++meals" }
new Ctr { counter = "philosopher.meals" }
new Emit {
event { topic = "release"; data { ["id"] = "id" } }
target = "'arbitrator'"
}
}
}
}
}
["thinking"] {
after {
["thinking"] = new Timeout {
delay = "std:randomAround(10,2)"
triggers = new Emit { event = new Internal { topic = "thought" } }
}
}
on {
["thought"] {
to = "hungry"
}
}
}
}
}
}
}
instances {
["arbitrator"] { stateMachineName = "arbitrator" }
for (i in IntSeq(0, n - 1)) {
["\(i)"] {
stateMachineName = "philosopher"
data { ["id"] = "\(i)" }
}
}
}