// Independent worked listings. Load this chapter with vocabulary.sysml, not with other chapters. package Lch07_01 { private import CoffeeVocabulary::*; // ANCHOR: listing-1 action def GrindBeans; // ANCHOR_END: listing-1 } package Lch07_02 { private import CoffeeVocabulary::*; // ANCHOR: listing-2 action def GrindBeans; action def HeatWater; action def BrewCycle { action grind : GrindBeans; action heat : HeatWater; } // ANCHOR_END: listing-2 } package Lch07_03 { private import CoffeeVocabulary::*; // ANCHOR: listing-3 action def BrewCycle { action grind : GrindBeans; action heat : HeatWater; first grind then heat; } // ANCHOR_END: listing-3 } package Lch07_04 { private import CoffeeVocabulary::*; // ANCHOR: listing-4 action def BrewCycle { action grind : GrindBeans; action heat : HeatWater; action extract : ExtractCoffee; action dispense : DispenseCoffee; first grind then heat; first heat then extract; first extract then dispense; } // ANCHOR_END: listing-4 } package Lch07_05 { private import CoffeeVocabulary::*; // ANCHOR: listing-5 action def BrewCycle { action grind : GrindBeans; action heat : HeatWater; action extract : ExtractCoffee; action dispense : DispenseCoffee; first start then grind; first grind then heat; first heat then extract; first extract then dispense; first dispense then done; } // ANCHOR_END: listing-5 } package Lch07_06 { private import CoffeeVocabulary::*; // ANCHOR: listing-6 action def BrewCycle { action grind : GrindBeans; then action heat : HeatWater; then action extract : ExtractCoffee; then action dispense : DispenseCoffee; } // ANCHOR_END: listing-6 } package Lch07_07 { private import CoffeeVocabulary::*; // ANCHOR: listing-7 action def BrewCycle { action grind : GrindBeans; action heat : HeatWater; action extract : Extract; succession grindDone first grind then heat; succession first heat then extract; } // ANCHOR_END: listing-7 } package Lch07_08 { private import CoffeeVocabulary::*; // ANCHOR: listing-8 action def GrindBeans { in item beans : CoffeeBeans; out item grounds : GroundCoffee; } // ANCHOR_END: listing-8 } package Lch07_09 { private import CoffeeVocabulary::*; // ANCHOR: listing-9 action def GrindBeans { in item beans : CoffeeBeans; out item grounds : GroundCoffee; } action def ExtractCoffee { in item grounds : GroundCoffee; in item water : HotWater; out item coffee : BrewedCoffee; } // ANCHOR_END: listing-9 } package Lch07_10 { private import CoffeeVocabulary::*; // ANCHOR: listing-10 action def BrewCycle { action grind : GrindBeans; action heat : HeatWater; action extract : ExtractCoffee; action dispense : DispenseCoffee; fork forkNode; first start then forkNode; first forkNode then grind; first forkNode then heat; join joinNode; first grind then joinNode; first heat then joinNode; first joinNode then extract; first extract then dispense; first dispense then done; } // ANCHOR_END: listing-10 } package Lch07_11 { private import CoffeeVocabulary::*; private import ScalarValues::Boolean; // ANCHOR: listing-11 action def BrewCycle { in attribute espressoMode : Boolean; action grind : GrindBeans; action heat : HeatWater; action espressoExtract : ExtractEspresso; action dripExtract : ExtractDrip; action dispense : DispenseCoffee; first start then grind; first grind then heat; decide decideMethod; first heat then decideMethod; first decideMethod if espressoMode then espressoExtract; first decideMethod if not espressoMode then dripExtract; merge mergeMethod; first espressoExtract then mergeMethod; first dripExtract then mergeMethod; first mergeMethod then dispense; first dispense then done; } // ANCHOR_END: listing-11 } package Lch07_12 { private import CoffeeVocabulary::*; private import ScalarValues::Boolean; // ANCHOR: listing-12 package CoffeeMachineActions { private import ScalarValues::*; private import CoffeeMachineDomain::*; action def GrindBeans { in item beans : CoffeeBeans; } action def HeatWater { in item water : Water; } action def ExtractEspresso; action def ExtractDrip; action def DispenseCoffee { out item coffee : BrewedCoffee; } action def BrewCycle { in attribute espressoMode : Boolean; in item beans : CoffeeBeans; in item water : Water; out item coffee : BrewedCoffee; action grind : GrindBeans { in item :>> beans = BrewCycle::beans; } action heat : HeatWater { in item :>> water = BrewCycle::water; } action espressoExtract : ExtractEspresso; action dripExtract : ExtractDrip; action dispense : DispenseCoffee { out item :>> coffee = BrewCycle::coffee; } // Grind and heat in parallel fork forkPrep; first start then forkPrep; first forkPrep then grind; first forkPrep then heat; join joinPrep; first grind then joinPrep; first heat then joinPrep; // Choose extraction method decide decideMethod; first joinPrep then decideMethod; first decideMethod if espressoMode then espressoExtract; first decideMethod if not espressoMode then dripExtract; merge mergeMethod; first espressoExtract then mergeMethod; first dripExtract then mergeMethod; // Dispense and finish first mergeMethod then dispense; first dispense then done; } } // ANCHOR_END: listing-12 } package Lch07_13 { private import CoffeeVocabulary::*; // ANCHOR: listing-13 action def NotifyReady { part display : Panel; send new BrewComplete() to display; } // ANCHOR_END: listing-13 } package Lch07_14 { private import CoffeeVocabulary::*; // ANCHOR: listing-14 action def WaitForBrew { accept brewDone : BrewComplete; } // ANCHOR_END: listing-14 } package Lch07_15 { private import CoffeeVocabulary::*; // ANCHOR: listing-15 action def ServeCustomer { part customerDisplay : Panel; accept orderReceived : BrewRequest; then action brew : BrewCycle; then action notify send new BrewComplete() to customerDisplay; } // ANCHOR_END: listing-15 } package Lch07_16 { private import CoffeeVocabulary::*; // ANCHOR: listing-16 action def RouteSignalThroughPort { port communicationPort : CommunicationPort; send new LowWaterSignal() via communicationPort; } // ANCHOR_END: listing-16 } package Lch07_17 { private import CoffeeVocabulary::*; // ANCHOR: listing-17 action def RouteAcceptThroughPort { port communicationPort : CommunicationPort; accept alert : FaultSignal via communicationPort; } // ANCHOR_END: listing-17 } package Lch07_18 { private import CoffeeVocabulary::*; // ANCHOR: listing-18 part def CoffeeMachine { part grinder : Grinder; part brewer : Brewer; part waterTank : WaterTank; perform action brewCycle : BrewCycle; } // ANCHOR_END: listing-18 } package Lch07_19 { private import CoffeeVocabulary::*; private import ScalarValues::Integer; // ANCHOR: listing-19 action def BrewCycle { inout attribute brewCycles : Integer; assign brewCycles := brewCycles + 1; } // ANCHOR_END: listing-19 } package Lch07_20 { private import CoffeeVocabulary::*; private import ScalarValues::Boolean; // ANCHOR: listing-20 action def ToggleMode { inout attribute espressoMode : Boolean; } // ANCHOR_END: listing-20 } package Lch07_21 { private import CoffeeVocabulary::*; private import ScalarValues::Real; // ANCHOR: listing-21 action def HeatAndStir { in attribute targetTemp : Real; inout attribute currentTemp : Real; while currentTemp < targetTemp { action stir : Stir; assign currentTemp := currentTemp + 1.0; } } // ANCHOR_END: listing-21 } package Lch07_22 { private import CoffeeVocabulary::*; private import ScalarValues::Integer; // ANCHOR: listing-22 action def FulfillRequest { in item order : BrewRequest; } action def ProcessBrewQueue { in item brewRequests : BrewRequest[0..*]; out attribute successCount : Integer; assign successCount := 0; for request : BrewRequest in brewRequests { action brew : FulfillRequest { in item :>> order = request; } assign successCount := successCount + 1; } } // ANCHOR_END: listing-22 } package Lch07_23 { private import CoffeeVocabulary::*; private import ScalarValues::Real; // ANCHOR: listing-23 action def BrewCycle { port panelPort : CommunicationPort; in attribute temperature : Real; if temperature > 105.0 { send new FaultSignal() via panelPort; terminate; } then action extract : ExtractCoffee; } // ANCHOR_END: listing-23 }