BEHAVIOUR MODELING WITH STATE MACHINE AND ACTIVITY DIAGRAMS

Similar documents
Using UML Part Two Behavioral Modeling Diagrams

Designing a Home Alarm using the UML. And implementing it using C++ and VxWorks

Communications Software Engineering Design Model

CPS122 Lecture: State and Activity Diagrams in UML

Chapter 19. Activity Diagrams

Compliance and Requirement Traceability for SysML v.1.0a

Modeling Guidelines Manual

Introduction to LabVIEW Design Patterns

Announcements. SE 1: Software Requirements Specification and Analysis. Review: Use Case Descriptions

Model Simulation in Rational Software Architect: Business Process Simulation

Types of UML Diagram. UML Diagrams OOAD. Computer Engineering Sem -IV

BPMN Business Process Modelling Notation

4.7 Business Process Model and Notation

Introduction. UML = Unified Modeling Language It is a standardized visual modeling language.

Sequence Diagrams. Massimo Felici. Massimo Felici Sequence Diagrams c

Process Modeling Notations and Workflow Patterns

Process Modeling using BPMN 2.0

UML Activities & Actions. Charles ANDRE - UNSA

Interaction Diagrams. Use Cases and Actors INTERACTION MODELING

Modeling Workflow Patterns

Cyclic Architectures in UML

Process / Operation Symbols

Integrating Legacy Code / Models with Model Based Development Using Rhapsody

How to build agent based models. Field service example

Designing Real-Time and Embedded Systems with the COMET/UML method

How To Control A Car Alarm On A Car With A Remote Control System

Synchronization in. Distributed Systems. Cooperation and Coordination in. Distributed Systems. Kinds of Synchronization.

Configuration Manager

vcenter Orchestrator Developer's Guide

Compute Cluster Server Lab 3: Debugging the parallel MPI programs in Microsoft Visual Studio 2005

KS3 Computing Group 1 Programme of Study hours per week

UML basics. Part II: The activity diagram. The activity diagram's purpose. by Donald Bell IBM Global Services

TAR25 audio recorder. User manual Version 1.03

SCORPION. micron security products

Digital Systems Based on Principles and Applications of Electrical Engineering/Rizzoni (McGraw Hill

Transport Layer Protocols

Basics of VTune Performance Analyzer. Intel Software College. Objectives. VTune Performance Analyzer. Agenda

Multiple Connection Telephone System with Voice Messaging

Spring 2011 Prof. Hyesoon Kim

Software Engineering. System Modeling

Real Time Programming: Concepts

How to Develop Accessible Linux Applications

Intellect Platform - The Workflow Engine Basic HelpDesk Troubleticket System - A102

Chapter 6, The Operating System Machine Level

Hosted VoIP Phone System. Admin Portal User Guide for. Call Center Administration

4 Starts to flash when the system triggers an alarm/fault

Monitoring Replication

Object Oriented Programming. Risk Management

The Parts of the System

StateFlow Hands On Tutorial

StarUML Documentation

Solution-16 Operators Manual ISSUE 1.60

A flowchart is not a state machine

Kirsten Sinclair SyntheSys Systems Engineers

A Dynamic Assertion-based verification platform for UML Statecharts over Rhapsody

Sofware Requirements Engineeing

Business Process Modelling Notation A tutorial

Integration, testing and debugging of C code together with UML-generated sources

Jump-Start Tutorial For ProcessModel

AUTODIALLER / QUICKDIALLER - SA132

Running a Workflow on a PowerCenter Grid

Models of Small Group Development

WEEK 8.1 Registers and Counters. ECE124 Digital Circuits and Systems Page 1

System Modeling / Class Diagra Diagr m a Week 6

Bitrix Site Manager 4.1. User Guide

Printed in China. Issue 4 AT&T 12/11. Message Guard is a registered trademark of Advanced American Telephones.

Digital Cable TV. User Guide

2 SYSTEM DESCRIPTION TECHNIQUES

GSM Autodialer Professional GJD700 Speech & Text Autodialer

TestManager Administration Guide

PART IV Performance oriented design, Performance testing, Performance tuning & Performance solutions. Outline. Performance oriented design

Lecture 8: Synchronous Digital Systems

Fluke 89-IV & 189 Event Logging

Automating Business Processes Using SharePoint Designer

Diagramming Techniques:

11. FLOWCHART BASED DESIGN

Automatic Telephone Dialer TD-101(W)

BPMN Business Process Modeling Notation

Auditing UML Models. This booklet explains the Auditing feature of Enterprise Architect. Copyright Sparx Systems Pty Ltd

Sonatype CLM Server - Dashboard. Sonatype CLM Server - Dashboard

LEN s.r.l. Via S. Andrea di Rovereto 33 c.s CHIAVARI (GE) Tel Fax mailto: len@len.it url: http//

i. Node Y Represented by a block or part. SysML::Block,

? Index. Introduction. 1 of 38 About the QMS Network Print Monitor for Windows NT

Motion Activated Camera User Manual

A Comparison Study of Qos Using Different Routing Algorithms In Mobile Ad Hoc Networks

Algorithm & Flowchart & Pseudo code. Staff Incharge: S.Sasirekha

Document Management User Guide

RTOS Debugger for ecos

COMSPHERE 6700 SERIES NETWORK MANAGEMENT SYSTEM

- User input includes typing on the keyboard, clicking of a mouse, tapping or swiping a touch screen device, etc.

Titanium Schedule Center Management Software USER MANUAL. Sales and Customer Service Technical Support

Frequently Asked Questions: Cisco Jabber 9.x for Android

QUALITY TOOLBOX. Understanding Processes with Hierarchical Process Mapping. Robert B. Pojasek. Why Process Mapping?

Analytics for Performance Optimization of BPMN2.0 Business Processes

LECTURE 11: PROCESS MODELING

INSTALLATION MANUAL VEHICLE SECURITY SYSTEM CE-SS200

Transcription:

BEHAVIOUR MODELING WITH STATE MACHINE AND ACTIVITY DIAGRAMS 1

Objectives Describe system behavior and show how to capture it in a model. Demonstrate how to read and interpret: A state machine diagram An activity diagram 2

Agenda How to describe behavior? Modelling with state machine diagrams Modelling with Activity diagrams 3

Where are we? How to describe behavior? Modelling with State machine diagrams Modelling with Activity diagrams 4

What Is System Behavior? System behavior is how a system acts and reacts. It comprises the actions and activities of a system. 5

What is a Behavior Model? A view of a system that emphasizes the behavior of the system as a whole (as it appears to outside users) Uses: Activity Diagrams State machine Diagrams Sequence Diagrams Interaction Overview Diagrams The system/object is regarded as a black box and the functionalities are expressed from a user s perspective Behavior modeling during development: In the analysis phases: The model must capture the requirements of the system, not the implementation solution In the design & implementation phases: The model must capture the implementation solution. 6

Types of behavior Behavior can be simple: Simple behavior does not depend on the object s history. Behavior can be continuous: Continuous behavior depends on the object s history but in a smooth, continuous fashion. Behavior can be state-driven: State-driven behavior means that the object s behavior can be divided into disjoint sets. 7

Simple behavior Simple behavior is not affected by the object s history: cos( x ) gettemperature( ) setvoltage( v ) Max(a,b) An activity diagram can be used to represent simple behaviour. 8

Continuous behavior Object s behavior depends on history in a continuous way PID control loop: X n Y n W K + n a - Delay V n + + Z n K b Digital filter: Fuzzy logic: Uses partial set membership to compute a smooth, continuous output UML is not very good at describing continuous behavior. 9

State behavior Useful when an object Exhibits discontinuous modes of behavior Is reactive waits for and responds to incoming events For example a Light can be : Off On A light can be characterized as having 3 states On, Off & Flashing. The system can only reside in one of these states at a given time. Flashing A state machine can be used to represent state behaviour. 10

Where are we? How to describe behavior? Introduction to State machine diagrams Introduction to Activity diagrams 11

Quick picture of a state machine idle busy 12

Example: Professor There are a sequence of events before an instructor becomes a University professor. Assistant professor (achieves tenure by producing a number of quality publications) Tenure/Associate professor Professor (based on seniority) Assistant Professor Tenured Professor Retired 13

What is a State Machine? A state machine models dynamic behavior of a element (system, component, class, operation, etc.) State machines are ideal to describe reactive, eventdriven behavior. It specifies the sequence of states in which an object can exist in. a finite number of states The events and conditions that cause transitions between those states. The actions that take place when those states are reached States can be Composite Orthogonal 14

Why use state machines? State machines are executable Because state machines are formally defined, they form executable models. State machines can be visualized graphically. State machines can be animated - their dynamic behavior shown graphically: Standard debugging can be done, such as setting breakpoints, step through, step into, and so on. You can focus on the abstract behavior: Was the door locked with a card or a code? Rather than, is some variable 0 or 1? State Machines provide for easy testing. 15

What is a State Machine Diagram? A state machine diagram visualizes a state machine State symbol Transition lines between the states 16

State Machine Diagram Basic Syntax Initial state Transition Self transition State Final state 17

States / transitions / events / actions What is a state? A state is a distinguishable, disjoint, orthogonal condition of existence of an object that persists for a significant period of time. What is a transition? What is an event? A transition is a response to an event of interest moving the object from a state to a state. An event is an occurrence of a stimulus that can trigger a state transition. What is an action? An action is a run-to-completion behavior. The object does not accept or process any new events until the actions associated with the current event are complete. 18

What is a state? (details) Represents the mode of operation of an activity. idle busy 19

What is a state? (details) The state machine is either in a stable state or is executing the actions specified on a transition A state is also a memory: Use states to memorize a sequence of received input States may be used instead of variables / attributes if it improves the state machine structure, readability or maintainability idle busy Red Yellow Green 20

What is a state? (details) The system must always be in exactly one state at a given level of abstraction. The object must be in either off or on or delay it cannot be in more than one or none. 21

What is a state? (details) Pseudostates Initial Final (return) History state Shallow Deep 22

What is a transition? (details) A transition is the journey from one state to another the placeholder for behavior activated when a event that matches the trigger is selected from a event pool (e.g. signal queue) Transitions may end in the original state A transition ends in a state Final state A Transition may be split using a junction WaitNotification updateid(id)/ack(); Dialing 23

What is a transition? (details) Transition syntax trigger [ guard ] / action list trigger parameter-list digit(n) [number incomplete] / store digit(); Trigger (no guard) Idle usercardok() / ^opendoor(); Dialing guard action WaitDoorOpened doorclosed() [passed==1] digit(n) [number complete] / connect(number); [door.status == open ] event and guard Connected guard only WaitDoorClosed 24

What is a transition? (details) What are guards? A guard is some condition that must be met for the transition to be taken. Guards are evaluated prior to the execution of any action. Guards can be: Variable range specification, for example: [cost<50] Concurrent state machine is in some state [IS_IN(fault)] If two guards are likely to be true at the same time, then it is a good idea to chain condition connectors, so that the order in which the guards are tested is known. 25

Problem 3 Define the proper transition label based on the following criteria: 1. The variable failure_msg is set to true and x is set to 5/y when the event abort occurs. STATE_1 STATE_2 2. Five time units after STATE_1 is entered, system_status is set to level1. STATE_1 STATE_2 26

Problem 3 (continued) Define the proper transition label based on the following criteria: 3. If the event start_testing occurs and power is true, the variable light_cmd is set to true. STATE_1 STATE_2 4. When the value of X changes, then set Z to the absolute value of X. STATE_1 STATE_2 27

Problem 3 - Solution Define the proper transition label based upon the following criteria: 1. The variable failure_msg is set to true and x is set to 5/y when the event abort occurs. STATE_1 ABORT/FAILURE_MSG=true;X=5/Y; STATE_2 2. Five time units after STATE_1 is entered, system_status is set to level1. STATE_1 dly(5)/system_status=level1; STATE_2 28

Problem 3 - Solution (continued) Define the proper transition label based on the following criteria: 3. If the event start_testing occurs and power is true, the variable light_cmd is set to true. START_TESTING and [POWER]/ LIGHT_CMD=true; STATE_1 STATE_2 4. When the value of X changes, then set Z to the absolute value of X. ch(x)/z=abs(x); STATE_1 STATE_2 29

What is a transition? (details) How are transitions handled? If an object is in a state S that responds to an event evx, then it acts upon that event. It transitions to the specified state, if the event triggers a transition and the guard (if any) on that transition evaluates to TRUE. It executes any actions associated with that transition. Events are quietly discarded if: A transition is triggered, but the transition s guard evaluates to FALSE. A transition to a conditional pseudostate is triggered, but all exiting transition guards evaluate to FALSE. The event does not explicitly trigger a transition or reaction. 30

What is an action? (details) Actions are run to completion: Normally actions take an insignificant amount of time to perform They may occur when: A transition is taken A reaction occurs A state is entered A state is exited 31

What is an action? (details) Entry / exit actions Entry actions Exit actions Note the order of execution of the actions and that the guard gets checked before any actions are taken. 32

What is an Event? (details) An event is an occurrence of a stimulus that can trigger a state transition. Example: Successful publication of numerous papers Assistant Professor Event Tenured 33

What is an Event? (details) UML defines 4 kinds of events: Signal Event Asynchronous signal received for example, evon, evoff Call Event Operation call received, for example, opcall(a,b,c) This is known as a Triggered Operation in Rational Rhapsody Change Event Change in value occurred Time Event Absolute time arrived Relative time elapsed, for example, tm(pulsewidthtime) 34

Time event When an object enters a state, any Timeout from that state is started. When the Timeout expires, the state machine receives the expiration as an event. When an object leaves a state, any timeout that was started on entry to that state is cancelled. Only one timeout can be used per state; nested states can be used if several timeouts are needed. Entry action Time event Exit action 35

tm(delaytime) tm(delaytime) is specific to Rational Rhapsody and code is automatically generated to start and stop the timeout. This is equivalent to the second state-chart where a timer is started on entering the state and stopped on exiting the state. If the timer expires, then it would send the requested event, for example, evdelay. UML actually defines the keyword after(delay) instead of tm(delay). 36

Exercise: luggage belt system Draw the state machine for a luggage belt system. The belt is started when the start button is pressed and runs until either the stop button is pressed or until there is no luggage on the belt. This condition is when no luggage has been detected in the previous 60 seconds. 37

Exercise: Luggage belt system (Solution) 38

Hierarchy & concurrency in state machines Simple State Machine Concurrent state machine Hierarchical state machine 39

Concurrency What happens when you want to look at the behavior of two lights simultaneously? L1ON_L2ON L1OFF_L2ON L1ON_L2OFF L1OFF_L2OFF 40

Concurrency Allows the behavior of two lights to be viewed simultaneously. TWO_LIGHTS LIGHT_ONE LIGHT_TWO L1ON L2ON L1OFF L2OFF When using concurrent states it is recommended that the states do not interact or broadcast data. 41

concurrent state communication concurrent states may communicate via: Broadcast events All active concurrent states receive their own copy of each received event and are free to act on it or discard it. Propagated events A transition in one concurrent state can send an event that affects another. Guards [IS_IN( state )] uses the substate of a concurrent state in a guard. Attributes Since the concurrent states are of the same object, they see all the attributes of the object. IS_IN is a Rational Rhapsody C macro that can be used to test to see if an object is in a particular state. 42

Composition A composite state is a state which is composed of other states. The states contained within a composite state are called substates. A composite state A substate of armed If the event evdisarm is received when the object is in state armed, then irrespective of which nested state is active, the transition will be taken and the object will go into the off state. 43

Exercise: LED Draw the state machine for an LED class that can be in one of three modes: on, off and flashing at 1Hz. 44

Exercise: LED (Solution) 45

State machine design guidelines Identify and define states of the System Identify and define transitions Identify and define events and actions 46

Poorly formed state machine Race condition Must be same event History not initialized No default state Conflicting transitions Overlapping guards Use before initialization 47

Exercise: mouse Draw the state machine for the following mouse that has three extra buttons: One of these buttons allows the Mouse to magnify the area around the mouse. This magnify mode is invoked and exited by pressing the magnify button (evmagnify). When in the magnify mode, if the magnify button is held (evmagnifyheld), then the up (evup) and down (evdown) buttons control the magnification, invoking operations incmagnification() and decmagnification(). It remains in this mode until the magnify button is released (evmagnifyreleased). When the magnify button is not held, the up (evup) and down (evdown) buttons invoke operations up() and down(). 48

Exercise: Mouse (Solution) 49

Exercise: Battery charger Draw the state machine for a simple Battery Charger that can charge two batteries in parallel. The charger has three modes: idle, discharging, and charging. A button can be pressed (evstart) to start charging the batteries. However, before each battery can be charged, it must be discharged. When each battery is discharged, it sends an event (evbatterya_discharged or evbatteryb_discharged) to the Battery Charger. When each battery is charged, it sends an event (evbatterya_full or evbatteryb_full) to the Battery Charger. When both batteries are charged, the Battery Charger returns to the idle mode. 50

Exercise: Battery charger (Solution) 51

Where are we? How to describe behavior? Modelling with State machine diagrams Modelling with Activity diagrams 52

What Is an Activity Diagram? Describe the workflow behavior of a system An activity diagram captures the activities and actions performed. It is essentially a flow chart, showing flow of control from one activity or action to another. Show activities that are conditional or parallel. Useful for: analyzing a use case by describing what actions need to take place and when they should occur describing a complicated sequential algorithm modeling applications with parallel processes modeling bussiness workflow 'Enter Departure Airport' 'Departure Airport' 'Lookup city' [found 1 flight] [found 0 flights] [found > 1 flight] 'List of alternatives' 'Select flight' 53

Example: Student course selection Concurrent Threads Guard Condition Check Schedule Select Course [ add course ] [ delete course ] Check Pre-requisites [ checks completed ] [ checks failed ] Decision Delete Course Activity/Action Synchronization Bar (Fork) Synchronization Bar (Join) Assign to Course Resolve Conflicts Transition Update Schedule 54

Activity Diagram Basic Syntax Initial Node Object Node Action Node Fork Join Activity Final Decision Node Guard 55

Activity Diagram Symbols - 1 Initial node Starting point for invoking other activities. An activity may have several starting points. Activity2 if (a) { x = 7; } Action/Activity An action is an executable unit. Can also refer to a new activity diagram - sub-activity 56

Activity Diagram Symbols - 2 Class3 Object node Used to show input to or output from an action. UpdateOrder CustomerOrder object flow shows objects being generated or used by actions or activities in activity diagrams PrepareInvoice 57

Activity Diagram Symbols - 3 x Decision node A decision node is a control node that chooses between outgoing flows. Each branch has its own guard condition Else may be defined for at most one outgoing transition true Guard Alternative from a decision node that is mutually exclusive from the other alternatives Fork/join symbol Divides a flow into multiple concurrent flows. Flows can be split and synchronized again. 58

Activity Diagram Symbols - 4 Signal12 Accept event symbol Represents an input action. Send signal symbol Represents an output action. 59

Exercise Write an activity diagram to describe the process of writing and posting a letter. You might or might not have a stamp. 60

Exercise - Solution Find Pen Find Paper Write Letter [else] Buy stamp [havestamp] Address envelope Afix stamp Post Letter 61

Review What is system behavior? What is a state machine diagram? Describe the different parts of the diagram. Define state. What is an activity diagram? What kind of behavior is best suited to be modeled with state machine Diagrams? What kind of behavior is best suited to be modeled with Activity Diagrams? 62