1 / 27

The Models are the Code - Executable UML

The Models are the Code - Executable UML. Lecture 9 - Communication and Relationship Dynamics Paul Krause. Lecture 9 - Communication and Relationship Dynamics. Parameter passing using signals Synchronous creation and deletion of objects Class-based state machines. Signals.

lotte
Download Presentation

The Models are the Code - Executable UML

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. Lecture 9 - Communication and Relationship Dynamics • Parameter passing using signals • Synchronous creation and deletion of objects • Class-based state machines

  3. Signals • The dynamics of a domain are established by the exchange of signals between state machine instances • Signals may contain data • The data in a signal may be used by the entry actions in the recipient state machine • 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. Shipment shipmentID trackingNumber recipient … Order ProductSelection Book Signal exchange between objects 0..1 is included in R9 includes 1..* 0..1 is sent to customer as R6 1 delivers contents of R4 1..* contains customer selections of 0..* is purchased on 1..* contains customer selections of

  5. 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 entry/ // Notify customer that the charge // was approved and the order will // be shipped // create a Shipment for the order Delivered to Customer Being Packed and Shipped Delivered to Customer orderDelivered 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 Signal exchange between objects Shipment state machine // signal that the order has been delivered select one order related by self -> Order[R6] generate orderDelivered to order 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. Event parameters • We may wish to pass items of data as parameters to events • The collection of event parameters can be viewed as an object • By convention, this object is denoted: rcvd_evt • The entry actions may then access the values of the parameters by referring to rcvd_evt • Rule: • all events that cause a transition into a particular state must carry the same parameters

  7. 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; Passing event parameters checkOut(accountNumber, billingAddress, cardExpirationDate, cardHolderName, customerEmail, customerName, customerPhone, shippingAddress)

  8. 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; Passing event parameters 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. 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; Passing event parameters 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. 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; Passing event parameters checkOut(accountNumber, billingAddress, cardExpirationDate, cardHolderName, customerEmail, customerName, customerPhone, shippingAddress) // Link the order to the customer relate self to customer across R5;

  11. Signals and events • A signal is an asynchronous message • An “event” is the receipt of a signal by some state machine • strictly, a signal event • When a signal is generated, its parameters are instantiated using name-value pairs • e.g. • generate addSelection( productID: rcvd_evt.productID, quantity: rcvd_evt.quantity) to order;

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

  13. Creation and deletion of objects • Actions can synchronously create or delete instances of objects without state machines within a procedure • Instances with state machines can be created or deleted asynchronously by sending them signals • Synchronous creation and deletion of objects with state machines is also possible • see Mellor and Balcer section 10.2.2

  14. 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; … Synchronous creation and deletion of objects Order state machine addSelection (productID, quantity) addSelection (productID, quantity) cancel checkOut(…)

  15. 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; … Synchronous creation and deletion of objects Order state machine addSelection (productID, quantity) addSelection (productID, quantity) cancel checkOut(…)

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

  17. 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; Synchronous creation and deletion of objects Order state machine addSelection (productID, quantity) addSelection (productID, quantity) cancel checkOut(…)

  18. 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; Synchronous creation and deletion of objects cancel destroying the association will destroy the respective instance of the association class

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

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

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

  22. Use of an assigner state machine • Usually this will be a class-based state machine • Has only one instance • The assigner is a single point of control for resolving resource contention • This is in addition to any object-based state machine

  23. 1: Waiting for Shipment 2: Waiting for a Free Clerk 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; entry/ select any readyShipment from instances of Shipment where selected.waitingToBePacked; if not empty readyShipment generate shipmentReadyToPack to self; end if; entry/ select any freeClerk from instances of ShippingClerk where selected.idle; if not empty freeClerk generate clerkFree to self; end if; Shipping Clerk Assigner clerkAssignedToShipment shipmentReadyToPack clerkFree

  24. 2: Waiting for a Free Clerk 1: Waiting for Shipment 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; entry/ select any freeClerk from instances of ShippingClerk where selected.idle; if not empty freeClerk generate clerkFree to self; end if; entry/ select any readyShipment from instances of Shipment where selected.waitingToBePacked; if not empty readyShipment generate shipmentReadyToPack to self; end if; Shipping Clerk Assigner clerkAssignedToShipment shipmentReadyToPack clerkFree

  25. 1: Waiting for Shipment 2: Waiting for a Free Clerk 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; entry/ select any readyShipment from instances of Shipment where selected.waitingToBePacked; if not empty readyShipment generate shipmentReadyToPack to self; end if; entry/ select any freeClerk from instances of ShippingClerk where selected.idle; if not empty freeClerk generate clerkFree to self; end if; Shipping Clerk Assigner clerkAssignedToShipment shipmentReadyToPack clerkFree

  26. 1: Waiting for Shipment 2: Waiting for a Free Clerk 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; entry/ select any readyShipment from instances of Shipment where selected.waitingToBePacked; if not empty readyShipment generate shipmentReadyToPack to self; end if; entry/ select any freeClerk from instances of ShippingClerk where selected.idle; if not empty freeClerk generate clerkFree to self; end if; Shipping Clerk Assigner clerkAssignedToShipment shipmentReadyToPack clerkFree

  27. Summary • Parameters can be passed between state machines using signals • We have explored some aspects of • Synchronous creation and deletion of objects • Asynchronous creation and deletion of objects • We have also seen how class-based state machines can be used to handle resource contention • See Chapters 10-13 of Mellor and Balcer

More Related