1
play

1 How to model concurrency within an object Examples of Aggregation - PDF document

Review of getting started: Scenario making: gets us started thinking about More Dynamic Modeling events. Interface (high-level prototyping): helps us to think about order of things. (happening in projects) Event trace: helps to know


  1. Review of getting started: ● Scenario making: gets us started thinking about More Dynamic Modeling events. ● Interface (high-level prototyping): helps us to think about order of things. (happening in projects) ● Event trace: helps to know what object is doing what action. ● State Diagram creation tips. 10a-MoreDynamicModels 1 2 10a-MoreDynamicModels Dynamic Model - State States Labeled with Conditions Diagram Microwave Oven ● Graphical representation of a finite state machine. SOP open_door/close:=f; heat:=f (null) ● Changing states - transitioning on events. start_oven/start:=t; error:=t ● Events - external stimuli and internal messages open_door/close:=f close_door SE1 S4 ■ ex. button pushed; timer complete; tub full. S0 done/start:=f; heat:=f start, error close; heat do/close:=t close ■ ex. “complete” event sent by state close_door start_cooking/start:=f ● In each state, a set of predicates based on start_oven/start:=t open_door/close:=f instance variables, is valid. SE2 reset/close:=f; S3 S2 warmup/heat:=t start, close, start,close, error:=f start, close error heat 3 4 10a-MoreDynamicModels 10a-MoreDynamicModels How dynamic model relates to object Dynamic Models for E.S. model ● Dynamic Model for user buttons would be simplistic; button modeling might not be needed. pushed on off button ● One state diagram for each class (with pushed ● Some environmental units might have behavior that important behavior.) should be modeled. (like an engine shifting through speeds) ● Each class has concurrent behavior. ● For embedded systems - might only need one significant ● Aggregation in the Object Model usually behavior model (for controller.) implies concurrency in the Dynamic Model. ● Complex models will be decomposed into more detailed behavioral models. ● Concurrency could be present within a model . 5 6 10a-MoreDynamicModels 10a-MoreDynamicModels 1

  2. How to model concurrency within an object Examples of Aggregation (5.17) Car turn key to start Ignition [Transmission release key in Neutral] ● Object model off starting on turn key off Transmission push R push N Reverse Car Neutral push N push F Forward stop upshift upshift second third first downshift downshift Ignition Transmission Brake Accelerator Each class here will need a concurrent state diagram Accelerator Brake depress accelerator depress brake on off release accelerator on off release brake 7 10a-MoreDynamicModels Example of nesting How to hide complexity (and other syntax as well) ● Not have a ‘flat’ state diagram coin in(value) coin in(value) Do/add to balance(value) idle ● Start abstract and then do subdiagrams. cancel / refund coins select(item) [change<0] ■ use bull’s eye [item empty] ● Take one abstract state and expand it with state Do/test item present; make change generalization. [change=0] [change>0] Example: lower-level state diagram Do/dispense for Dispense item activity change Do/move arm Do/move are to Do/push item to correct row correct column off shelf 9 10 10a-MoreDynamicModels 10a-MoreDynamicModels stop Notation on Transitions and in State Generalization States Push R ● Do/ activity Neutral Reverse Push N event1 (attribs) [condition1]/ action1 State1 do/ activity 1 ■ takes some time. Push N Push F ■ associated with a state. You might need any or State2 Forward ● Guards all of these for your project! do/ activity 2 ■ conditions - boolean Push R ■ [ guard ] Reverse Neutral Push N ● Actions : Push N Push F ■ instantaneous Forward ■ associated with an event. Upshift Upshift ■ /action First Second Third downshift downshift 11 12 10a-MoreDynamicModels 10a-MoreDynamicModels 2

  3. Checking for completeness Things to watch out for and consistency ● Formal specifications do this better! ● Think about input from concurrent objects at unexpected times. ■ The mathematical format can allow automation of these types of checks. ■ ex. If more than one ATM machine is trying to access ● Every state should have a way in and out. the same account at the same time. ■ User input when not planned. (OK to ignore, but make ■ unless starting point or ending point. sure that is what is really wanted.) ● Look for one object’s Dynamic Model sending an ● Take your scenarios and see if they work! event that doesn’t have any receiving transition in ■ Walk through seeing that all the object’s another object’s DM. operations/messages has all the needed transitions. 13 14 10a-MoreDynamicModels 10a-MoreDynamicModels Producer-Consumer - Producer-Consumer Normal Scenario State machine 1 consumer consumer producer producer start get ack send(producer.get) start data get/send(consumer.ack) ack0 timeout/ ack ack send(consumer.nak) fetch data_ready/ wait consumer.data(buf) data(buf) ack timeout wait stash do/save buf 15 16 10a-MoreDynamicModels 10a-MoreDynamicModels Producer-Consumer Basic Class Diagram State machine 2 consumer producer start consumer producer send(producer.get) nak get, ack start get/send(consumer.ack) ack0 data, ack, nak timeout/ ack send(consumer.nak) fetch nak data_ready/ wait consumer.data(buf) data(buf) ack timeout wait stash do/save buf /ack 17 18 10a-MoreDynamicModels 10a-MoreDynamicModels 3

  4. Topics Covered: Dynamic Model Timing and ● Dynamic Model ■ Synchronization schemes Exceptional Handling ■ Exception Handling ■ Timing including safety critical issues. stop 10a-MoreDynamicModels 19 20 10a-MoreDynamicModels Synchronization (Very Simple) Power Plant start idle ● In concurrent processing, the actions of the objects are rarely independent of each other. ● One may need to stop and wait for another process to ‘catch up’ or get to a certain state. op_temp/send(pumps_on) cool timeout(1s)[water cold] heat do/raise rods ● Example: In a nuclear power plant, the model too_hot/insert rods would need to reflect waiting for rods to be in off/insert rods place before generating power. off/ close valves; Get_ready pumps_on pumps pumps off do/open valves do/start pumps 21 22 10a-MoreDynamicModels 10a-MoreDynamicModels Synchronization of States Synchronization of States by status detection by a common event A B B A StateA1 StateB1 event1 event1 A1 B1 event StateB2 IN(A2) StateA2 A2 B2 Firing of the two transitions in the two models Transition between B1 and B2 will not fire until will happen at the same time. object A has entered state A2. 23 24 10a-MoreDynamicModels 10a-MoreDynamicModels 4

  5. Synchronization of States Synchronization of States by common data by Communication A B A B StateA1 StateB1 StateA1 StateB1 do: x:=0 event/send(sync) sync event When(x==1) StateA2 StateB2 StateA2 StateB2 do: x:= 1 Transition from State B1 to State B2 will not fire until in State A2. (This assumes shared memory.) 25 26 10a-MoreDynamicModels 10a-MoreDynamicModels Examples of exception Exception Handling handling ● Events such as resets and hardware interrupts ● Possible to modeling exiting all the substates of a must be handled. superstate in UML. ● These are called Exceptions . ■ Ex. Pushing the N (neutral button) in any of the forward states of a transmission. ● Needed if user can exit a sequence of states at ● 3 ways to exit: normal completion, direct anytime. transition, and exception . normal exiting by completion Superstate event1 using a final state. Good modularity. event substate1 substate2 some_event exception_event normal exit but violates data hiding 27 28 10a-MoreDynamicModels 10a-MoreDynamicModels Timing Issues in Dynamic Timing ( Safety critical ) Model ● Sometimes the firing of a transition is time ● Safety critical real-time solutions dependent , especially in embedded systems. ■ example: ◆ transition out of ‘boiler on’ state after being in this state for 1 ● Real-time systems might have transitions that are hour, even if one expects a transition on tied to a real-time clock . when(temperature>=expected). ● States might time-out after a certain length of time. Boiler when(temperature >= expected) ● Transitions might need to be stalled for a certain On Off length of time. timeout(1h) 29 10a-MoreDynamicModels 5

  6. Delays in Dynamic Model More Timing Issues in D. M. ● For a real-time system, the event might refer to a ● Sometimes a transition should not be fired for a real-time clock certain amount of time. ■ example: ● This timing constraint can be modeled using ◆ changing a traffic signal from day operation to night operation timeout and an extra state at 10 p.m. ■ ex. ◆ 10 seconds since the exit from state A Day Night 2200_hours ◆ This will delay the transition to State B for 10 seconds. superstate superstate 0600_hours event timeout(10s) State A Hold State B 31 32 10a-MoreDynamicModels 10a-MoreDynamicModels 6

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend