The Models are the Code Executable UML Lecture
The Models are the Code Executable UML Lecture 9 - Communication and Relationship Dynamics Paul Krause Executable UML
Lecture 9 - Communication and Relationship Dynamics v Parameter passing using signals v Synchronous creation and deletion of objects v Class-based state machines Executable UML
Signals v The dynamics of a domain are established by the exchange of signals between state machine instances v Signals may contain data v The data in a signal may be used by the entry actions in the recipient state machine v Signalling is asynchronous v the sending machine carries on with its business v the receiving state machine may execute a transition, and may choose to send another signal, but it does not “return” to the sender. Executable UML
Signal exchange between objects Shipment 0. . 1 R 9 is included in includes 1. . * shipment. ID tracking. Number recipient … Product. Selection 0. . 1 is sent to customer as R 6 1 Book Executable UML R 4 1. . * 0. . * contains customer is selections of purchased on Order delivers contents of
Signal exchange between objects Shipment state machine Delivered to Customer entry/ self. time. Delivered = rcvd_evt. reported. Delivery. Time // signal that the order has been delivered // signal the order has been delivered select onethat order related by self -> Order[R 6] select one order related by self -> Order[R 6] generate order. Delivered to order. Delivered Order state machine // notify the Customer that we think Being Packed and Shipped // the order has been delivered Delivered to Customer select one customer related entry/ by self ->Customer[R 5] order. Delivered // Notify customer that the charge order. Reported. Delivered( // notify the Customer that we think generate // was approved and the order will // the order has been delivered customer. Email: customer. email) to EE_Online_Customer // be shipped select one customer related by self ->Customer[R 5] // create a Shipment for the order Executable UML generate order. Reported. Delivered( customer. Email: customer. email) to EE_Online_Customer
Event parameters v We may wish to pass items of data as parameters to events v The collection of event parameters can be viewed as an object v By convention, this object is denoted: rcvd_evt v The entry actions may then access the values of the parameters by referring to rcvd_evt v Rule: v all events that cause a transition into a particular state must carry the same parameters Executable UML
Passing event parameters check. Out(account. Number, billing. Address, card. Expiration. Date, card. Holder. Name, customer. Email, customer. Name, customer. Phone, shipping. Address) Establishing Customer and Verifying Payment entry/ // Create a customer if one does not already // exist with the given e-mail address select any customer from instances of Customer where selected. email == rcvd. evt. customer. Email; if empty customer create object instance customer of Customer; customer. email = rcvd_evt. customer. Email; end if; // use the name, address etc to update the customer // whether new or existing customer. name = rcvd_evt. customer. Name; customer. shipping. Address = rcvd_evt. shipping. Address; customer. phone = rcvd_evt. customer. Phone; // Link the order to the customer relate self to customer across R 5; Executable UML
Passing event parameters Establishing Customer and Verifying Payment check. Out(account. Number, billing. Address, card. Expiration. Date, entry/ a customer if one does not already card. Holder. Name, customer. Email, ////Create a customer if one does not already ////exist with given exist with thethe given e-mail address customer. Name, customer. Phone, select any from instances of Customer select anycustomer instances of Customer shipping. Address) where selected. email == rcvd. evt. customer. Email; if empty customer create object instance customer of Customer; customer. email rcvd_evt. customer. Email; create object=instance customer of Customer; end if; customer. email = rcvd_evt. customer. Email; end if; // use the name, address etc to update the customer // whether new or existing customer. name = rcvd_evt. customer. Name; customer. shipping. Address = rcvd_evt. shipping. Address; customer. phone = rcvd_evt. customer. Phone; // Link the order to the customer relate self to customer across R 5; Executable UML
Passing event parameters check. Out(account. Number, billing. Address, card. Expiration. Date, card. Holder. Name, customer. Email, customer. Name, customer. Phone, shipping. Address) Establishing Customer and Verifying Payment entry/ // Create a customer if one does not already // exist with the given e-mail address select any customer from instances of Customer where selected. email == rcvd. evt. customer. Email; if empty customer create object instance customer of Customer; customer. email = rcvd_evt. customer. Email; if; name, end address etc to update the customer // use the // whether new or existing // use the name, address etc to update the customer. name//=whether rcvd_evt. customer. Name; new or existing customer. shipping. Address customer. name== rcvd_evt. shipping. Address; rcvd_evt. customer. Name; = rcvd_evt. shipping. Address; customer. phonecustomer. shipping. Address = rcvd_evt. customer. Phone; customer. phone = rcvd_evt. customer. Phone; // Link the order to the customer relate self to customer across R 5; Executable UML
Passing event parameters check. Out(account. Number, billing. Address, card. Expiration. Date, card. Holder. Name, customer. Email, customer. Name, customer. Phone, shipping. Address) Establishing Customer and Verifying Payment entry/ // Create a customer if one does not already // exist with the given e-mail address select any customer from instances of Customer where selected. email == rcvd. evt. customer. Email; if empty customer create object instance customer of Customer; customer. email = rcvd_evt. customer. Email; end if; // use the name, address etc to update the customer // whether new or existing customer. name = rcvd_evt. customer. Name; customer. shipping. Address = rcvd_evt. shipping. Address; customer. phone = rcvd_evt. customer. Phone; // Link the order to the customer // Linkself the order to the customer relate to customer across R 5; relate self to customer across R 5; Executable UML
Signals and events v A signal is an asynchronous message v An “event” is the receipt of a signal by some state machine v strictly, a signal event v When a signal is generated, its parameters are instantiated using name-value pairs v e. g. v generate add. Selection( product. ID: rcvd_evt. product. ID, quantity: rcvd_evt. quantity) to order; Executable UML
Signals to self New Order entry/ // Add the first selection to the order generate add. Selection( product. ID: rcvd_evt. product. ID, quantity: rcvd_evt. quantity) to self; generated and sent to self received and acted on. add. Selection(product. ID, quantity) Signals from self are always acted on before any other outstanding Adding Selection to Order signals entry/ // Add the (next) selection to the order … Executable UML
Creation and deletion of objects v Actions can synchronously create or delete instances of objects without state machines within a procedure v Instances with state machines can be created or deleted asynchronously by sending them signals v Synchronous creation and deletion of objects with state machines is also possible v see Mellor and Balcer section 10. 2. 2 Executable UML
Synchronous creation and deletion of objects Order state machine add. Selection (product. ID, quantity) Adding Selection to Order entry/ // Add the (next) selection to the order create object instance new. Selection of Product. Selection; select any book from instances of Product where selected. Product. ID == rcvd_evt. book. Number; relate book to self across R 4 using new. Selection; … check. Out(…) Executable UML cancel
Synchronous creation and deletion of objects Order state machine add. Selection (product. ID, quantity) Adding Selection to Order entry/ // Add the (next) selection to the order create object instance new. Selection of Product. Selection; select any book from instances of Product where selected. Product. ID == rcvd_evt. book. Number; relate book to self across R 4 using new. Selection; … check. Out(…) Executable UML cancel
Synchronous creation and deletion of objects Order state machine add. Selection (product. ID, quantity) Adding Selection to Order entry/ // Add the (next) selection to the order create object instance new. Selection of Product. Selection; select any book from instances of Product where selected. Product. ID == rcvd_evt. book. Number; relate book to self across R 4 using new. Selection; … check. Out(…) Executable UML cancel
Synchronous creation and deletion of objects Order state machine add. Selection (product. ID, quantity) Adding Selection to Order entry/ // Add the (next) selection to the order create object instance new. Selection of Product. Selection; select any book from instances of Product where selected. Product. ID == rcvd_evt. book. Number; relate book to self across R 4 using new. Selection; new. Selection. quantity = rcvd_evt. quantity; check. Out(…) Executable UML cancel
Synchronous creation and deletion of objects Cancelling Entire Order cancel entry/ // Delete all the selections of the Order select many selections related by self -> Product. Selection[R 4]; for each selection in selections select one product related by selection ->Product[R 4]; unrelate self from product across R 4 using selection; end for; destroying the association will destroy the respective instance of the association class Executable UML
Competition in associations Shipment shipment. ID tracking. Number recipient … Executable UML Shipping. Clerk awaiting. Assignment R 23 0. . 1 is currently packing being packed by
(Partial) State machine for shipping clerk 1: Clerk Idle entry/ select one current. Shipment related by self -> Shipment[R 23]; … shipment. Ready 2; Selecting Books entry/ … Executable UML
Two idle clerks… A: Shipping clerk 6 select shipment : Shipment B: Shipping clerk 1 6 select shipment 1 1 both clerks try to grab the same shipment 2 Executable UML 2
Use of an assigner state machine v Usually this will be a class-based state machine v Has only one instance v The assigner is a single point of control for resolving resource contention v This is in addition to any object-based state machine Executable UML
Shipping Clerk Assigner 1: Waiting for Shipment entry/ select any ready. Shipment from instances of Shipment where selected. waiting. To. Be. Packed; if not empty ready. Shipment generate shipment. Ready. To. Pack to self; end if; shipment. Ready. To. Pack 2: Waiting for a Free Clerk entry/ select any free. Clerk from instances of Shipping. Clerk where selected. idle; if not empty free. Clerk generate clerk. Free to self; end if; Executable UML clerk. Assigned. To. Shipment 3: Assigning Clerk to Shipment entry/ select any ready. Shipment from instances of Shipment where selected. waiting. To. Be. Packed; select any free. Clerk from instances of Shipping. Clerk where selected. idle; relate free. Clerk to ready. Shipment across R 23; ready. Shipment. waiting. To. Be. Packed = false; free. Clerk. idle = false; generate clerk. Assigned to free. Clerk; generate clerk. Assigned. To. Shipment to self; clerk. Free
Shipping Clerk Assigner 1: Waiting for Shipment clerk. Assigned. To. Shipment entry/ select any ready. Shipment from instances of Shipment where selected. waiting. To. Be. Packed; if not empty ready. Shipment 3: Assigning Clerk to Shipment generate shipment. Ready. To. Pack to self; entry/ end if; select any ready. Shipment from instances of Shipment shipment. Ready. To. Pack 2: Waiting for a Free Clerk entry/ select any free. Clerk from instances of Shipping. Clerk where selected. idle; if not empty free. Clerk generate clerk. Free to self; end if; Executable UML where selected. waiting. To. Be. Packed; select any free. Clerk from instances of Shipping. Clerk where selected. idle; relate free. Clerk to ready. Shipment across R 23; ready. Shipment. waiting. To. Be. Packed = false; free. Clerk. idle = false; generate clerk. Assigned to free. Clerk; generate clerk. Assigned. To. Shipment to self; clerk. Free
Shipping Clerk Assigner 1: Waiting for Shipment entry/ select any ready. Shipment from instances of Shipment where selected. waiting. To. Be. Packed; if not empty ready. Shipment generate shipment. Ready. To. Pack to self; end if; shipment. Ready. To. Pack 2: Waiting for a Free Clerk clerk. Assigned. To. Shipment 3: Assigning Clerk to Shipment entry/ select any ready. Shipment from instances of Shipment where selected. waiting. To. Be. Packed; select any free. Clerk from instances of Shipping. Clerk where selected. idle; relate free. Clerk to ready. Shipment across R 23; ready. Shipment. waiting. To. Be. Packed = false; free. Clerk. idle = false; generate clerk. Assigned to free. Clerk; generate clerk. Assigned. To. Shipment to self; entry/ select any free. Clerk from instances of Shipping. Clerk where selected. idle; if not empty free. Clerk generate clerk. Free to self; end if; Executable UML clerk. Free
Shipping Clerk Assigner 1: Waiting for Shipment entry/ select any ready. Shipment from instances of Shipment where selected. waiting. To. Be. Packed; if not empty ready. Shipment generate shipment. Ready. To. Pack to self; end if; shipment. Ready. To. Pack 2: Waiting for a Free Clerk entry/ select any free. Clerk from instances of Shipping. Clerk where selected. idle; if not empty free. Clerk generate clerk. Free to self; end if; Executable UML clerk. Assigned. To. Shipment 3: Assigning Clerk to Shipment entry/ select any ready. Shipment from instances of Shipment where selected. waiting. To. Be. Packed; select any free. Clerk from instances of Shipping. Clerk where selected. idle; relate free. Clerk to ready. Shipment across R 23; ready. Shipment. waiting. To. Be. Packed = false; clerk. Free free. Clerk. idle = false; generate clerk. Assigned to free. Clerk; generate clerk. Assigned. To. Shipment to self;
Summary v Parameters can be passed between state machines using signals v We have explored some aspects of v Synchronous creation and deletion of objects v Asynchronous creation and deletion of objects v We have also seen how class-based state machines can be used to handle resource contention v See Chapters 10 -13 of Mellor and Balcer Executable UML
- Slides: 27