diff --git a/big/big.pkl b/big/big.pkl new file mode 100644 index 0000000..3ac9522 --- /dev/null +++ b/big/big.pkl @@ -0,0 +1,92 @@ +import + "https://raw.githubusercontent.com/CollaborativeStateMachines/Cirrina/refs/heads/develop/src/main/resources/pkl/csm/csml.pkl" + +sm = new csml.StateMachine { + transient { + ["bigId"] = "std:getSequentialId()" + ["target"] = "''" + ["otherBigs"] = "[...]" + ["pingCounter"] = "0" + ["pongCounter"] = "0" + } + states { + ["registerBig"] = new csml.Initial { + entry { + new csml.Raise { + event = new csml.Global { topic = "registerBig"; data { ["bigId"] = "bigId" } } + } + } + on { + ["allBigsRegistered"] = new csml.Transition { + to = "sendPing" + do { + new csml.Eval { expression = "otherBigs = std:getAllStateMachines()" } + new csml.Eval { + expression = "otherBigs = std:removeFromList(\("otherBigs"), \("bigId"))" + } + } + } + } + } + ["sendPing"] = new csml.State { + always { + new csml.Transition { + to = "waitForPingOrPong" + iif = "pingCounter < 20000" + do { + new csml.Eval { expression = "pingCounter = pingCounter + 1" } + new csml.Eval { expression = "target = std:takeRandom(\("otherBigs"))" } + new csml.Raise { + event = new csml.Global { + topic = "ping" + data { ["sender"] = "bigId"; ["receiver"] = "target" } + } + } + } + or = "receiveRemaining" + } + } + } + ["waitForPingOrPong"] = new csml.State { + on { + ["ping"] = new csml.Transition { + iif = "$sender != bigId && $receiver == bigId" + do { + new csml.Raise { + event = new csml.Global { + topic = "pong" + data { ["sender"] = "bigId"; ["receiver"] = "$sender" } + } + } + } + } + ["pong"] = new csml.Transition { + iif = "$receiver == bigId && $sender == target" + to = "sendPing" + } + } + } + ["receiveRemaining"] = new csml.State { + entry { + new csml.Raise { event = new csml.Global { topic = "donePinging" } } + } + on { + ["ping"] = new csml.Transition { + iif = "$sender != bigId && $receiver == bigId" + do { + new csml.Raise { + event = new csml.Global { + topic = "pong" + data { ["sender"] = "bigId"; ["receiver"] = "$sender" } + } + } + } + } + ["shutdown"] = new csml.Transition { + to = "done" + } + } + } + ["done"] = new csml.Terminal {} + } +} diff --git a/big/defs.pkl b/big/defs.pkl new file mode 100644 index 0000000..8cbbffc --- /dev/null +++ b/big/defs.pkl @@ -0,0 +1 @@ +bigs = List("zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven") diff --git a/big/main.pkl b/big/main.pkl new file mode 100644 index 0000000..7f52427 --- /dev/null +++ b/big/main.pkl @@ -0,0 +1,27 @@ +amends + "https://raw.githubusercontent.com/Frnd-me/Cirrina/refs/heads/develop/src/main/resources/pkl/csm/csml.pkl" + +import "big.pkl" +import "defs.pkl" +import "sink.pkl" + +version = "4.0.0" +collaborativeStateMachine { + stateMachines { + ["sink"] = sink.sm + ["big"] = big.sm + } +} +instances { + ["sink"] = "sink" + for (b in defs.bigs) { [b] = "big" } +} +instanceData { + for (b in defs.bigs) { + [b] { + ["bigId"] = "'\(b)'" + ["otherBigs"] = + "['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', ...] - ['\(b)']" + } + } +} diff --git a/big/services.pkl b/big/services.pkl new file mode 100644 index 0000000..7459387 --- /dev/null +++ b/big/services.pkl @@ -0,0 +1,4 @@ +amends + "https://raw.githubusercontent.com/Frnd-me/Cirrina/refs/heads/develop/src/main/resources/pkl/csm/bindings.pkl" + +bindings {} diff --git a/big/sink.pkl b/big/sink.pkl new file mode 100644 index 0000000..1f31553 --- /dev/null +++ b/big/sink.pkl @@ -0,0 +1,30 @@ +import + "https://raw.githubusercontent.com/Frnd-me/Cirrina/refs/heads/develop/src/main/resources/pkl/csm/csml.pkl" + +sm = new csml.StateMachine { + transient { + ["doneCounter"] = "0" + ["cumulatedPongCounter"] = "0" + } + states { + ["waitingForBigs"] = new csml.Initial { + on { + ["donePinging"] = new csml.Transition { + to = "isFinal" + do { new csml.Eval { expression = "++doneCounter" } } + } + } + } + ["isFinal"] = new csml.State { + always { + new csml.Transition { + to = "done" + iif = "doneCounter == 12" + do { new csml.Raise { event = new csml.Global { topic = "shutdown" } } } + or = "waitingForBigs" + } + } + } + ["done"] = new csml.Terminal {} + } +} diff --git a/chameneos/chameneos.pkl b/chameneos/chameneos.pkl new file mode 100644 index 0000000..8c4e0e2 --- /dev/null +++ b/chameneos/chameneos.pkl @@ -0,0 +1,53 @@ +import + "https://raw.githubusercontent.com/CollaborativeStateMachines/Cirrina/refs/heads/develop/src/main/resources/pkl/csm/csml.pkl" + +sm = new csml.StateMachine { + transient { + ["chameneosId"] = "std:getUniqueId()" + ["color"] = "std:getRandomColor()" + ["individualMeetingCounter"] = "0" + } + states { + ["requestingPartner"] = new csml.Initial { + entry { + new csml.Raise { + event = new csml.Global { + topic = "requestingPartner" + data { ["chameneosId"] = "chameneosId"; ["chameneosColor"] = "color" } + } + } + } + on { + ["matchMade"] = new csml.Transition { + to = "matchFound" + iif = "$chameneos == chameneosId" + } + ["change"] = new csml.Transition { + to = "requestingPartner" + iif = "$partner == chameneosId" + do { + new csml.Eval { expression = "color = std:complement(color, $color)" } + new csml.Eval { expression = "individualMeetingCounter = individualMeetingCounter + 1" } + } + } + ["done"] = new csml.Transition { + to = "done" + } + } + } + ["matchFound"] = new csml.State { + entry { + new csml.Eval { expression = "color = std:complement(color, $color)" } + new csml.Eval { expression = "individualMeetingCounter = individualMeetingCounter + 1" } + new csml.Raise { + event = new csml.Global { + topic = "change" + data { ["partner"] = "$partner"; ["color"] = "color" } + } + } + } + always { new csml.Transition { to = "requestingPartner" } } + } + ["done"] = new csml.Terminal {} + } +} diff --git a/chameneos/defs.pkl b/chameneos/defs.pkl new file mode 100644 index 0000000..0f3ebe5 --- /dev/null +++ b/chameneos/defs.pkl @@ -0,0 +1,2 @@ +chameneos = List("one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven") + diff --git a/chameneos/main.pkl b/chameneos/main.pkl new file mode 100644 index 0000000..4757251 --- /dev/null +++ b/chameneos/main.pkl @@ -0,0 +1,23 @@ +amends + "https://raw.githubusercontent.com/Frnd-me/Cirrina/refs/heads/develop/src/main/resources/pkl/csm/csml.pkl" + +import "chameneos.pkl" +import "defs.pkl" +import "mall.pkl" + +version = "4.0.0" +collaborativeStateMachine { + stateMachines { + ["mall"] = mall.sm + ["chameneos"] = chameneos.sm + } +} +instances { + ["mall"] = "mall" + for (c in defs.chameneos) { [c] = "chameneos" } +} +instanceData { + for (c in defs.chameneos) { + [c] { ["chameneosId"] = "'\(c)'" } + } +} diff --git a/chameneos/mall.pkl b/chameneos/mall.pkl new file mode 100644 index 0000000..a6f2200 --- /dev/null +++ b/chameneos/mall.pkl @@ -0,0 +1,47 @@ +import + "https://raw.githubusercontent.com/Frnd-me/Cirrina/refs/heads/develop/src/main/resources/pkl/csm/csml.pkl" + +sm = new csml.StateMachine { + transient { + ["waitingList"] = "[...]" + ["meetingCounter"] = "0" + } + states { + ["waitingForChameneos"] = new csml.Initial { + on { + ["requestingPartner"] = new csml.Transition { + to = "waitingForChameneos" + iif = "waitingList.isEmpty() && meetingCounter < 20000" + do { new csml.Eval { expression = "waitingList += [$chameneosId]" } } + or = "scheduleMeeting" + } + } + } + ["scheduleMeeting"] = new csml.State { + always { + new csml.Transition { + to = "waitingForChameneos" + iif = "!waitingList.isEmpty() && meetingCounter < 20000" + do { + new csml.Eval { expression = "++meetingCounter" } + new csml.Raise { + event = new csml.Global { + topic = "matchMade" + data { + ["partner"] = "$chameneosId" + ["color"] = "$chameneosColor" + } + } + target = "waitingList.get(0)" + } + new csml.Eval { expression = "waitingList -= [waitingList.get(0)]" } + } + or = "done" + } + } + } + ["done"] = new csml.Terminal { + entry { new csml.Raise { event = new csml.Global { topic = "done" } } } + } + } +} diff --git a/chameneos/services.pkl b/chameneos/services.pkl new file mode 100644 index 0000000..7459387 --- /dev/null +++ b/chameneos/services.pkl @@ -0,0 +1,4 @@ +amends + "https://raw.githubusercontent.com/Frnd-me/Cirrina/refs/heads/develop/src/main/resources/pkl/csm/bindings.pkl" + +bindings {} diff --git a/count/counter.pkl b/count/counter.pkl index c25cbdc..d7a9ea9 100644 --- a/count/counter.pkl +++ b/count/counter.pkl @@ -1,5 +1,5 @@ import - "https://raw.githubusercontent.com/CollaborativeStateMachines/Cirrina/refs/heads/develop/src/main/resources/pkl/csm/csml.pkl" + "https://raw.githubusercontent.com/Frnd-me/Cirrina/refs/heads/develop/src/main/resources/pkl/csm/csml.pkl" sm = new csml.StateMachine { transient { @@ -9,8 +9,8 @@ sm = new csml.StateMachine { ["counting"] = new csml.Initial { on { ["increment"] = new csml.Transition { - iif = "count < 1000000" - do { new csml.Eval { expression = "count = count + 1" } } + iif = "count < 50000" + do { new csml.Eval { expression = "++count" } } to = "counting" or = "done" } diff --git a/count/main.pkl b/count/main.pkl index a4df5e2..8f9afdc 100644 --- a/count/main.pkl +++ b/count/main.pkl @@ -1,11 +1,17 @@ amends - "https://raw.githubusercontent.com/CollaborativeStateMachines/Cirrina/refs/heads/develop/src/main/resources/pkl/csm/csml.pkl" + "https://raw.githubusercontent.com/Frnd-me/Cirrina/refs/heads/develop/src/main/resources/pkl/csm/csml.pkl" import "counter.pkl" import "producer.pkl" version = "4.0.0" -stateMachines { - ["producer"] = producer.sm - ["counter"] = counter.sm +collaborativeStateMachine { + stateMachines { + ["producerMachine"] = producer.sm + ["counterMachine"] = counter.sm + } +} +instances { + ["producer"] = "producerMachine" + ["counter"] = "counterMachine" } diff --git a/count/producer.pkl b/count/producer.pkl index 7f0aeab..2dfe6a1 100644 --- a/count/producer.pkl +++ b/count/producer.pkl @@ -1,10 +1,7 @@ import - "https://raw.githubusercontent.com/CollaborativeStateMachines/Cirrina/refs/heads/develop/src/main/resources/pkl/csm/csml.pkl" + "https://raw.githubusercontent.com/Frnd-me/Cirrina/refs/heads/develop/src/main/resources/pkl/csm/csml.pkl" sm = new csml.StateMachine { - transient { - ["messagesSent"] = "0" - } states { ["sendMessage"] = new csml.Initial { entry { @@ -14,7 +11,7 @@ sm = new csml.StateMachine { ["increment"] = new csml.Transition { to = "sendMessage" } ["finalCount"] = new csml.Transition { to = "success" - iif = "$count == 1000000" + iif = "$count == 50000" or = "failure" } } diff --git a/count/services.pkl b/count/services.pkl index 07c151f..7459387 100644 --- a/count/services.pkl +++ b/count/services.pkl @@ -1,4 +1,4 @@ amends - "https://raw.githubusercontent.com/CollaborativeStateMachines/Cirrina/refs/heads/develop/src/main/resources/pkl/csm/bindings.pkl" + "https://raw.githubusercontent.com/Frnd-me/Cirrina/refs/heads/develop/src/main/resources/pkl/csm/bindings.pkl" bindings {} diff --git a/philosophers/arbitrator.pkl b/philosophers/arbitrator.pkl index 4551648..30e1929 100644 --- a/philosophers/arbitrator.pkl +++ b/philosophers/arbitrator.pkl @@ -1,87 +1,46 @@ -import "https://raw.githubusercontent.com/CollaborativeStateMachines/Cirrina/refs/heads/develop/src/main/resources/pkl/csm/Csml.pkl" +import + "https://raw.githubusercontent.com/Frnd-me/Cirrina/refs/heads/develop/src/main/resources/pkl/csm/csml.pkl" -class StateMachine extends Csml.StateMachineDescription { - name = "arbitrator" - localContext { - variables { - new { - name = "allocated" - value = "[...]" - } - } +sm = new csml.StateMachine { + transient { + ["allocated"] = "[...]" + ["doneCounter"] = "0" } states { - new Csml.StateDescription { - name = "waitingForRequests" - initial = true - on { - new Csml.OnTransitionDescription { - event = "requesting" - guards { - new Csml.GuardDescription { - expression = "utility:notIn(\("allocated"), $forkOne, ($forkOne + 1) % 6)" - } - } - actions { - new Csml.AssignActionDescription { - variable = new { - name = "allocated" - value = "utility:addToList(\("allocated"), $forkOne, ($forkOne + 1) % 6)" - } - } - new Csml.RaiseActionDescription { - event { - name = "allocated" - data { - new { - name = "forkOne" - value = "$forkOne" - } - } - channel = "global" - } - } - } - } - new Csml.OnTransitionDescription { - event = "requesting" - guards { - new { - expression = "!utility:notIn(\("allocated"), $forkOne, ($forkOne + 1) % 6)" - } - } - actions { - new Csml.RaiseActionDescription { - event { - name = "denied" - data { - new { - name = "forkOne" - value = "$forkOne" - } - } - channel = "global" - } - } - } - } - new Csml.OnTransitionDescription { - event = "finished" - guards { - new Csml.GuardDescription { - expression = "utility:in(\("allocated"), $forkOne, ($forkOne + 1) % 6)" - } - } - actions { - new Csml.AssignActionDescription { - variable = new { - name = "allocated" - value = "utility:removeFromList(\("allocated"), $forkOne, ($forkOne + 1) % 6)" - } - } - } - } - } - } + ["waitingForRequests"] = new csml.Initial { + on { + ["requesting"] = new csml.Transition { + to = "waitingForRequests" + iif = "!(allocated.contains($forkId) || allocated.contains(($forkId + 1) % 6))" + do { + new csml.Eval { expression = "allocated + [$forkId, ($forkId + 1) % 6]" } + new csml.Raise { event = new csml.Global { topic = "allocated" }; target = "$replyTo" } + } + or = "denied" + } + ["finished"] = new csml.Transition { + to = "waitingForRequests" + iif = "allocated.contains($forkId) && allocated.contains(($forkId + 1) % 6)" + do { new csml.Eval { expression = "allocated - [$forkId, ($forkId + 1) % 6]" } } + } + ["done"] = new csml.Transition { + to = "waitingForRequests" + iif = "doneCounter < 5" + do { new csml.Eval { expression = "doneCounter = doneCounter + 1" } } + or = "done" + } + } + } + ["denied"] = new csml.State { + always { + new csml.Transition { + to = "waitingForRequests" + do { + new csml.Raise { event = new csml.Global { topic = "denied" }; target = "$replyTo" } + } + } + } + } + ["done"] = new csml.Terminal {} } -} \ No newline at end of file +} diff --git a/philosophers/defs.pkl b/philosophers/defs.pkl index 595fd42..1be02ab 100644 --- a/philosophers/defs.pkl +++ b/philosophers/defs.pkl @@ -1 +1 @@ -philosophers = List("1", "2", "3", "4", "5", "6") \ No newline at end of file +philosophers = List("zero", "one", "two", "three", "four", "five") diff --git a/philosophers/main.pkl b/philosophers/main.pkl index 4be768d..cf3ebb3 100644 --- a/philosophers/main.pkl +++ b/philosophers/main.pkl @@ -1,14 +1,25 @@ -amends "https://raw.githubusercontent.com/CollaborativeStateMachines/Cirrina/refs/heads/develop/src/main/resources/pkl/csm/Csml.pkl" +amends + "https://raw.githubusercontent.com/Frnd-me/Cirrina/refs/heads/develop/src/main/resources/pkl/csm/csml.pkl" import "arbitrator.pkl" import "defs.pkl" import "philosopher.pkl" - -name = "benchmark" -version = "3.0.0" -stateMachines { - new arbitrator.StateMachine {} - for (_name in defs.philosophers) { - new philosopher.StateMachine {name = _name } +version = "4.0.0" +collaborativeStateMachine { + stateMachines { + ["arbitrator"] = arbitrator.sm + ["philosopher"] = philosopher.sm + } +} +instances { + ["arbitrator"] = "arbitrator" + for (p in defs.philosophers) { [p] = "philosopher" } +} +instanceData { + for (p in defs.philosophers.mapIndexed((i, name) -> new Dynamic { idx = i; id = name })) { + [p.id] { + ["philosopherId"] = "'\(p.id)'" + ["forkId"] = "\(p.idx)" + } + } } -} \ No newline at end of file diff --git a/philosophers/philosopher.pkl b/philosophers/philosopher.pkl index 458c60a..c96ac59 100644 --- a/philosophers/philosopher.pkl +++ b/philosophers/philosopher.pkl @@ -1,122 +1,57 @@ -import "https://raw.githubusercontent.com/CollaborativeStateMachines/Cirrina/refs/heads/develop/src/main/resources/pkl/csm/Csml.pkl" +import + "https://raw.githubusercontent.com/Frnd-me/Cirrina/refs/heads/develop/src/main/resources/pkl/csm/csml.pkl" -class StateMachine extends Csml.StateMachineDescription { - name = "philosopher" - local self = this - localContext { - variables { - new { - name = "counter" - value = "0" - } - } +sm = new csml.StateMachine { + transient { + ["tryCounter"] = "0" + ["eatCounter"] = "0" } states { - new { - name = "requestingFork" - initial = true - entry { - new Csml.AssignActionDescription { - variable = new { - name = "counter" - value = "counter + 1" - } - } - new Csml.RaiseActionDescription { - event { - name = "requesting" - data { - new { - name = "forkOne" - value = self.name - } - } - channel = "global" - } - } - } - on { - new { - event = "allocated" - guards { - new { - expression = "$forkOne == \(self.name) && ($forkOne + 1) % 6 == (\(self.name) + 1) % 6" - } - } - target = "eating" - } - new { - event = "denied" - guards { - new { - expression = "$forkOne == \(self.name) && ($forkOne + 1) % 6 == (\(self.name) + 1) % 6" - } - new { - expression = "counter <= 16000" - } - } - target = "requestingFork" - } - new { - event = "denied" - guards { - new { - expression = "$forkOne == \(self.name) && ($forkOne + 1) % 6 == (\(self.name) + 1) % 6" - } - new { - expression = "counter > 16000" - } - } - target = "leave" - } - } - } - new Csml.StateDescription { - name = "eating" + ["requestingFork"] = new csml.Initial { entry { - new Csml.RaiseActionDescription { - event { - name = "finished" + new csml.Eval { expression = "++tryCounter" } + new csml.Raise { + event = new csml.Global { + topic = "requesting" data { - new { - name = "forkOne" - value = self.name - } + ["replyTo"] = "philosopherId" + ["forkId"] = "forkId" } - channel = "global" } } } on { - new Csml.OnTransitionDescription { - event = "finished" - guards { - new Csml.GuardDescription { - expression = "$forkOne == \(self.name) && ($forkOne + 1) % 6 == (\(self.name) + 1) % 6" - } - new Csml.GuardDescription { - expression = "counter <= 16000" - } - } - target = "requestingFork" + ["allocated"] = new csml.Transition { to = "eating" } + ["denied"] = new csml.Transition { to = "evaluateCounter" } + } + } + ["evaluateCounter"] = new csml.State { + always { + new csml.Transition { + to = "requestingFork" + iif = "eatCounter < 16000" + or = "leave" } - new Csml.OnTransitionDescription { - event = "finished" - guards { - new Csml.GuardDescription { - expression = "$forkOne == \(self.name) && ($forkOne + 1) % 6 == (\(self.name) + 1) % 6" - } - new Csml.GuardDescription { - expression = "counter > 16000" + } + } + ["eating"] = new csml.State { + always { + new csml.Transition { + to = "evaluateCounter" + do { + new csml.Eval { expression = "++eatCounter" } + new csml.Raise { + event = new csml.Global { + topic = "finished" + data { ["forkId"] = "forkId" } + } } } - target = "leave" } } } - new Csml.StateDescription { - name = "leave" - terminal = true + ["leave"] = new csml.Terminal { + entry { new csml.Raise { event = new csml.Global { topic = "done" } } } } } -} \ No newline at end of file +} diff --git a/philosophers/services.pkl b/philosophers/services.pkl index 41ac2ec..7459387 100644 --- a/philosophers/services.pkl +++ b/philosophers/services.pkl @@ -1,4 +1,4 @@ -amends "https://raw.githubusercontent.com/CollaborativeStateMachines/Cirrina/refs/heads/develop/src/main/resources/pkl/csm/ServiceImplementationBindings.pkl" +amends + "https://raw.githubusercontent.com/Frnd-me/Cirrina/refs/heads/develop/src/main/resources/pkl/csm/bindings.pkl" -bindings { -} \ No newline at end of file +bindings {} diff --git a/pingPong/main.pkl b/pingPong/main.pkl new file mode 100644 index 0000000..d9e35f6 --- /dev/null +++ b/pingPong/main.pkl @@ -0,0 +1,17 @@ +amends + "https://raw.githubusercontent.com/Frnd-me/Cirrina/refs/heads/develop/src/main/resources/pkl/csm/csml.pkl" + +import "ping.pkl" +import "pong.pkl" + +version = "4.0.0" +collaborativeStateMachine { + stateMachines { + ["pingMachine"] = ping.sm + ["pongMachine"] = pong.sm + } +} +instances { + ["ping"] = "pingMachine" + ["pong"] = "pongMachine" +} diff --git a/pingPong/ping.pkl b/pingPong/ping.pkl new file mode 100644 index 0000000..710ced8 --- /dev/null +++ b/pingPong/ping.pkl @@ -0,0 +1,24 @@ +import + "https://raw.githubusercontent.com/Frnd-me/Cirrina/refs/heads/develop/src/main/resources/pkl/csm/csml.pkl" + +sm = new csml.StateMachine { + transient { ["numPings"] = "50000" } + states { + ["ping"] = new csml.Initial { + entry { + new csml.Raise { event = new csml.Global { topic = "ping" } } + new csml.Eval { expression = "--numPings" } + } + on { + ["pong"] = new csml.Transition { + iif = "numPings != 0" + to = "ping" + or = "done" + } + } + } + ["done"] = new csml.Terminal { + entry { new csml.Raise { event = new csml.Global { topic = "done" } } } + } + } +} diff --git a/pingpong/pong.pkl b/pingPong/pong.pkl similarity index 52% rename from pingpong/pong.pkl rename to pingPong/pong.pkl index 818dae8..d7ffdbe 100644 --- a/pingpong/pong.pkl +++ b/pingPong/pong.pkl @@ -1,14 +1,12 @@ import - "https://raw.githubusercontent.com/CollaborativeStateMachines/Cirrina/refs/heads/develop/src/main/resources/pkl/csm/csml.pkl" + "https://raw.githubusercontent.com/Frnd-me/Cirrina/refs/heads/develop/src/main/resources/pkl/csm/csml.pkl" sm = new csml.StateMachine { states { ["pong"] = new csml.Initial { on { ["ping"] = new csml.Transition { - do { - new csml.Raise { event = new csml.Global { topic = "pong" } } - } + do { new csml.Raise { event = new csml.Global { topic = "pong" } } } } ["done"] = new csml.Transition { to = "done" } } diff --git a/pingPong/services.pkl b/pingPong/services.pkl new file mode 100644 index 0000000..7459387 --- /dev/null +++ b/pingPong/services.pkl @@ -0,0 +1,4 @@ +amends + "https://raw.githubusercontent.com/Frnd-me/Cirrina/refs/heads/develop/src/main/resources/pkl/csm/bindings.pkl" + +bindings {} diff --git a/pingpong/benchmark/Akka.txt b/pingpong/benchmark/Akka.txt deleted file mode 100644 index f8f6882..0000000 --- a/pingpong/benchmark/Akka.txt +++ /dev/null @@ -1,31 +0,0 @@ -Number of pings: 50.000 -Execution - Iterations: -PingPongAkkaActorBenchmark Iteration-0: 316.151 ms -PingPongAkkaActorBenchmark Iteration-1: 118.366 ms -PingPongAkkaActorBenchmark Iteration-2: 77.245 ms -PingPongAkkaActorBenchmark Iteration-3: 84.737 ms -PingPongAkkaActorBenchmark Iteration-4: 70.632 ms -PingPongAkkaActorBenchmark Iteration-5: 76.096 ms -PingPongAkkaActorBenchmark Iteration-6: 72.107 ms -PingPongAkkaActorBenchmark Iteration-7: 67.815 ms -PingPongAkkaActorBenchmark Iteration-8: 64.724 ms -PingPongAkkaActorBenchmark Iteration-9: 65.730 ms -PingPongAkkaActorBenchmark Iteration-10: 68.262 ms -PingPongAkkaActorBenchmark Iteration-11: 64.844 ms - - -Execution - Summary: - Total executions = 12 - Filtered executions = 10 -PingPongAkkaActorBenchmark Best Time: 64.724 ms -PingPongAkkaActorBenchmark Worst Time: 84.737 ms -PingPongAkkaActorBenchmark Median: 69.447 ms -PingPongAkkaActorBenchmark Arith. Mean Time: 71.219 ms -PingPongAkkaActorBenchmark Geo. Mean Time: 70.966 ms -PingPongAkkaActorBenchmark Harmonic Mean Time: 70.724 ms -PingPongAkkaActorBenchmark Std. Dev Time: 6.142 ms -PingPongAkkaActorBenchmark Lower Confidence: 67.412 ms -PingPongAkkaActorBenchmark Higher Confidence: 75.026 ms -PingPongAkkaActorBenchmark Error Window: 3.807 ms (5.345 percent) -PingPongAkkaActorBenchmark Coeff. of Variation: 0.086 -PingPongAkkaActorBenchmark Skewness: 0.979 \ No newline at end of file diff --git a/pingpong/benchmark/AkkaRemote.txt b/pingpong/benchmark/AkkaRemote.txt deleted file mode 100644 index 8f63738..0000000 --- a/pingpong/benchmark/AkkaRemote.txt +++ /dev/null @@ -1,30 +0,0 @@ -Number of pings: 50.000 -Execution - Iterations: -PingPongAkkaActorBenchmark Iteration-0: 30511.704 ms -PingPongAkkaActorBenchmark Iteration-1: 25736.073 ms -PingPongAkkaActorBenchmark Iteration-2: 30145.372 ms -PingPongAkkaActorBenchmark Iteration-3: 31287.985 ms -PingPongAkkaActorBenchmark Iteration-4: 33002.205 ms -PingPongAkkaActorBenchmark Iteration-5: 30022.782 ms -PingPongAkkaActorBenchmark Iteration-6: 31745.709 ms -PingPongAkkaActorBenchmark Iteration-7: 32723.041 ms -PingPongAkkaActorBenchmark Iteration-8: 32083.870 ms -PingPongAkkaActorBenchmark Iteration-9: 29523.999 ms -PingPongAkkaActorBenchmark Iteration-10: 24884.690 ms -PingPongAkkaActorBenchmark Iteration-11: 28197.974 ms - -Execution - Summary: - Total executions = 12 - Filtered executions = 12 -PingPongAkkaActorBenchmark Best Time: 24884.690 ms -PingPongAkkaActorBenchmark Worst Time: 33002.205 ms -PingPongAkkaActorBenchmark Median: 30328.538 ms -PingPongAkkaActorBenchmark Arith. Mean Time: 29988.784 ms -PingPongAkkaActorBenchmark Geo. Mean Time: 29881.058 ms -PingPongAkkaActorBenchmark Harmonic Mean Time: 29767.749 ms -PingPongAkkaActorBenchmark Std. Dev Time: 2476.228 ms -PingPongAkkaActorBenchmark Lower Confidence: 28587.726 ms -PingPongAkkaActorBenchmark Higher Confidence: 31389.841 ms -PingPongAkkaActorBenchmark Error Window: 1401.058 ms (4.672 percent) -PingPongAkkaActorBenchmark Coeff. of Variation: 0.083 -PingPongAkkaActorBenchmark Skewness: -0.904 \ No newline at end of file diff --git a/pingpong/benchmark/CSM.txt b/pingpong/benchmark/CSM.txt deleted file mode 100644 index f334d1e..0000000 --- a/pingpong/benchmark/CSM.txt +++ /dev/null @@ -1,20 +0,0 @@ -Number of pings: 50.000 -Execution - Iterations: -CsmPingPong Iteration-0: 37631.159 ms -CsmPingPong Iteration-1: 41742.721 ms -CsmPingPong Iteration-2: 41878.055 ms -CsmPingPong Iteration-3: 41937.863 ms -CsmPingPong Iteration-4: 38841.834 ms -CsmPingPong Iteration-5: 38506.544 ms -CsmPingPong Iteration-6: 43645.336 ms -CsmPingPong Iteration-7: 41605.493 ms -CsmPingPong Iteration-8: 41993.211 ms -CsmPingPong Iteration-9: 41589.462 ms -CsmPingPong Iteration-10: 42283.925 ms -CsmPingPong Iteration-11: 41893.918 ms - -Execution - Summary: - Total executions = 12 - Filtered executions = 12 -PingPongAkkaActorBenchmark Best Time: 37631.159 ms -PingPongAkkaActorBenchmark Worst Time: 43645.336 ms \ No newline at end of file diff --git a/pingpong/main.pkl b/pingpong/main.pkl deleted file mode 100644 index 4ba7532..0000000 --- a/pingpong/main.pkl +++ /dev/null @@ -1,11 +0,0 @@ -amends - "https://raw.githubusercontent.com/CollaborativeStateMachines/Cirrina/refs/heads/develop/src/main/resources/pkl/csm/csml.pkl" - -import "ping.pkl" -import "pong.pkl" - -version = "4.0.0" -stateMachines { - ["ping"] = ping.sm - ["pong"] = pong.sm -} diff --git a/pingpong/ping.pkl b/pingpong/ping.pkl deleted file mode 100644 index ccc3819..0000000 --- a/pingpong/ping.pkl +++ /dev/null @@ -1,30 +0,0 @@ -import - "https://raw.githubusercontent.com/CollaborativeStateMachines/Cirrina/refs/heads/develop/src/main/resources/pkl/csm/csml.pkl" - -sm = new csml.StateMachine { - transient { - ["totalMessages"] = "50000" - } - states { - ["ping"] = new csml.Initial { - entry { - new csml.Raise { event = new csml.Global { topic = "ping" } } - new csml.Eval { expression = "totalMessages = totalMessages - 1" } - } - on { - ["pong"] = new csml.Transition { - iif { - "totalMessages != 0" - } - to = "ping" - or = "done" - } - } - } - ["done"] = new csml.Terminal { - entry { - new csml.Raise { event = new csml.Global { topic = "done" } } - } - } - } -} diff --git a/pingpong/services.pkl b/pingpong/services.pkl deleted file mode 100644 index 07c151f..0000000 --- a/pingpong/services.pkl +++ /dev/null @@ -1,4 +0,0 @@ -amends - "https://raw.githubusercontent.com/CollaborativeStateMachines/Cirrina/refs/heads/develop/src/main/resources/pkl/csm/bindings.pkl" - -bindings {} diff --git a/sleepingBarber/barber.pkl b/sleepingBarber/barber.pkl index 3282012..1d09d2f 100644 --- a/sleepingBarber/barber.pkl +++ b/sleepingBarber/barber.pkl @@ -1,59 +1,32 @@ import - "https://raw.githubusercontent.com/CollaborativeStateMachines/Cirrina/refs/heads/develop/src/main/resources/pkl/csm/Csml.pkl" + "https://raw.githubusercontent.com/Frnd-me/Cirrina/refs/heads/develop/src/main/resources/pkl/csm/csml.pkl" -class StateMachine extends Csml.StateMachineDescription { - name = "barber" +sm = new csml.StateMachine { states { - new { - name = "sleeping" - initial = true - entry { - new Csml.RaiseActionDescription { - event { - name = "statusSleeping" - channel = "global" - } - } - } + ["sleeping"] = new csml.Initial { + entry { new csml.Raise { event = new csml.Global { topic = "statusSleeping" } } } on { - new { - event = "enter" - target = "cutting" + ["enter"] = new csml.Transition { + to = "cutting" + do { + new csml.Raise { event = new csml.Global { topic = "comeIn" }; target = "$customer" } + } } + ["terminate"] = new csml.Transition { to = "done" } } } - new { - name = "cutting" + ["cutting"] = new csml.State { always { - new { - guards { - new { - expression = "utility:busyWait(1000) == 1000" - } - } - actions { - new Csml.RaiseActionDescription { - event { - name = "done" - data { - new { - name = "customer" - value = "$customer" - } - } - channel = "global" - } - } - new Csml.RaiseActionDescription { - event { - name = "getNext" - channel = "global" - } - } + new csml.Transition { + to = "sleeping" + iif = "(function (){ let x = 0; while ( x < 1000) {x++}; return true})()" + do { + new csml.Raise { event = new csml.Global { topic = "done" }; target = "$customer" } + new csml.Raise { event = new csml.Global { topic = "getNext" } } } - target = "sleeping" } } } + ["done"] = new csml.Terminal {} } } diff --git a/sleepingBarber/customer.pkl b/sleepingBarber/customer.pkl index 2d99b51..70c3c9c 100644 --- a/sleepingBarber/customer.pkl +++ b/sleepingBarber/customer.pkl @@ -1,127 +1,51 @@ -import "https://raw.githubusercontent.com/CollaborativeStateMachines/Cirrina/refs/heads/develop/src/main/resources/pkl/csm/Csml.pkl" +import + "https://raw.githubusercontent.com/Frnd-me/Cirrina/refs/heads/develop/src/main/resources/pkl/csm/csml.pkl" -class StateMachine extends Csml.StateMachineDescription { - name = "customer" - local self = this - localContext { - variables { - new { - name = "counter" - value = "0" - } - } - } +sm = new csml.StateMachine { + transient { ["counter"] = "0" } states { - new { - name = "init" - initial = true + ["init"] = new csml.Initial { on { - new { - event = "ready" - target = "requestHaircut" - } + ["ready"] = new csml.Transition { to = "requestHaircut" } } } - new { - name = "requestHaircut" + ["requestHaircut"] = new csml.State { entry { - new Csml.RaiseActionDescription { - event { - name = "customerEnter" - data { - new { - name = "customer" - value = self.name - } - } - channel = "global" + new csml.Raise { + event = new csml.Global { + topic = "customerEnter" + data { ["customer"] = "customerId" } } } } on { - new { - event = "full" - guards { - new { - expression = "$customer == \(self.name)" - } - } - target = "requestHaircut" - } - new { - event = "enter" - guards { - new { - expression = "$customer == \(self.name)" - } - } - target = "gettingHaircut" - } - new { - event = "waiting" - guards { - new { - expression = "$customer == \(self.name)" - } - } - target = "waiting" - } + ["full"] = new csml.Transition { to = "requestHaircut" } + ["comeIn"] = new csml.Transition { to = "gettingHaircut" } + ["waiting"] = new csml.Transition { to = "waiting" } } } - new { - name = "gettingHaircut" - entry { - new Csml.AssignActionDescription { - variable = new { - name = "counter" - value = "counter + 1" - } - } - } + ["gettingHaircut"] = new csml.State { + entry { new csml.Eval { expression = "++counter" } } on { - new { - event = "done" - guards { - new { - expression = "$customer == \(self.name)" - } - new { - expression = "counter < 333" - } - } - target = "requestHaircut" - } - new { - event = "done" - guards { - new { - expression = "$customer == \(self.name)" - } - new { - expression = "counter >= 333" - } - } - target = "leave" + ["done"] = new csml.Transition { to = "evaluateCounter" } + } + } + ["evaluateCounter"] = new csml.State { + always { + new csml.Transition { + to = "requestHaircut" + iif = "counter < 1000" + or = "leave" } } } - new { - name = "waiting" + ["waiting"] = new csml.State { on { - new { - event = "enter" - guards { - new { - expression = "$customer == \(self.name)" - } - } - target = "gettingHaircut" - } + ["comeIn"] = new csml.Transition { to = "gettingHaircut" } } } - new { - name = "leave" - terminal = true + ["leave"] = new csml.Terminal { + entry { new csml.Raise { event = new csml.Global { topic = "doneCutting" } } } } } } diff --git a/sleepingBarber/defs.pkl b/sleepingBarber/defs.pkl index 27526ab..9e1e579 100644 --- a/sleepingBarber/defs.pkl +++ b/sleepingBarber/defs.pkl @@ -1 +1 @@ -customers = List("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15") +customers = List("zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen") diff --git a/sleepingBarber/main.pkl b/sleepingBarber/main.pkl index 86655d0..73d88f3 100644 --- a/sleepingBarber/main.pkl +++ b/sleepingBarber/main.pkl @@ -1,16 +1,26 @@ -amends "https://raw.githubusercontent.com/CollaborativeStateMachines/Cirrina/refs/heads/develop/src/main/resources/pkl/csm/Csml.pkl" +amends + "https://raw.githubusercontent.com/Frnd-me/Cirrina/refs/heads/develop/src/main/resources/pkl/csm/csml.pkl" import "barber.pkl" import "customer.pkl" import "defs.pkl" import "waitingRoom.pkl" -name = "benchmark" -version = "3.0.0" -stateMachines { - new barber.StateMachine {} - for (_def in defs.customers) { - new customer.StateMachine { name = _def } +version = "4.0.0" +collaborativeStateMachine { + stateMachines { + ["barber"] = barber.sm + ["customer"] = customer.sm + ["waitingRoom"] = waitingRoom.sm + } +} +instances { + ["barber"] = "barber" + for (c in defs.customers) { [c] = "customer" } + ["waitingRoom"] = "waitingRoom" +} +instanceData { + for (c in defs.customers) { + [c] { ["customerId"] = "'\(c)'" } } - new waitingRoom.StateMachine {} } diff --git a/sleepingBarber/services.pkl b/sleepingBarber/services.pkl index 48fc97f..7459387 100644 --- a/sleepingBarber/services.pkl +++ b/sleepingBarber/services.pkl @@ -1,3 +1,4 @@ -amends "https://raw.githubusercontent.com/CollaborativeStateMachines/Cirrina/refs/heads/develop/src/main/resources/pkl/csm/ServiceImplementationBindings.pkl" +amends + "https://raw.githubusercontent.com/Frnd-me/Cirrina/refs/heads/develop/src/main/resources/pkl/csm/bindings.pkl" bindings {} diff --git a/sleepingBarber/waitingRoom.pkl b/sleepingBarber/waitingRoom.pkl index 94f49ba..ac77854 100644 --- a/sleepingBarber/waitingRoom.pkl +++ b/sleepingBarber/waitingRoom.pkl @@ -1,193 +1,94 @@ -import "https://raw.githubusercontent.com/CollaborativeStateMachines/Cirrina/refs/heads/develop/src/main/resources/pkl/csm/Csml.pkl" +import + "https://raw.githubusercontent.com/Frnd-me/Cirrina/refs/heads/develop/src/main/resources/pkl/csm/csml.pkl" -class StateMachine extends Csml.StateMachineDescription { - name = "waitingRoom" - localContext { - variables { - new { - name = "waitingCustomers" - value = "[...]" - } - new { - name = "barberStatus" - value = "''" - } - } +sm = new csml.StateMachine { + transient { + ["waitingCustomers"] = "[...]" + ["barberStatus"] = "''" + ["doneCounter"] = "0" } states { - new { - name = "process" - initial = true - entry { - new Csml.RaiseActionDescription { - event { - name = "ready" - channel = "global" - } + ["init"] = new csml.Initial { + always { + new csml.Transition { + to = "process" + do { new csml.Raise { event = new csml.Global { topic = "ready" } } } } } + } + ["process"] = new csml.State { on { - new { - event = "customerEnter" - guards { - new { - expression = "waitingCustomers.size() == 3" - } - } - actions { - new Csml.RaiseActionDescription { - event { - name = "full" - data { - new { - name = "customer" - value = "$customer" - } - } - channel = "global" - } - } - } + ["customerEnter"] = new csml.Transition { + to = "process" + iif = "waitingCustomers.size() == 3" + do { new csml.Raise { event = new csml.Global { topic = "full" }; target = "$customer" } } + or = "evaluateWaitingRoom" } - new { - event = "customerEnter" - guards { - new { - expression = "waitingCustomers.isEmpty()" - } - new { - expression = "barberStatus == 'sleeping'" - } - } - actions { - new Csml.RaiseActionDescription { - event { - name = "enter" - data { - new { - name = "customer" - value = "$customer" - } - } - channel = "global" + ["getNext"] = new csml.Transition { + iif = "!waitingCustomers.isEmpty()" + do { + new csml.Raise { + event = new csml.Global { + topic = "enter" + data { ["customer"] = "waitingCustomers.get(0)" } } + target = "'barber'" } - new Csml.AssignActionDescription { - variable = new { - name = "barberStatus" - value = "'busy'" - } + new csml.Eval { + expression = "waitingCustomers = waitingCustomers - [waitingCustomers.get(0)]" } + new csml.Eval { expression = "barberStatus = 'busy'" } } } - new { - event = "customerEnter" - guards { - new { - expression = "waitingCustomers.isEmpty()" - } - new Csml.GuardDescription { - expression = "barberStatus == 'busy'" - } - } - actions { - new Csml.AssignActionDescription { - variable = new { - name = "waitingCustomers" - value = "utility:addToList(\("waitingCustomers"), $customer)" - } - } - new Csml.RaiseActionDescription { - event { - name = "waiting" - data { - new { - name = "customer" - value = "$customer" - } - } - channel = "global" - } - } - } + ["statusSleeping"] = new csml.Transition { + do { new csml.Eval { expression = "barberStatus = 'sleeping'" } } } - new { - event = "customerEnter" - guards { - new { - expression = "waitingCustomers.size() != 3" - } - new { - expression = "!waitingCustomers.isEmpty()" - } - } - actions { - new Csml.AssignActionDescription { - variable = new { - name = "waitingCustomers" - value = "utility:addToList(\("waitingCustomers"), $customer)" - } - } - new Csml.RaiseActionDescription { - event { - name = "waiting" - data { - new { - name = "customer" - value = "$customer" - } - } - channel = "global" - } - } - } + ["doneCutting"] = new csml.Transition { + to = "process" + iif = "doneCounter < 15" + do { new csml.Eval { expression = "++doneCounter" } } + or = "terminate" } - new { - event = "getNext" - guards { - new { - expression = "!waitingCustomers.isEmpty()" - } - } - actions { - new Csml.RaiseActionDescription { - event { - name = "enter" - data { - new { - name = "customer" - value = "waitingCustomers.get(0)" - } - } - channel = "global" - } - } - new Csml.AssignActionDescription { - variable = new { - name = "waitingCustomers" - value = "utility:removeFirst(\("waitingCustomers"))" - } - } - new Csml.AssignActionDescription { - variable = new { - name = "barberStatus" - value = "'busy'" - } - } + } + } + ["evaluateWaitingRoom"] = new csml.State { + always { + new csml.Transition { + to = "evaluateBarberStatus" + iif = "waitingCustomers.isEmpty()" + or = "addToWaitingRoom" + } + } + } + ["evaluateBarberStatus"] = new csml.State { + always { + new csml.Transition { + to = "process" + iif = "barberStatus == 'sleeping'" + do { + new csml.Raise { + event = new csml.Global { topic = "enter"; data { ["customer"] = "$customer" } } + target = "'barber'" + } + new csml.Eval { expression = "barberStatus = 'busy'" } } + or = "addToWaitingRoom" } - new { - event = "statusSleeping" - actions { - new Csml.AssignActionDescription { - variable = new { - name = "barberStatus" - value = "'sleeping'" - } - } + } + } + ["addToWaitingRoom"] = new csml.State { + always { + new csml.Transition { + to = "process" + do { + new csml.Eval { expression = "waitingCustomers = waitingCustomers + [$customer]" } + new csml.Raise { event = new csml.Global { topic = "waiting" }; target = "$customer" } } } } } + ["terminate"] = new csml.Terminal { + entry { new csml.Raise { event = new csml.Global { topic = "terminate" } } } + } } }