|
| 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 | +} |
0 commit comments