02291: System Integration Components (part II) Hubert Baumeister huba@dtu.dk DTU Compute Technical University of Denmark Spring 2020
Problem for the connection of components BankATM verifyPIN verifyPIN withdraw Clearing− Bank ATM Company CB BC AB BA pinOk pinOk pinNotOK pinNotOK withdrawOK withdrawNotOk Interconnecting Components: What can go wrong? 1. message sent but not understood 2. message sent but component is not ready to receive 3. component waits for a message not sent ◮ . . .
Solution for 1: Interfaces Required Interface Provided Interface by port BA by port AB Port AB Clearing Company Bank ATM Provided Interface Required Interface Port BC Port BA by port BA by port AB <<interface>> BankToAtm verifyPIN(iban:IBAN, pin:int) withdraw(iban, amount:Money) Bank ATM <<interface>> AtmToBank pinOK pinNotOK withdrawOk withdrawNotOk
Solution for 2+3: Protocol state machines Protocol state machine ◮ Associated to provided interfaces of a port ◮ Sending messages to the required interface ◮ [post] usually [ˆm] meaning: A message m has been sent to the required interface [pre] operation / [post] s1 s2 Behavioural state machine operation [guard] / action s1 s2
Solution for 2+3: Protocol state machines Protocol for the interface BankToAtm which is the provided interface of PortBA and the required interface of PortAB sm: BankToAtm {protocol} /[^withdrawNoOk] /[^withdrawOk] verifyPin(p) /[^pinOk] withdraw(i,a) idle verifying withdraw withdrawing /[^pinNotOk]
Solution for 2+3: Protocol state machines Protocol for the interface BankToAtm which is the provided interface of PortBA and the required interface of PortAB sm: BankToAtm {protocol} /[^withdrawNoOk] /[^withdrawOk] verifyPin(p) /[^pinOk] withdraw(i,a) idle verifying withdraw withdrawing /[^pinNotOk] Protocol for interface AtmToBank which is the provided interface of PortAB and the required interface of portBA AtmToBank {protocol} pinOk /[^verifyPin] waiting Idle pinNotOk
Protocol state machines Protocol for the interface BankToAtm which is the provided interface of PortBA and the required interface of PortAB sm: BankToAtm {protocol} /[^withdrawNoOk] /[^withdrawOk] verifyPin(p) /[^pinOk] withdraw(i,a) idle verifying withdraw withdrawing /[^pinNotOk] Protocol for interface AtmToBank which is the provided interface of PortAB and the required interface of portBA AtmToBank {protocol} withdrawOk withdrawNotOk /[^verifyPin] pinOk/[^withdraw(i,a)] Idle waiting Withdraw pinNotOk
Exercise: Bank to Clearing Company Required Interface Provided Interface by port BA by port AB Port AB Clearing Company Bank ATM Provided Interface Required Interface Port BC Port BA by port BA by port AB «interface» «interface» CcToBank BankToCc verifyPin(p) pinOk pinNotOk What are the two PSM’s for the two interfaces?
PSM’s CcToBank and BankToCc «interface» «interface» CcToBank BankToCc verifyPin(p) pinOk pinNotOk
Implementing components by components UML User Manual, Grady Booch
Bank component showing Implementation by classes Bank ClearingCompanyToBank BankToATMPort BankToAtm «delegate» «delegate» * * «delegate» «delegate» Bank BankToClearingCompany AtmToBank Account Customer
Detailed Class Diagram for the Bank Component Port BA <<interface>> BankToATMPort BankToAtm verifyPIN(a,p) verifyPIN(a,p) withdraw(a,m) * Account withdraw(a,m) pinOK number : IBAN pinNotOk balance : int <<interface>> AtmToBank withdraw(amount:int): bool ... pinOK 1 atm pinNotOK withdrawOk 1..* withdrawNotOk Bank 1..* name: String Port BC Customer 1 b ... name pinOK <<interface>> address pinNotOk c BankToClearingCompany * * ... accountFor(a): Account pinOK ... pinNotOk <<interface>> ClearingCompanyToBank 1 cc verifyPIN(a,p)
Behaviour implementation Lifecycle state machine BankToATMPort sm: BankToATMPort BankToAtmPort withdrawOk/atm.withdrawOK verifyPin withdrawNotOk/atm.withdrawNotOk pinOk pinNotOk pinNotOk/atm.pinNotOk withdraw withdrawOk verifyPin(a,p)/b.verifyPin(self,ap,p) idle verifying withdrawNotOk pinOK/atm.pinOK * waiting for widthdraw(a,m)/b.withdraw(self,a,m) withdrawing withdraw Bank Customer name verifyPin * Lifecycle state machine Bank address pinOk pinNotOk .. withdraw withdrawOk sm: Bank withdraw(p,a1,m)[not(a1=a)]/p.withdrawNotOk withdrawNotOk -accountFor pinNoOk/p.pinNotOk [c.account->exists(nbr-a)]/cc.verifyPin(a,pin) Account [else]/p.pinNotOk number verifyPin(p,a,pin) waiting for balance idle verifying ClearingCompany verification withdraw pinOK/p.pinOK verifyPin .. [wok]/p.widthdrawOk [else]/p.withdrawNotOk waiting for withdraw withdrawing withdraw(p,a1,m)[a1=a]/acc := accountFor(a1); wok := acc.withdraw(m)
LSM conformance with PSM Protocol for provided interface of the port Bank to ATM sm: BankToAtm {protocol} /[^withdrawNoOk] /[^withdrawOk] «interface» «interface» BankToAtm AtmToBank verifyPin(p) /[^pinOk] withdraw(i,a) idle verifying withdraw withdrawing verifyPin pinOk withdraw pinNotOk /[^pinNotOk] withdrawOk withdrawNotOk BankToAtmPort lifecycle state machines BankToAtmPort verifyPin pinOk sm: BankToATMPort withdrawOk/atm.withdrawOK pinNotOk withdrawNotOk/atm.withdrawNotOk withdraw withdrawOk pinNotOk/atm.pinNotOk withdrawNotOk verifyPin(a,p)/b.verifyPin(self,ap,p) idle verifying pinOK/atm.pinOK waiting for widthdraw(a,m)/b.withdraw(self,a,m) withdrawing withdraw
Summary ◮ Required and provided interfaces of a port have protocol state machines ◮ Usually there are always two matching protocol state machines for the opposite ports ◮ Classes implementing components have life cycle state machines
Recommend
More recommend