Presentation is loading. Please wait.

Presentation is loading. Please wait.

Executable UML The Models are the Code - Executable UML Lecture 9 - Communication and Relationship Dynamics Paul Krause.

Similar presentations


Presentation on theme: "Executable UML The Models are the Code - Executable UML Lecture 9 - Communication and Relationship Dynamics Paul Krause."— Presentation transcript:

1 Executable UML The Models are the Code - Executable UML Lecture 9 - Communication and Relationship Dynamics Paul Krause

2 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

3 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  the sending machine carries on with its business  the receiving state machine may execute a transition, and may choose to send another signal, but it does not “return” to the sender.

4 Executable UML Signal exchange between objects Shipment shipmentID trackingNumber recipient … OrderProductSelectionBook R9 R6 R4 0..1 is included in includes 1..* 0..1 is sent to customer as 1 delivers contents of 1..* contains customer selections of 1..* contains customer selections of 0..* is purchased on

5 Executable UML Signal exchange between objects Delivered to Customer entry/ self.timeDelivered = rcvd_evt.reportedDeliveryTime // signal that the order has been delivered select one order related by self -> Order[R6] generate orderDelivered to order Being Packed and Shipped entry/ // Notify customer that the charge // was approved and the order will // be shipped // create a Shipment for the order Delivered to Customer entry/ // notify the Customer that we think // the order has been delivered select one customer related by self ->Customer[R5] generate orderReportedDelivered( customerEmail:customer.email) to EE_Online_Customer orderDelivered // signal that the order has been delivered select one order related by self -> Order[R6] generate orderDelivered to order Shipment state machine Order state machine // notify the Customer that we think // the order has been delivered select one customer related by self ->Customer[R5] generate orderReportedDelivered( customerEmail:customer.email) to EE_Online_Customer orderDelivered

6 Executable UML 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:  all events that cause a transition into a particular state must carry the same parameters

7 Executable UML Passing event parameters 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.customerEmail; if empty customer create object instance customer of Customer; customer.email = rcvd_evt.customerEmail; end if; // use the name, address etc to update the customer // whether new or existing customer.name = rcvd_evt.customerName; customer.shippingAddress = rcvd_evt.shippingAddress; customer.phone = rcvd_evt.customerPhone; // Link the order to the customer relate self to customer across R5; checkOut(accountNumber, billingAddress, cardExpirationDate, cardHolderName, customerEmail, customerName, customerPhone, shippingAddress)

8 Executable UML Passing event parameters 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.customerEmail; if empty customer create object instance customer of Customer; customer.email = rcvd_evt.customerEmail; end if; // use the name, address etc to update the customer // whether new or existing customer.name = rcvd_evt.customerName; customer.shippingAddress = rcvd_evt.shippingAddress; customer.phone = rcvd_evt.customerPhone; // Link the order to the customer relate self to customer across R5; checkOut(accountNumber, billingAddress, cardExpirationDate, cardHolderName, customerEmail, customerName, customerPhone, shippingAddress) // 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.customerEmail; if empty customer create object instance customer of Customer; customer.email = rcvd_evt.customerEmail; end if;

9 Executable UML Passing event parameters 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.customerEmail; if empty customer create object instance customer of Customer; customer.email = rcvd_evt.customerEmail; end if; // use the name, address etc to update the customer // whether new or existing customer.name = rcvd_evt.customerName; customer.shippingAddress = rcvd_evt.shippingAddress; customer.phone = rcvd_evt.customerPhone; // Link the order to the customer relate self to customer across R5; checkOut(accountNumber, billingAddress, cardExpirationDate, cardHolderName, customerEmail, customerName, customerPhone, shippingAddress) // use the name, address etc to update the customer // whether new or existing customer.name = rcvd_evt.customerName; customer.shippingAddress = rcvd_evt.shippingAddress; customer.phone = rcvd_evt.customerPhone;

10 Executable UML Passing event parameters 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.customerEmail; if empty customer create object instance customer of Customer; customer.email = rcvd_evt.customerEmail; end if; // use the name, address etc to update the customer // whether new or existing customer.name = rcvd_evt.customerName; customer.shippingAddress = rcvd_evt.shippingAddress; customer.phone = rcvd_evt.customerPhone; // Link the order to the customer relate self to customer across R5; checkOut(accountNumber, billingAddress, cardExpirationDate, cardHolderName, customerEmail, customerName, customerPhone, shippingAddress) // Link the order to the customer relate self to customer across R5;

11 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  strictly, a signal event v When a signal is generated, its parameters are instantiated using name-value pairs v e.g.  generate addSelection( productID: rcvd_evt.productID, quantity: rcvd_evt.quantity) to order;

12 Executable UML Signals to self New Order entry/ // Add the first selection to the order generate addSelection( productID: rcvd_evt.productID, quantity: rcvd_evt.quantity) to self; Adding Selection to Order entry/ // Add the (next) selection to the order … addSelection(productID, quantity) generated and sent to self received and acted on. Signals from self are always acted on before any other outstanding signals

13 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  see Mellor and Balcer section 10.2.2

14 Executable UML Synchronous creation and deletion of objects Order state machine Adding Selection to Order entry/ // Add the (next) selection to the order create object instance newSelection of ProductSelection; select any book from instances of Product where selected.ProductID == rcvd_evt.bookNumber; relate book to self across R4 using newSelection; … addSelection (productID, quantity) addSelection (productID, quantity) cancel checkOut(…)

15 Executable UML Synchronous creation and deletion of objects Order state machine Adding Selection to Order entry/ // Add the (next) selection to the order create object instance newSelection of ProductSelection; select any book from instances of Product where selected.ProductID == rcvd_evt.bookNumber; relate book to self across R4 using newSelection; … addSelection (productID, quantity) addSelection (productID, quantity) cancel checkOut(…)

16 Executable UML Synchronous creation and deletion of objects Order state machine Adding Selection to Order entry/ // Add the (next) selection to the order create object instance newSelection of ProductSelection; select any book from instances of Product where selected.ProductID == rcvd_evt.bookNumber; relate book to self across R4 using newSelection; … addSelection (productID, quantity) addSelection (productID, quantity) cancel checkOut(…)

17 Executable UML Synchronous creation and deletion of objects Order state machine Adding Selection to Order entry/ // Add the (next) selection to the order create object instance newSelection of ProductSelection; select any book from instances of Product where selected.ProductID == rcvd_evt.bookNumber; relate book to self across R4 using newSelection; newSelection.quantity = rcvd_evt.quantity; addSelection (productID, quantity) addSelection (productID, quantity) cancel checkOut(…)

18 Executable UML Synchronous creation and deletion of objects Cancelling Entire Order entry/ // Delete all the selections of the Order select many selections related by self -> ProductSelection[R4]; for each selection in selections select one product related by selection ->Product[R4]; unrelate self from product across R4 using selection; end for; cancel destroying the association will destroy the respective instance of the association class

19 Executable UML Competition in associations Shipment shipmentID trackingNumber recipient … ShippingClerk awaitingAssignment 0..1 is currently packing 0..1 is currently being packed by R23

20 Executable UML (Partial) State machine for shipping clerk 1: Clerk Idle entry/ select one currentShipment related by self -> Shipment[R23]; … 2; Selecting Books entry/ … shipmentReady

21 Executable UML Two idle clerks… A: Shipping clerkB: Shipping clerk:Shipment 6 1 2 1 6 1 2 select shipment both clerks try to grab the same shipment

22 Executable UML 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

23 Executable UML Shipping Clerk Assigner 1: Waiting for Shipment entry/ select any readyShipment from instances of Shipment where selected.waitingToBePacked; if not empty readyShipment generate shipmentReadyToPack to self; end if; 2: Waiting for a Free Clerk entry/ select any freeClerk from instances of ShippingClerk where selected.idle; if not empty freeClerk generate clerkFree to self; end if; 3: Assigning Clerk to Shipment entry/ select any readyShipment from instances of Shipment where selected.waitingToBePacked; select any freeClerk from instances of ShippingClerk where selected.idle; relate freeClerk to readyShipment across R23; readyShipment.waitingToBePacked = false; freeClerk.idle = false; generate clerkAssigned to freeClerk; generate clerkAssignedToShipment to self; shipmentReadyToPack clerkFree clerkAssignedToShipment

24 Executable UML Shipping Clerk Assigner 2: Waiting for a Free Clerk entry/ select any freeClerk from instances of ShippingClerk where selected.idle; if not empty freeClerk generate clerkFree to self; end if; 3: Assigning Clerk to Shipment entry/ select any readyShipment from instances of Shipment where selected.waitingToBePacked; select any freeClerk from instances of ShippingClerk where selected.idle; relate freeClerk to readyShipment across R23; readyShipment.waitingToBePacked = false; freeClerk.idle = false; generate clerkAssigned to freeClerk; generate clerkAssignedToShipment to self; shipmentReadyToPack clerkFree clerkAssignedToShipment 1: Waiting for Shipment entry/ select any readyShipment from instances of Shipment where selected.waitingToBePacked; if not empty readyShipment generate shipmentReadyToPack to self; end if;

25 Executable UML Shipping Clerk Assigner 1: Waiting for Shipment entry/ select any readyShipment from instances of Shipment where selected.waitingToBePacked; if not empty readyShipment generate shipmentReadyToPack to self; end if; 3: Assigning Clerk to Shipment entry/ select any readyShipment from instances of Shipment where selected.waitingToBePacked; select any freeClerk from instances of ShippingClerk where selected.idle; relate freeClerk to readyShipment across R23; readyShipment.waitingToBePacked = false; freeClerk.idle = false; generate clerkAssigned to freeClerk; generate clerkAssignedToShipment to self; shipmentReadyToPack clerkFree clerkAssignedToShipment 2: Waiting for a Free Clerk entry/ select any freeClerk from instances of ShippingClerk where selected.idle; if not empty freeClerk generate clerkFree to self; end if;

26 Executable UML Shipping Clerk Assigner 1: Waiting for Shipment entry/ select any readyShipment from instances of Shipment where selected.waitingToBePacked; if not empty readyShipment generate shipmentReadyToPack to self; end if; 2: Waiting for a Free Clerk entry/ select any freeClerk from instances of ShippingClerk where selected.idle; if not empty freeClerk generate clerkFree to self; end if; shipmentReadyToPack clerkFree clerkAssignedToShipment 3: Assigning Clerk to Shipment entry/ select any readyShipment from instances of Shipment where selected.waitingToBePacked; select any freeClerk from instances of ShippingClerk where selected.idle; relate freeClerk to readyShipment across R23; readyShipment.waitingToBePacked = false; freeClerk.idle = false; generate clerkAssigned to freeClerk; generate clerkAssignedToShipment to self;

27 Executable UML Summary v Parameters can be passed between state machines using signals v We have explored some aspects of  Synchronous creation and deletion of objects  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


Download ppt "Executable UML The Models are the Code - Executable UML Lecture 9 - Communication and Relationship Dynamics Paul Krause."

Similar presentations


Ads by Google