diff --git a/sleepingBarber/barber.pkl b/sleepingBarber/barber.pkl new file mode 100644 index 0000000..3282012 --- /dev/null +++ b/sleepingBarber/barber.pkl @@ -0,0 +1,59 @@ +import + "https://raw.githubusercontent.com/CollaborativeStateMachines/Cirrina/refs/heads/develop/src/main/resources/pkl/csm/Csml.pkl" + +class StateMachine extends Csml.StateMachineDescription { + name = "barber" + states { + new { + name = "sleeping" + initial = true + entry { + new Csml.RaiseActionDescription { + event { + name = "statusSleeping" + channel = "global" + } + } + } + on { + new { + event = "enter" + target = "cutting" + } + } + } + new { + name = "cutting" + 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" + } + } + } + target = "sleeping" + } + } + } + } +} diff --git a/sleepingBarber/customer.pkl b/sleepingBarber/customer.pkl new file mode 100644 index 0000000..2d99b51 --- /dev/null +++ b/sleepingBarber/customer.pkl @@ -0,0 +1,127 @@ +import "https://raw.githubusercontent.com/CollaborativeStateMachines/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" + } + } + } + states { + new { + name = "init" + initial = true + on { + new { + event = "ready" + target = "requestHaircut" + } + } + } + new { + name = "requestHaircut" + entry { + new Csml.RaiseActionDescription { + event { + name = "customerEnter" + data { + new { + name = "customer" + value = self.name + } + } + channel = "global" + } + } + } + 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" + } + } + } + new { + name = "gettingHaircut" + entry { + new Csml.AssignActionDescription { + variable = new { + name = "counter" + value = "counter + 1" + } + } + } + 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" + } + } + } + new { + name = "waiting" + on { + new { + event = "enter" + guards { + new { + expression = "$customer == \(self.name)" + } + } + target = "gettingHaircut" + } + } + } + new { + name = "leave" + terminal = true + } + } +} diff --git a/sleepingBarber/defs.pkl b/sleepingBarber/defs.pkl new file mode 100644 index 0000000..27526ab --- /dev/null +++ b/sleepingBarber/defs.pkl @@ -0,0 +1 @@ +customers = List("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15") diff --git a/sleepingBarber/main.pkl b/sleepingBarber/main.pkl new file mode 100644 index 0000000..86655d0 --- /dev/null +++ b/sleepingBarber/main.pkl @@ -0,0 +1,16 @@ +amends "https://raw.githubusercontent.com/CollaborativeStateMachines/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 } + } + new waitingRoom.StateMachine {} +} diff --git a/sleepingBarber/services.pkl b/sleepingBarber/services.pkl new file mode 100644 index 0000000..48fc97f --- /dev/null +++ b/sleepingBarber/services.pkl @@ -0,0 +1,3 @@ +amends "https://raw.githubusercontent.com/CollaborativeStateMachines/Cirrina/refs/heads/develop/src/main/resources/pkl/csm/ServiceImplementationBindings.pkl" + +bindings {} diff --git a/sleepingBarber/waitingRoom.pkl b/sleepingBarber/waitingRoom.pkl new file mode 100644 index 0000000..94f49ba --- /dev/null +++ b/sleepingBarber/waitingRoom.pkl @@ -0,0 +1,193 @@ +import "https://raw.githubusercontent.com/CollaborativeStateMachines/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 = "''" + } + } + } + states { + new { + name = "process" + initial = true + entry { + new Csml.RaiseActionDescription { + event { + name = "ready" + channel = "global" + } + } + } + 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" + } + } + } + } + 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" + } + } + new Csml.AssignActionDescription { + variable = new { + name = "barberStatus" + value = "'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" + } + } + } + } + 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" + } + } + } + } + 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'" + } + } + } + } + new { + event = "statusSleeping" + actions { + new Csml.AssignActionDescription { + variable = new { + name = "barberStatus" + value = "'sleeping'" + } + } + } + } + } + } + } +}