Download - The Models are the Code - Executable UML
Executable UML
The Models are the Code -Executable UML
Lecture 9 - Communication and Relationship Dynamics
Paul Krause
Executable UML
Lecture 9 - Communication and Relationship Dynamics
Parameter passing using signals
Synchronous creation and deletion of objects
Class-based state machines
Executable UML
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.
Executable UML
Signal exchange between objects
Shipment
shipmentIDtrackingNumberrecipient…
Order
ProductSelection
Book
R9
R6
R4
0..1
is included inincludes 1..*
0..1 is sent to customer as
1 delivers contents of
1..*contains customerselections of
0..*is
purchasedon
Executable UML
Signal exchange between objects
Delivered to Customer
entry/self.timeDelivered = rcvd_evt.reportedDeliveryTime
// signal that the order has been deliveredselect 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 deliveredselect one customer related by self ->Customer[R5]generate orderReportedDelivered( customerEmail:customer.email) to EE_Online_Customer
orderDelivered
// signal that the order has been deliveredselect one order related by self -> Order[R6]generate orderDelivered to order
Shipment statemachine
Order state machine// notify the Customer that we think // the order has been deliveredselect one customer related by self ->Customer[R5]generate orderReportedDelivered( customerEmail:customer.email) to EE_Online_Customer
orderDelivered
Executable UML
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
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 addressselect 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 existingcustomer.name = rcvd_evt.customerName;customer.shippingAddress = rcvd_evt.shippingAddress;customer.phone = rcvd_evt.customerPhone;
// Link the order to the customerrelate self to customer across R5;
checkOut(accountNumber,billingAddress, cardExpirationDate,cardHolderName, customerEmail,customerName, customerPhone,shippingAddress)
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 addressselect 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 existingcustomer.name = rcvd_evt.customerName;customer.shippingAddress = rcvd_evt.shippingAddress;customer.phone = rcvd_evt.customerPhone;
// Link the order to the customerrelate 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 addressselect 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;
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 addressselect 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 existingcustomer.name = rcvd_evt.customerName;customer.shippingAddress = rcvd_evt.shippingAddress;customer.phone = rcvd_evt.customerPhone;
// Link the order to the customerrelate 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 existingcustomer.name = rcvd_evt.customerName;customer.shippingAddress = rcvd_evt.shippingAddress;customer.phone = rcvd_evt.customerPhone;
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 addressselect 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 existingcustomer.name = rcvd_evt.customerName;customer.shippingAddress = rcvd_evt.shippingAddress;customer.phone = rcvd_evt.customerPhone;
// Link the order to the customerrelate self to customer across R5;
checkOut(accountNumber,billingAddress, cardExpirationDate,cardHolderName, customerEmail,customerName, customerPhone,shippingAddress)
// Link the order to the customerrelate self to customer across R5;
Executable UML
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;
Executable UML
Signals to self
New Order
entry/// Add the first selection to the ordergenerate 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 sentto self
received and actedon.Signals from self are always acted on beforeany other outstandingsignals
Executable UML
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
Executable UML
Synchronous creation and deletion of objects
Order state machine
Adding Selection to Order
entry/// Add the (next) selection to the ordercreate 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(…)
Executable UML
Synchronous creation and deletion of objects
Order state machine
Adding Selection to Order
entry/// Add the (next) selection to the ordercreate 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(…)
Executable UML
Synchronous creation and deletion of objects
Order state machine
Adding Selection to Order
entry/// Add the (next) selection to the ordercreate 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(…)
Executable UML
Synchronous creation and deletion of objects
Order state machine
Adding Selection to Order
entry/// Add the (next) selection to the ordercreate 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(…)
Executable UML
Synchronous creation and deletion of objects
Cancelling Entire Order
entry/// Delete all the selections of the Orderselect 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
Executable UML
Competition in associations
Shipment
shipmentIDtrackingNumberrecipient…
ShippingClerk
awaitingAssignment0..1is currentlypacking
0..1is currently
being packedby
R23
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
Executable UML
Two idle clerks…
A: Shipping clerk B: Shipping clerk:Shipment
6
1
2
1 6
1
2
select shipment select shipment
both clerks try to grab the same shipment
Executable UML
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
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
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;
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;
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;
Executable UML
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