Skip to content

Commit bdfb102

Browse files
authored
feat: moving examples to the runtime project (#132)
1 parent 6bb7721 commit bdfb102

12 files changed

Lines changed: 1033 additions & 19 deletions

README.md

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@
55
</div>
66
<br>
77

8-
[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](LICENSE.md) [![Build](https://github.com/UIBK-DPS-DC/Cirrina/actions/workflows/build.yml/badge.svg?event=push)](https://github.com/UIBK-DPS-DC/Cirrina/actions/workflows/build.yml?event=push) [![Docker Image Version (tag)](https://img.shields.io/docker/v/collaborativestatemachines/cirrina/unstable?color=red)](https://hub.docker.com/repository/docker/collaborativestatemachines/cirrina/tags/unstable/) [![Docker Image Version (tag)](https://img.shields.io/docker/v/collaborativestatemachines/cirrina/stable?color=blue)](https://hub.docker.com/repository/docker/collaborativestatemachines/cirrina/tags/stable/)
8+
[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](LICENSE.md)
9+
[![Build](https://github.com/UIBK-DPS-DC/Cirrina/actions/workflows/build.yml/badge.svg?event=push)](https://github.com/UIBK-DPS-DC/Cirrina/actions/workflows/build.yml?event=push)
10+
[![Docker Image Version (tag)](https://img.shields.io/docker/v/collaborativestatemachines/cirrina/stable?color=blue)](https://hub.docker.com/layers/collaborativestatemachines/cirrina/stable/)
11+
[![Docker Image Version (tag)](https://img.shields.io/docker/v/collaborativestatemachines/cirrina/unstable?color=red)](https://hub.docker.com/layers/collaborativestatemachines/cirrina/unstable)
912

1013
Cirrina, a distributed Collaborative State Machines (CSM) runtime for the Cloud-Edge-IoT continuum.
11-
Collaborative State Machines is a state machine-based programming model for the Cloud-Edge-IoT
14+
Collaborative State Machines is a state-machine-based programming model for the Cloud-Edge-IoT
1215
continuum. For more information, please visit
1316
the [Project Website](https://collaborativestatemachines.github.io/).
1417

@@ -17,19 +20,3 @@ the [Distributed and Parallel Systems Group of the
1720
University Innsbruck](https://dps.uibk.ac.at/).
1821

1922
For contributions, please see the [Contribution Guidelines](CONTRIBUTING.md).
20-
21-
To deploy Cirrina using Kubernetes, see the [Helm Chart](charts/cirrina).
22-
23-
## Citing
24-
25-
```
26-
@misc{etheredge2025collaborativestatemachinesbetter,
27-
title={Collaborative State Machines: A Better Programming Model for the Cloud-Edge-IoT Continuum},
28-
author={Marlon Etheredge and Thomas Fahringer and Felix Erlacher and Elias Kohler and Stefan Pedratscher and Juan Aznar-Poveda and Nishant Saurabh and Adrien Lebre},
29-
year={2025},
30-
eprint={2507.21685},
31-
archivePrefix={arXiv},
32-
primaryClass={cs.DC},
33-
url={https://arxiv.org/abs/2507.21685},
34-
}
35-
```

examples/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Cirrina Examples
2+
3+
This directory contains a collection of examples.
4+
5+
To run an example on multiple isolated resources, we recommend
6+
using [Vagrant](https://developer.hashicorp.com/vagrant).
7+
8+
To execute the [helloWorld](tutorial/helloWorld.pkl) example, run:
9+
10+
```
11+
./cirrina \
12+
RUN=one,two \
13+
MAIN_URI=file:///examples/tutorial/helloWorld.pkl \
14+
ETCD_CONTEXT_URL=http://localhost:2379
15+
```

examples/concurrency/big.pkl

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
amends
2+
"https://raw.githubusercontent.com/CollaborativeStateMachines/Cirrina/refs/heads/develop/src/main/resources/pkl/csm/csml.pkl"
3+
4+
local n = 12
5+
6+
collaborativeStateMachine {
7+
stateMachines {
8+
["big"] {
9+
transient { ["count"] = "0" }
10+
states {
11+
["register"] = new Initial {
12+
entry { new Emit { event { topic = "register" }; target = "'sink'" } }
13+
on {
14+
["initial"] = new Transition {
15+
to = "run"
16+
}
17+
}
18+
}
19+
["run"] = new State {
20+
entry {
21+
new Eval { expression = "++count" }
22+
new Ctr { counter = "big.pings" }
23+
new Emit {
24+
event {
25+
topic = "ping"
26+
data { ["sender"] = "id" }
27+
}
28+
target = "std:takeRandom(peers).toString()"
29+
}
30+
}
31+
on {
32+
["ping"] {
33+
yields {
34+
new Emit {
35+
event {
36+
topic = "pong"
37+
data { ["sender"] = "id" }
38+
}
39+
target = "$sender.toString()"
40+
}
41+
}
42+
}
43+
["pong"] {
44+
yields {
45+
new Match {
46+
cases {
47+
new Case {
48+
of = "count % 1000 == 0"
49+
yields {
50+
new Emit { event { topic = "report" } }
51+
}
52+
}
53+
}
54+
}
55+
new Eval { expression = "++count" }
56+
new Ctr { counter = "big.pings" }
57+
new Emit {
58+
event {
59+
topic = "ping"
60+
data { ["sender"] = "id" }
61+
}
62+
target = "std:takeRandom(peers).toString()"
63+
}
64+
}
65+
}
66+
}
67+
}
68+
}
69+
}
70+
["sink"] = new StateMachine {
71+
transient {
72+
["total"] = "0"
73+
["registered"] = "0"
74+
}
75+
states {
76+
["wait"] = new Initial {
77+
on {
78+
["register"] = new Transition {
79+
yields {
80+
new Eval { expression = "++registered" }
81+
new Match {
82+
cases {
83+
new Case {
84+
of = "registered == 12"
85+
yields {
86+
new Emit { event { topic = "initial" } }
87+
}
88+
}
89+
}
90+
}
91+
}
92+
}
93+
["report"] {
94+
yields {
95+
new Eval { expression = "total += 1000" }
96+
new Ctr { counter = "sink.total"; by = 1000 }
97+
}
98+
}
99+
}
100+
}
101+
}
102+
}
103+
}
104+
}
105+
instances {
106+
["sink"] { stateMachineName = "sink" }
107+
for (i in IntSeq(0, n - 1)) {
108+
["\(i)"] {
109+
stateMachineName = "big"
110+
data {
111+
["id"] = "\(i)"
112+
["peers"] = "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11] - [\(i)]"
113+
}
114+
}
115+
}
116+
}

examples/concurrency/chameneos.pkl

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
amends "https://raw.githubusercontent.com/CollaborativeStateMachines/Cirrina/refs/heads/develop/src/main/resources/pkl/csm/csml.pkl"
2+
3+
local n = 12
4+
5+
collaborativeStateMachine {
6+
stateMachines {
7+
["chameneos"] {
8+
transient {
9+
["color"] = "std:takeRandom([1,2,3,...])"
10+
}
11+
states {
12+
["request"] = new Initial {
13+
entry {
14+
new Emit {
15+
event {
16+
topic = "requesting"
17+
data { ["id"] = "id"; ["color"] = "color" }
18+
}
19+
target = "'mall'"
20+
}
21+
}
22+
on {
23+
["matchMade"] = new Transition {
24+
to = "request"
25+
yields {
26+
new Eval { expression = "color = (function (x,y) { if (x == y) {x} else {x ^ y} })(color, $color)" }
27+
new Emit {
28+
event {
29+
topic = "change"
30+
data { ["color"] = "color" }
31+
}
32+
target = "$partner.toString()"
33+
}
34+
}
35+
}
36+
["change"] = new Transition {
37+
to = "request"
38+
yields {
39+
new Eval { expression = "color = $color" }
40+
}
41+
}
42+
}
43+
}
44+
}
45+
}
46+
["mall"] {
47+
transient {
48+
["waiting"] = "[...]"
49+
["count"] = "0"
50+
}
51+
states {
52+
["wait"] = new Initial {
53+
on {
54+
["requesting"] = new Transition {
55+
yields {
56+
new Match {
57+
cases {
58+
new Case {
59+
of = "waiting.isEmpty()"
60+
yields { new Eval { expression = "waiting += [$id]" } }
61+
}
62+
new Case {
63+
of = "!waiting.isEmpty()"
64+
yields {
65+
new Eval { expression = "++count" }
66+
new Ctr { counter = "mall.meetings" }
67+
new Emit {
68+
event {
69+
topic = "matchMade"
70+
data {
71+
["partner"] = "$id"
72+
["color"] = "$color"
73+
}
74+
}
75+
target = "waiting.get(0).toString()"
76+
}
77+
new Eval { expression = "waiting -= [waiting.get(0)]" }
78+
}
79+
}
80+
}
81+
82+
}
83+
}
84+
}
85+
}
86+
}
87+
}
88+
}
89+
}
90+
}
91+
92+
instances {
93+
["mall"] { stateMachineName = "mall" }
94+
for (i in IntSeq(0, n - 1)) {
95+
["\(i)"] {
96+
stateMachineName = "chameneos"
97+
data { ["id"] = "\(i)" }
98+
}
99+
}
100+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
amends
2+
"https://raw.githubusercontent.com/CollaborativeStateMachines/Cirrina/refs/heads/develop/src/main/resources/pkl/csm/csml.pkl"
3+
4+
local n = 3
5+
6+
collaborativeStateMachine {
7+
stateMachines {
8+
["arbiter"] {
9+
transient {
10+
["ingredients"] = "[0, 1, 2, ...]"
11+
["count"] = "0"
12+
}
13+
states {
14+
["run"] = new Initial {
15+
entry {
16+
new Eval { expression = "++count" }
17+
new Ctr { counter = "arbiter.rounds" }
18+
new Emit {
19+
event {
20+
topic = "provided"
21+
data { ["ingredients"] = "ingredients - [std:takeRandom(ingredients)]" }
22+
}
23+
}
24+
}
25+
on {
26+
["finish"] = new Transition { to = "run" }
27+
}
28+
}
29+
}
30+
}
31+
["smoker"] {
32+
states {
33+
["wait"] = new Initial {
34+
on {
35+
["provided"] = new Transition {
36+
to = "smoking"
37+
provided = "!($ingredients.contains(id))"
38+
}
39+
}
40+
}
41+
["smoking"] = new State {
42+
after {
43+
["wait"] = new Timeout {
44+
delay = "std:randomAround(10,2)"
45+
triggers = new Emit { event = new Internal { topic = "continue" } }
46+
}
47+
}
48+
on {
49+
["continue"] = new Transition {
50+
to = "wait"
51+
yields { new Emit { event { topic = "finish" }; target = "'arbiter'" } }
52+
}
53+
}
54+
}
55+
}
56+
}
57+
}
58+
}
59+
instances {
60+
["arbiter"] { stateMachineName = "arbiter" }
61+
for (i in IntSeq(0, n - 1)) {
62+
["\(i)"] {
63+
stateMachineName = "smoker"
64+
data { ["id"] = "\(i)" }
65+
}
66+
}
67+
}

examples/concurrency/count.pkl

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
amends
2+
"https://raw.githubusercontent.com/CollaborativeStateMachines/Cirrina/refs/heads/develop/src/main/resources/pkl/csm/csml.pkl"
3+
4+
collaborativeStateMachine {
5+
stateMachines {
6+
["producer"] {
7+
states {
8+
["init"] = new Initial {
9+
entry {
10+
new Emit { event = new Internal { topic = "send" } }
11+
}
12+
on { ["send"] = new Transition { to = "send" } }
13+
}
14+
["send"] = new State {
15+
after {
16+
["send"] = new Timeout {
17+
delay = "std:randomAround(10,2)"
18+
triggers = new Emit { event = new Internal { topic = "send" } }
19+
}
20+
}
21+
on {
22+
["send"] = new Transition {
23+
to = "init"
24+
yields { new Emit { event { topic = "increment" } } }
25+
}
26+
}
27+
}
28+
}
29+
}
30+
["counter"] {
31+
transient { ["count"] = "0" }
32+
states {
33+
["count"] = new Initial {
34+
on {
35+
["increment"] = new Transition {
36+
yields {
37+
new Eval { expression = "++count" }
38+
new Ctr { counter = "counter.count" }
39+
}
40+
}
41+
}
42+
}
43+
}
44+
}
45+
}
46+
}
47+
instances {
48+
["counter"] { stateMachineName = "counter" }
49+
["producer"] { stateMachineName = "producer" }
50+
}

0 commit comments

Comments
 (0)