UML State Models U State ode s Basic State Model - - PowerPoint PPT Presentation

uml state models u state ode s
SMART_READER_LITE
LIVE PREVIEW

UML State Models U State ode s Basic State Model - - PowerPoint PPT Presentation

Overview UML State Models U State ode s Basic State Model Concepts/Notations Basic State Model Concepts/Notations History Psudostates State Model Exercise 1 State Model Exercise 1 Composite States Eunjee Song State


slide-1
SLIDE 1

UML State Models U State

  • de s

Eunjee Song

  • Dept. of Computer Science

Baylor University y y

Some slides adapted from materials in the following sources: UML 2 0 Specification by OMG UML Tutorial by Dr R France and State Model

Eunjee Song State Models-1

UML 2.0 Specification by OMG, UML Tutorial by Dr. R. France, and State Model Tutorial by Dr. E Toch.

Overview

 Basic State Model Concepts/Notations  Basic State Model Concepts/Notations  History Psudostates

State Model Exercise 1

 State Model Exercise 1  Composite States  State Modeling Design Studio  Advanced State Model Topics in UML 2.0

Eunjee Song State Models-2

What’s Missing in Behavior Modeling?

p : Product : ShooppingCart customer display() getPrice() addProduct (p) checkout ()

In Sequence diagram, we do not really know how the state of the shopping cart state of the shopping cart changes.

Eunjee Song

Modeling States

How can we model the state of the shopping

How can we model the state of the shopping cart?

Depends on:

Object state (e.g. created, destroyed)

Variable assignment

Relation status (i.e. number of items)

Operating methods & processes

History

Eunjee Song

History

slide-2
SLIDE 2

The Automata

 A machine whose output behavior is not only

a direct consequence of the current input, but q p ,

  • f some past history of its inputs.

 Characterized by an internal state which

y represents this past experience.

If the phone is ON, then clicking will turn it off clicking will turn it off If the phone is OFF, then clicking will turn it on

Eunjee Song

Automata – Mathematical Foundations

 An Automata is a 4-tuple: S,, ,S0

 S is a set of states   is an alphabet - finite set of symbols   is the transition function:  : S    S

Gi t t d

 S0 is an initial state

M

click click

  • ff
  • n

Given a state and an input, the automata jumps to a new state S0

 Many uses:

 Stochastic processes (x, y & z are probabilities)

Formal and nat ral lang ages ( & are

 Formal and natural languages (x, y & z are

characters)

 Complex systems (x, y & z are…)

Eunjee Song

p y ( , y )

Automata Modeling with Statecharts

 A Statechart augments deterministic

automata making them suitable for automata, making them suitable for specifying behavior of complex systems, using: using:

 Visual formalism  Rich alphabet model

p

 State Modularity  Parallel behavior

 Developed by David Harel (Weizman Inst.)

Eunjee Song

State Models

 A state model specifies the life histories of objects in

terms of the sequences of operations that can occur in response to external stimuli.

 For example, a state model can describe how an object

responds to a request to invoke one of its methods responds to a request to invoke one of its methods.

 A state model consists of state diagrams that each

describes how an object responds to external stimuli.

 A state diagram describes behavior in terms of

sequences of states that an object can go through in t t response to events.

Eunjee Song State Models-8

slide-3
SLIDE 3

Simple Example: Telephone Object

dl dl

state initial state

I dle I dle

lift receiver/ get dial caller hangs up / di

event

Active Active

tone disconnect

  • When the object is created, it moves into

the Idle state.

Active Active

Activity that is performed during transition: it executes

  • If a “lift receiver” event is received the
  • bject moves from the Idle to the Active
  • state. During the transition the “get dial

tone” activity is executed. executes instantaneously tone activity is executed.

  • If a “caller hangs up” event occurs when

in Active state, the object moves to the Idle state and the “disconnect” activity is f d d i h i i

Eunjee Song State Models-9

performed during the transition.

Object Behavior - General Model

 Typical object lifecycle initialize initialize Object Object Wait for Wait for Wait for

Handling depends on Handling depends on specific request type specific request type

Handle Handle Request Request Request

void:offHook ();

Handle Handle Request Request

(); {busy = true;

  • bj.reqDialtone();

… };

Terminate Terminate Object Object

Eunjee Song State Models-10

Object Object

Object Behavior and State Machines

 Reflecting object lifecycle in a state diagram

  • n

Initialize Initialize Object Object

  • n

Lamp Lamp On On

Handle Handle Wait for Wait for Event Event

  • ff
  • n/print(”on”)

Event Event

  • ff

Lamp Lamp Off Off

  • ff

Terminate Terminate Object Object

Off Off stop

Eunjee Song State Models-11

Key Concepts

 An event is a significant or noteworthy occurrence at

a point in time.

 Examples of events: sending a request to invoke a method  Examples of events: sending a request to invoke a method,

termination of an activity.

 An event occurs instantaneously in the time scale of an

application application.

 A state is a condition of an object during its lifetime.

 For example, a student is in the registered state after

completing course registration.

 A state is an abstraction of an object’s attribute values and

links

 For example, a bank account is in the Overdraft

state when the value of its balance attribute is less than 0.

Eunjee Song State Models-12

than 0.

slide-4
SLIDE 4

Key Concepts - 2

 A transition occurs when an event causes an object to

change from its current (source) state to a target state.

 For example, if a student is in the registered state and then  For example, if a student is in the registered state and then

drops out of the program then the student is in the “not registered” state.

 The source and target states can be the same.  The source and target states can be the same.  A transition is said to fire when the change from source to

target state occurs.

 A guard condition on a transition is a boolean  A guard condition on a transition is a boolean

expression that must be true for a transition to fire

 An activity is a behavior that is executed in response

y p to an event.

Eunjee Song State Models-13

Basic UML State Diagram

top

State State Initial Initial state state “top” state top” state

top

Ready Ready

Event Event state state

/ctr := 0 stop

Transition Transition

/ctr : 0 stop

Activity Activity Final Final t t t t

Done Done stop

ct ty ct ty state state

Eunjee Song State Models-14

States & Classes

t d State view Class view State Order status: {created, sent, created in gathering Transition status {c eated, se t, received} hasProblems : boolean th It () in gathering gatherItems() updateInventory() sendOrder() received(customer) sent received(customer) sendReciept() is received in problem

Eunjee Song

Activities

 When holding the state,

the component can

in gathering

p perform activities.

 Can be continuous, taking a

do: gatherItems() do: updateInventory()

specific, or unbounded, time

 Activities within a state are

sequential sequential

 Activities can be interrupted

 There are special types of

created enter: set hasProblems to false

There are special types of activities: enter, exit and event classified activities

do: init gathering list exit: clean log file

Eunjee Song

Intro | Building Blocks | Advanced

slide-5
SLIDE 5

Transitions

x y event [guard] / action

Eunjee Song

Event Types

ChangeEvent: Occurs when a condition expressed as a boolean expression becomes true or when there is a change in value of some entity. y

when condition or true/false(variable)

Examples: when(temperature > 80); when(balance < 0); true(hasError)

SignalEvent: Occurs when an signal is sent or received, where a g g , signal is a one-way transmission of information from one object to a target object.

Event(param1,param2,…)

Examples: lift receiver; hang-up telephone

TimeEvent: Passage of a specific period of time after a designated event, or an occurrence of a specified time instance.

Passage of time since entry to current state - after (time period) , e.g., after (10 secs), after (5 secs since exit of state A)

Occurrence of a time instance – when(due-date=Feb 28, 2005, 11pm)

Eunjee Song State Models-18

Events Examples

 Signal Events

 Method calls: received(customer)

E ent signals i

t R d

created

 Event signals: inventoryReady

 Time event

 interval expiry;

created

inventoryReady

p y

tm(3 days), tm(1000 ms)

 calendar/clock time; when(11:50)

Change Event:

in gathering

false(hasProblems)

 Change Event:

 Change in value of some entity;

false(hasProblems); true(hasProblems);

sent tm(3 days)

received()

true(hasProblems);

is received ()

in problem

Eunjee Song

Guards (Conditions)

C diti l ti f t iti

 Conditional execution of transitions

 guards (Boolean predicates) must be side-effect free

bid bid [value < 100] /reject /reject

Selling Selling Happy Happy

bid bid [value >= 200] /sell /sell [ ] j j bid bid [(value >= 100) & (value < 200)] /sell /sell

Unhappy Unhappy

Eunjee Song State Models-20

slide-6
SLIDE 6

Guards (cont.)

sent in gathering

gatheringFinished [all items were gathered]

in gathering in problem

gatheringFinished [items are not found]  Evaluated when the transition is triggered  Types of guards:

Si l di t

 Simple predicate: [hasProblems], [x > 0]  Combined predicates:

[hasProblems  (hasProblems  order.sum < 100]

 Guards on activities: [active(gatherItems)]  State related (we’ll get back to it later)

Eunjee Song

State Representations

StateName StateName

activity executed when state is

StateName

Att1 : Attrib1 t / ti

entered activity executed

entry/ action exit/ action event/ action

when state is exited activity executed when event

do/ action

  • ccurs while in

state activity executed while in state

Eunjee Song State Models-22

State Syntax

A state symbol can have one or more compartments (all optional): compartments (all optional):

 Name compartment  Internal transition compartment

 contains internal actions or activities  Format:  event(args) [condition] / action

t / ti (i k d i li itl )

 entry / action (invoked implicitly)  exit / action (invoked implicitly)  do / machine name (invokes a nested state machine)

Eunjee Song State Models-23

 do / machine name (invokes a nested state machine)

State Syntax

 Entry and exit activities cannot have  Entry and exit activities cannot have

arguments and cannot have guard conditions.

 Activity expressions can use object attributes  Activity expressions can use object attributes

and links, and parameters of events on incoming transitions. incoming transitions.

Eunjee Song State Models-24

slide-7
SLIDE 7

State Entry and Exit Actions

LampOn LampOn

entry/lamp.on(); it/l ff()

e2 e2

exit/lamp.off();

e1 e1

Eunjee Song State Models-25

Order of Actions: Simple Case

  • ff/printf(“to off”);
  • ff/printf(“to off”);

LampOff LampOff

entry/lamp.off(); entry/lamp.off();

LampOn LampOn

entry/lamp.on(); entry/lamp.on(); exit/printf(“exiting”); exit/printf(“exiting”); exit/printf(“exiting”); exit/printf(“exiting”);

Resulting activity sequence: Resulting activity sequence: printf(“exiting”); printf(“exiting”); printf(“to off”); printf(“to off”); printf(“exiting”); printf(“exiting”); printf(“exiting”); printf(“exiting”);

  • ff/printf(“needless”);
  • ff/printf(“needless”);

p lamp.off(); lamp.off(); lamp.off(); lamp.off(); printf( exiting ); printf( exiting ); printf(“needless”); printf(“needless”); lamp.off(); lamp.off();

Eunjee Song State Models-26

Internal Transitions

 Self-transitions that bypass entry and exit actions

Internal transition Internal transition LampOff LampOff triggered by triggered by an “off” event an “off” event

entry/lamp.off(); entry/lamp.off(); exit/printf(“exiting”); exit/printf(“exiting”); ff/ ll

  • ff/null;

Eunjee Song State Models-27

State (“Do”) Activities

 Forks a concurrent thread that executes

until:

 the action completes or

p

 the state is exited through an outgoing

transition

Error Error

t / i tf(“ !”) t / i tf(“ !”)

“do” activity do” activity

entry/printf(“error!”) entry/printf(“error!”) do/while (true) alarm.ring();

Eunjee Song State Models-28

slide-8
SLIDE 8

Hierarchical State Machines

 Graduated attack on complexity

 states decomposed into state machines

LampFlashing LampFlashing flash/ flash/

LampOff LampOff

entr /lamp off() entr /lamp off()

g

FlashOn FlashOn

entry/lamp.on() entry/lamp.on()

  • ff/
  • ff/

entry/lamp.off() entry/lamp.off()

1sec/ sec/ 1sec/ sec/

  • n/
  • n/
  • n/
  • n/

FlashOff FlashOff

entry/lamp.off() entry/lamp.off()

LampOn LampOn

entry/lamp.on() entry/lamp.on()

  • n/
  • n/
  • n/
  • n/

Eunjee Song State Models-29

“Stub” Notation

 Notational shortcut: no semantic

significance

LampFlashing LampFlashing flash/ flash/

LampOff LampOff

entr /lamp off() entr /lamp off()

g g

FlashOn FlashOn

  • ff/
  • ff/

entry/lamp.off() entry/lamp.off()

  • n/
  • n/
  • n/
  • n/
  • n/
  • n/

FlashOff FlashOff

LampOn LampOn

entry/lamp.on() entry/lamp.on()

  • n/
  • n/

Eunjee Song State Models-30

Group Transitions

Default transition to Default transition to LampOff LampOff

 Higher-level transitions

the initial state in LampFlashing the initial state in LampFlashing

LampFlashing LampFlashing

FlashOn FlashOn LampOff LampOff

entry/lamp.off() entry/lamp.off()

flash/ flash/ 1sec/ 1sec/ 1sec/ 1sec/

entry/lamp.on() entry/lamp.on()

  • ff/
  • ff/

1sec/ 1sec/

FlashOff FlashOff

entry/lamp.off() entry/lamp.off()

LampOn LampOn

  • n/
  • n/
  • n/
  • n/

y p () y p () entry/lamp.on() entry/lamp.on()

Group transition: when Group transition: when on

  • n occurs
  • ccurs

Group transition: when Group transition: when on

  • n occurs
  • ccurs

in any LampFlashing state in any LampFlashing state t iti i d t L O t iti i d t L O

Eunjee Song State Models-31

p a transition is made to LampOn a transition is made to LampOn

Completion Transitions

T i d b l ti t

 Triggered by a completion event

 generated automatically when an immediately nested

state machine terminates

Committing Committing completion completion Committing Committing

Phase Phase1 1

transition (no trigger) transition (no trigger)

Phase Phase2

CommitDone CommitDone

Phase Phase2

Eunjee Song State Models-32

slide-9
SLIDE 9

Triggering Rules

 Two or more transitions may have the same

event trigger

innermost transition takes precedence

 innermost transition takes precedence  event is discarded whether or not it triggers a transition

LampFlashing LampFlashing

FlashOn FlashOn

  • ff/
  • ff/

FlashOn FlashOn

  • n/

/

  • ff/
  • ff/

FlashOff FlashOff

  • n/

Eunjee Song State Models-33

Order of Actions: Complex Case

 Same approach as for the simple case

S1 1 exit/exS exit/exS1 1 S2 2 entry/enS entry/enS2 2 S11 11 S21 21 /initS /initS2 2 E/actE E/actE exit/exS exit/exS11 11 entry/enS entry/enS21 21 Event E occurs when the system is on S11 exS11  exS1  actE  enS2  initS2  enS21 Event E occurs when the system is on S11. Actions execution sequence: ?

Eunjee Song State Models-34

exS11  exS1  actE  enS2  initS2  enS21

State Merge Example

A statechart for an elevator. The elevator starts at the first floor. It can be moving up and down. If the elevator is idle on one floor, a time-out event occurs after a period of time and moves the elevator back to the first floor first floor. M i U

(fl )

OnFirstFloor MovingUp do/moving to floor MovingDown

go up (floor) arrived go down (floor) go up (floor)

Idle entry/timer = 0 MovingDown do/moving to floor

go down (floor) arrived go up (floor)

entry/timer = 0 do/increase timer

when(timer = time-out)/go down (first floor)

Eunjee Song 35 Eunjee Song

State Merge Example (cont.)

OnFirstFloor Moving do/moving to floor

go up (floor) i d

Idle

arrived go down (floor) go up (floor)

Idle entry/timer = 0 do/increase timer

when(timer = time-out)/go down (first floor)

Eunjee Song 36 Eunjee Song

slide-10
SLIDE 10

UML 2.0: History Pseudostates

 Deep History

 The most recent active configuration of the  The most recent active configuration of the

composite state that directly contains its pseudostate (e.g., the state configuration that was active when the composite state was last exited ) active when the composite state was last exited.)

 denoted by H* is a circle

 Shallow History  Shallow History

 The most recent active substate of its containing

state (but not substates of that substate) ( )

 denoted by H in a circle

Eunjee Song State Models-37

Command Backup Example without History Pseudostate

BackingUp Collecting Command BackingUp

evt1 evt2

Copying Cl i U Command

evt3

  • In state Command, the statechart receives the sequence evt1, evt2,

evt3 evt1

ClearingUp

evt3, evt1

  • Sequence of states: Command, Collecting, Copying, Command,

Collecting

Eunjee Song 38 Eunjee Song

Command Backup Example

BackingUp

with History Pseudostate

Collecting H*

evt1 evt2 t3

Copying ClearingUp Command

evt3

  • In state Command, the statechart receives the sequence evt1, evt2,

evt3 evt1

ClearingUp

evt3, evt1

  • Sequence of states: _______________, _______________,

_______________, _______________, ________________

Eunjee Song 39 Eunjee Song

Error-Fix Example with History Psudostae

A

entry/actP exit/actQ

Ready

start

S1

entry/actA exit/actB

S3

entry/actC do/activity1 e2/act6

StandBy

error H fixed

  • Shallow History
  • The most recent active

substate of its

S2

e1/act3 e2

S4

e4 e5/act7

containing state (but not substates of that substate)

e3/act4 e5/act5

Eunjee Song State Models-40

slide-11
SLIDE 11

State Model Exercise 1

 Refer to State Model Exercise 1 handout  Refer to State Model Exercise 1 handout

Eunjee Song State Models-41

Composite States

 A state can be decomposed in two ways:

 OR decomposition: object state decomposed into

a network of states. [Sequential substates] AND d iti bj t t t d d

 AND decomposition: object state decomposed

into two parallel components. [Concurrent substates] substates]

Eunjee Song State Models-42

Sequential substates

 An object in a composite state can only be in one of

that state’s substates at the same time (mutually exclusive)

 Sequential Substates are also called ‘OR‘ states,

disjoint substates disjoint substates

Validating

Active Idl

cardInserted Selecting Processing [continue]

Idle

maintain cancel Printing [not continue] entry/ readCard exit/ejectCard

Maintenance

Eunjee Song 43 Eunjee Song

Concurrent substates

 If an object can be in a composite state but can also

be in more than one of that state’s substates at the same time (may be active simultaneously) same time (may be active simultaneously)

 Concurrent Substates are also called ‘AND‘ states,

  • rthogonal substates

Maintenance Testing

maintain

TestingDevices SelfDiagnosis

[continue]

g Commanding Idle

maintain

Waiting Command

keyPress [not continue]

Eunjee Song 44 Eunjee Song

slide-12
SLIDE 12

Orthogonality: Example 1

 Multiple simultaneous perspectives on the same entity age age

Child Child

age age financialStatus financialStatus

Adult Adult Poor Poor Retiree Retiree Rich Rich

Eunjee Song State Models-45

Orthogonality: Example 2

 Multiple simultaneous perspectives on the same entity Marital Marital

Single Single

Marital Marital employee employee

Married Married Member Member Divorced Divorced Manager Manager

Eunjee Song State Models-46

Orthogonal Regions

 Combine multiple simultaneous descriptions

age age financialStatus financialStatus

Child Child Poor Poor

financialStatus financialStatus

Adult Adult Poor Poor

financialStatus financialStatus

Child Child

age age

Retiree Retiree Rich Rich Poor Poor Adult Adult Rich Rich Retiree Retiree

Eunjee Song State Models-47

Orthogonal Regions - Semantics

 All mutually orthogonal regions detect the same events and

respond to them “simultaneously” ll d t i t l i f ki d

financialStatus financialStatus legalStatus legalStatus

 usually reduces to interleaving of some kind

LawAbiding LawAbiding Poor Poor

robBank/ robBank/ robBank/ robBank/

Outlaw Outlaw Rich Rich

Eunjee Song State Models-48

slide-13
SLIDE 13

Interactions Between Regions

 Typically through shared variables or awareness

  • f other regions’ state changes

sane : Boolean sane : Boolean

Catch Catch22 22

sanityStatus sanityStatus flightStatus flightStatus sane : Boolean sane : Boolean flying : Boolean flying : Boolean y g

Crazy Crazy

entry/sane := false; entry/sane := false;

Flying Flying

entry/flying := true; entry/flying := true;

(flying)/ (flying)/ request request Grounding/ Grounding/ (sane)/ (sane)/ (~sane)/ (~sane)/

Sane Sane

entry/sane := true; entry/sane := true;

Grounding/ Grounding/

Grounded Grounded

entry/flying := false; entry/flying := false;

( sane)/ ( sane)/

Eunjee Song State Models-49

Washing Machine Example

Eunjee Song State Models-50

How does a Washing Machine Works?

 On / Off button. Start button (No stop button.)

F db k i i th t t

 Feedback is given on the current stage

(soaking, rinsing, draining, drying) Th l

 Three plans:

 Regular

D li t ( ki )

 Delicate (no soaking)  Super delicate (no soaking, no drying)

Off b li k d l b f t ti

 Off can be clicked only before starting, or

after finishing

Eunjee Song

Washing Machine

  • ff

idle click(power) click(power) Tm(10 mins) | light(off) soak click(start) [plan=regular] li k( t t) [ l d li t Do: light(soak) Do: pump(in) click(start) [plan=delicate

  • r super delicate]

tm(30 mins) Tm(5 mins) [plan=super delicate] | light(off) Do: light(rinse) Do: stir() rinse Do: light(drain) Do: pump(out) drain Do: light(dry) Do: stir() dry tm(30 mins) tm(5 mins) [plan=not super delicate]

Eunjee Song

slide-14
SLIDE 14

State Explosion: An Example

What is the off button can be

  • ff

clicked at any time?

idle click(power) click(power) Tm(10 mins) | light(off) soak click(start) [plan=regular]

What if we want to show

Do: light(soak) Do: pump(in) click(start) [plan=delicate

  • r super delicate]

tm(30 mins) Tm(5 mins) [plan=super delicate] | light(off)

how many minutes left to the end of the cycle?

Do: light(rinse) Do: stir() rinse Do: light(drain) Do: pump(out) drain Do: light(dry) Do: stir() dry tm(30 mins) tm(5 mins) [plan=not super delicate]

What if we want to

Eunjee Song

come back to the same state we left?

Composite States

  • ff

click(power) click(power) On idle Tm(10 mins) | light(off) ( ) soak click(start) [plan=regular] Do: light(soak) Do: pump(in) click(start) [plan=delicate

  • r super delicate]

tm(30 mins) Tm(5 mins) [plan=super delicate] | light(off) Do: light(rinse) Do: stir() rinse Do: light(drain) Do: pump(out) drain Do: light(dry) Do: stir() dry tm(30 mins) tm(5 mins) [plan=not super delicate]

Eunjee Song

Composite + History

  • ff

click(power) On idle Tm(10 mins) | light(off) click(power)

H

idle soak click(start) [plan=regular] Tm(10 mins) | light(off) Do: light(soak) Do: pump(in) click(start) [plan=delicate

  • r super delicate]

tm(30 mins) Tm(5 mins) [plan=super delicate] | light(off) Do: light(rinse) Do: stir() rinse Do: light(drain) Do: pump(out) drain Do: light(dry) Do: stir() dry tm(30 mins) tm(5 mins) [plan=not super delicate]

Eunjee Song

Interactions Between Parallel States

  • ff

click(power) click(power) On idle Spin Slow

H

soak idle Regular click(start) [Plan in Regular] click(start) Tm(30) [Plan in Do: spin(150rpm) Spin Slow Entered(rinse) Exited(rinse) Tm(entered(rinse),15) soak rinse Delicate Entered(soak) Tm(30) click(plan) click(plan) click(plan) [Plan not in Regular] Tm(30) [Plan in Super Delicate] idle Do: pump out water

  • ut

Entered(drain) Exited(drain) Entered(rinse) [Plan not in Regular] drain Do: pump in water in Tm(30) [Plan not in Super Delicate] Super Delicate click(plan) Do: spin(400rpm) Spin Fast

Eunjee Song

Pump Plan Controller Rotor

slide-15
SLIDE 15

“Flat” and Parallel Machines

A D 

Every parallel machine can be transformed into a sequential machine: Use of Orthogonal Regions

B E F     

(in G)

Regions

C G

(in G)

No Use of

B,G B,E B,F   

No Use of Orthogonal Regions

C,E C,G        

Eunjee Song

C,F  

Common Misuse of Orthogonality

 Using regions to model independent objects

Person Person1 1 Person Person2 Person Person1 1 Person Person2

Child Child Child Child

Person Person1 1 Person Person2 2

Adult Adult Adult Adult Retiree Retiree Retiree Retiree

Eunjee Song State Models-58

Transition Forks and Joins

 For transitions into/out of orthogonal

regions: g

age age

Child Child Adult Adult Retiree Retiree Staff Staff Member Member Manager Manager

employee employee

Eunjee Song State Models-59

Advanced State Model Concepts in UML 2.0 or later

Eunjee Song State Models-60

slide-16
SLIDE 16

State Syntax - Submachines

Dispense cash: Cash Dispenser  State name:submachine Dispense cash: Cash Dispenser

 machine is the name of a (nested) state machine

that has an initial and final state.

 Execution of the nested machine begins in the  Execution of the nested machine begins in the

initial state.

 When final state of the nested machine is reached

then the exit action of the parent state is executed (if it exists).

Eunjee Song State Models-61

UML 2.0: Entry/Exit Points

 Encapsulation of submachines definition of

ReadAmountSM

abort

definition of exit point

selectAmount

  • therAmount

EnterAmount

abort

aborted

amount

  • k

definition of

Eunjee Song State Models-62

again

definition of entry point

Entry/Exit Points: Usage

ATM VerifyCard

acceptCard

use of exit point

OutOfService

  • utOfService

ReadAmount : ReadAmountSM

aborted

exit point

releaseCard rejectTransaction again

ReleaseCard VerifyTransaction

releaseCard

use of entry point

Eunjee Song State Models-63

Not So Simple Telephone Object Example

Eunjee Song State Models-64

slide-17
SLIDE 17

Static Conditional Branching

 Merely a graphical shortcut for convenient

rendering of decision trees with guard conditions

Selling Selling Happy Happy

[value >= 200] /sell /sell bid bid [(value >= 100) & (value < 200)] /sell /sell [value >= 200] /sell /sell [value < 100] /reject /reject [(value 100) & (value 200)] /sell /sell

Unhappy Unhappy

Eunjee Song State Models-65

Identical model w/Guards

C diti l ti f t iti

 Conditional execution of transitions

 guards (Boolean predicates) must be side-effect free

bid bid [value < 100] /reject /reject

Selling Selling Happy Happy

bid bid [value >= 200] /sell /sell [ ] j j bid bid [(value >= 100) & (value < 200)] /sell /sell

Unhappy Unhappy

Eunjee Song State Models-66

Dynamic Conditional Branching

Ch i d t t d l t d t th

 Choice pseudostate: guards are evaluated at the

instant when the decision point is reached

Selling Selling Happy Happy

bid /gain := calculatePotentialGain(value) [gain >= 200] /sell /sell [(gain >= 100) & (gain < 200)] /sell /sell [gain >= 200] /sell /sell [gain < 100] /reject /reject

Unhappy Unhappy

[(gain 100) & (gain 200)] /sell /sell Dynamic Dynamic choicepoint choicepoint

Eunjee Song State Models-67

Object Types and Threads

P i bj t Obj t th t d l t th d i ti t

  • Passive objects: Objects that respond only to method invocation events
  • Objects execute methods only when requested (thread of execution –

left diagram)

  • Active objects: objects perform actions on their own

Initialize Initialize Initialize Initialize

j j p

  • Object has its own thread of execution (right diagram)

Initialize Initialize Object Object Wait for Wait for Request Request Initialize Initialize Object Object Wait for Wait for Request Request

Red arrows depict threads of

Handle Handle Request Request Request Request Handle Handle Request Request Request Request

control

Terminate Terminate Object Object Terminate Terminate Object Object

Eunjee Song State Models-68

j j

slide-18
SLIDE 18

Passive Objects: Dynamic Semantics

Initialize Initialize Object Object

Concurrency fl

Handle Handle Wait for Wait for Request Request

Two conflict

Handle Handle Request Request

Two concurrent method invocations

  • Encapsulation of information within a passive object does not protect the object from

Terminate Terminate Object Object

concurrency conflicts

  • Explicit synchronization is still required
  • Synchronization can be described by state diagrams (e.g., protocol state models can

Eunjee Song State Models-69

be used to restrict when a passive object responds to method calls

Active Objects and State Diagrams

If object is in the created state and a start event occurs, it sends a method invocation event (request to invoke ready()) to the object named master and moves to state ready.

anActiveObject anActiveObject #currentEvent : Event #currentEvent : Event

poll/defer

+ start ( ) + start ( ) + poll ( ) + poll ( ) created

start/^master.ready()

created start

start/^master.ready()

ready p ( ) p ( ) + stop ( ) + stop ( ) ready

stop/

ready y

poll/^master.ack()

Eunjee Song State Models-70

Active Objects: Dynamic Semantics

ActiveObject:

Run-to-completion model: Run to completion model:

  • Events are queued
  • An object processes events in a queue one at a time.
  • An object cannot suspend handling of an event to handle

h

Eunjee Song State Models-71

another event

The Run-to-Completion Model in Multi-tasking

Environment on a uni processor system Environment on a uni-processor system

 A high priority event for (another) active object

will preempt an active object that is currently will preempt an active object that is currently handling a low-priority event on a uniprocessor system

Active Active1 1 Active Active2 2 hi lo

Event is queued because object is handling the lo event

hi hi

Object, Active1, has i i i d d its activity suspended so that the Active2

  • bject can respond to

hi

Eunjee Song State Models-72