Seminarium on Component-based Software Engineering

Slides:



Advertisements
Similar presentations
Design by Contract.
Advertisements

CSE Winter 2008 Introduction to Program Verification refining an interface.
NEW SLIDE PROCEDURE A single combined PowerPoint™ file should be submitted for the entire session. Must be coordinated with your Program Chair Slides should.
Observer Method 1. References Gamma Erich, Helm Richard, “Design Patterns: Elements of Reusable Object- Oriented Software” 2.
Remote Method Invocation (RMI) Mixing RMI and sockets
March Ron McFadyen1 Design Patterns In software engineering, a design pattern is a generally repeatable solution to a commonly-occurring problem.
Computer Monitoring System for EE Faculty By Yaroslav Ross And Denis Zakrevsky Supervisor: Viktor Kulikov.
Reza Gorgan Mohammadi AmirKabir University of Technology, Department of Computer Engineering & Information Technology Advanced design.
Object-Oriented Programming with Java The Java Event Model Lecture 5.
Inter Process Communication:  It is an essential aspect of process management. By allowing processes to communicate with each other: 1.We can synchronize.
Polymorphism Chapter six of: Szyperski, Clemens et al. Component Software - Beyond Object-Oriented Programming. Second Edition.
Chapter 11 Operating Systems
Object-Oriented Programming with Java Lecture 2 The Java Event Model.
Components, interfaces, and re-entrance Taciana Amorim Vanderlei
Lesson 3 Remote Method Invocation (RMI) Mixing RMI and sockets Rethinking out tic-tac-toe game.
C++ fundamentals.
1 CSCI 6900: Design, Implementation, and Verification of Concurrent Software Eileen Kraemer August 19 th, 2010 The University of Georgia.
File System. NET+OS 6 File System Architecture Design Goals File System Layer Design Storage Services Layer Design RAM Services Layer Design Flash Services.
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 4 Web technologies: HTTP, CGI, PHP,Java applets)
Database testing Prepared by Saurabh sinha. Database testing mainly focus on: Data integrity test Data integrity test Stored procedures test Stored procedures.
Object-Oriented Software Engineering Practical Software Development using UML and Java Chapter 8: Modelling Interactions and Behaviour.
Protection and the Kernel: Mode, Space, and Context.
Announcements Assignment 3 due. Invite friends, co-workers to your presentations. Course evaluations on Friday.
(c) University of Washington08-1 CSC 143 Models and Views Reading: Ch. 18.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Introduction to Concurrency.
Hardware process When the computer is powered up, it begins to execute fetch-execute cycle for the program that is stored in memory at the boot strap entry.
1 Concurrency Architecture Types Tasks Synchronization –Semaphores –Monitors –Message Passing Concurrency in Ada Java Threads.
Android Security Model that Provide a Base Operating System Presented: Hayder Abdulhameed.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 43 Remote Method Invocation.
37 Copyright © 2007, Oracle. All rights reserved. Module 37: Executing Workflow Processes Siebel 8.0 Essentials.
SOFTWARE DESIGN AND ARCHITECTURE LECTURE 13. Review Shared Data Software Architectures – Black board Style architecture.
EPICS Release 3.15 Bob Dalesio May 19, Features for 3.15 Support for large arrays - done for rsrv in 3.14 Channel access priorities - planned to.
Hardware process When the computer is powered up, it begins to execute fetch-execute cycle for the program that is stored in memory at the boot strap entry.
Web Services An Introduction Copyright © Curt Hill.
Component Patterns – Architecture and Applications with EJB copyright © 2001, MATHEMA AG Component Patterns Architecture and Applications with EJB Markus.
SOCSAMS e-learning Dept. of Computer Applications, MES College Marampally FILE SYSTEM.
L10: Model-View-Controller General application structure. User Interface: Role, Requirements, Problems Design patterns: Model – View – Controller, Observer/Observable.
Software, IEE Proceedings, Vol.152, Num.3, June 2005,Page(s): Prasanthi.S March, Java-based component framework for dynamic reconfiguration.
Event Sources and Realtime Actions
Chapter 3: Windows7 Part 5.
The need for Programming Languages
EECE 310: Software Engineering
Chapter 2 Database System Concepts and Architecture
Introduction to Triggers
Observer Design Pattern
Other Important Synchronization Primitives
Distribution and components
INTER-PROCESS COMMUNICATION
Lesson 3 Remote Method Invocation (RMI) Mixing RMI and sockets
Implementing Subprograms
Chapter 3: Windows7 Part 5.
Chapter 40 Remote Method Invocation
Observer Design Pattern
New Slide Procedure   A single combined PowerPoint™ file should be submitted for the entire session. Must be coordinated with your Program Chair Slides.
System Calls David Ferry CSCI 3500 – Operating Systems
SAMANVITHA RAMAYANAM 18TH FEBRUARY 2010 CPE 691
Structuring Of Systems Using Upcalls - By David D. Clark
Chapter 46 Remote Method Invocation
Component-Based Software Engineering
Chapter 46 Remote Method Invocation
Why Threads Are A Bad Idea (for most purposes)
12. Command Pattern SE2811 Software Component Design
Model, View, Controller design pattern
Why Threads Are A Bad Idea (for most purposes)
Why Threads Are A Bad Idea (for most purposes)
CS703 – Advanced Operating Systems
Implementing Subprograms
Presentation transcript:

Seminarium on Component-based Software Engineering Callbacks and object re-entrance Marcello Bonsangue LIACS – Leiden University Fall 2004

Libraries A library is a collection of procedures It is always the client to call the library Library operations run to completion before returning control Only states before and after a call are relevant to clients, library intermediate states are not observable 31/12/2018 Seminarium CBSE

Callbacks A callback is a procedure that can be registered to a library so that the library can call it back Example: registration of client code to be called when library catch user events They are a mechanism for extensibility Callbacks operate on the intermediate state of a library!! 31/12/2018 Seminarium CBSE

Callback: message sequence chart User Client Library Client installs callback User calls library Library invokes callback Callback queries library Callback returns Calls Results Library returns 31/12/2018 Seminarium CBSE

A Directory service example The directory service supports callbacks to notify clients about changes in the managed directory A client can use this mechanism to implement a visual display of the directory content. 31/12/2018 Seminarium CBSE

The Directory service details LIBRARY Directory Name=ARRAY OF CHAR; Notifier=PROCEDURE(IN name:Name); PROCEDURE ThisFile(n:Name): Files.File; (*pre n <>“” *) (*post result=file named n OR (result=NIL and no such file *) PROCEDURE addEntry(n:Name,f:Files.File); (* pre n<>“” and f<>NIL *) (* post ThisFile(n)=f *) PROCEDURE RemoveEntry(n:Name); (* pre n<>”” *) (* post ThisFile(n)=NIL *) PROCEDURE RegisterNotifier(n:Notifier); (* pre n<>NIL *) (* post n registered, will be called on AddEntry and RemoveEntry *) PROCEDURE UnregisterNotifier(n:Notifier); (* post n unregistered, will not be called anymore *); DirectoryDisplay (V 1.0) IMPORT Directory; PROCEDURE Notifer(IN n:DirectoryName); BEGIN IF Directory.ThisFile(n) = NIL THEN (*entry under name n has been removed – delete n in display *) ELSE (* entry has been added under name n – include n in display *) END Notifier; Directory.RegisterNotifier(Notifier); END 31/12/2018 Seminarium CBSE

The Directory contract ambiguity What happens on redefinition of an entry? Notifier is not called … Redefine uses thisfile (that does not call notifier) …called once … Redefine uses addEntry (that calls notifiers) …twice Redefine uses removeEntry and addEntry (and both call notifier) The contract should specify who call notifier 31/12/2018 Seminarium CBSE

The Directory contract ambiguity Is the notifier called before or after the directory is updated? It is only sensible to call it after the update. It should be in the contract 31/12/2018 Seminarium CBSE

A new Directory display client LIBRARY Directory PROCEDURE addEntry(n:Name,f:Files.File); BEGIN Locate entry named n If not found append a new entry to the files list in this directory Else replace old binding with new file Call all registered notifiers END AddEntry; DirectoryDisplay (V 1.1) IMPORT Directory; PROCEDURE Notifier(IN n:Directory.Name); BEGIN IF Directory.ThisFile(n) = NIL THEN (* entry under name n has been removed – delete n in display *) ELSE IF n = “untitled” THEN Directory.RemoveEntry(n); (* entry has been added under name n include in display *) END END Notifier; Directory.Register(Notifier); 31/12/2018 Seminarium CBSE

ThisFile(“Untitled”)=f Broken contract Request of a user to create file “untitled” Notifier() is called by the directory File is removed by Notifier() The AddEntry() post condition ThisFile(“Untitled”)=f is broken User Directory DirectoryDisplay RegisterNotifier(Notifier) AddEntry(“Untitled”,f) Notifier(“Untitled”) ThisFile(“Untitled”) RemoveEntry(“Untitled”) Notifier(“Untitled”) ThisFile(“Untitled”) Notifier returns RemoveEntry returns Notifier returns AddEntry returns 31/12/2018 Seminarium CBSE

What is the problem The contract of the library does not says that notifiers do not have to change the file passed Difficult to express as it is a transitive problem Solutions: Incorporates histories of interactions in specifications Undecidable or very complex Use state test functions in specifications Test whether a particular operations is available 31/12/2018 Seminarium CBSE

Test functions LIBRARY Directory PROCEDURE InNotifier():BOOLEAN; (* pre true *) (* post a notifier call is in progress *) PROCEDURE AddEntry(IN n:name:Name;f:Files.file(); (* pre (not InNotifier() and n<>”” and f<>NIL *) (* post ThisFile(n) = f *) PROCEDURE RemoveEntry(IN n:Name); (* pre not InNotifier() *) (* post ThisFile(n)=NIL *) Example: Java security manager use test function to protect critical services from being called by untrusted services. 31/12/2018 Seminarium CBSE

Callbacks in objects We can structure an application in layers. Object can references other objects on different layers: Above the referenced object Method invocation = regular call Below the referenced object Method invocation = up-call Every method invoked as an up-call is a possible callback. 31/12/2018 Seminarium CBSE

A text processing example A text model is a sequence of characters that supports random access to read,insert and delete characters Text observers can register with the model and will be notified whenever a character is inserted or deleted A text viewer extends an observer and provides visualization 31/12/2018 Seminarium CBSE

The TextModel INTERFACE TextModel method max(): int; //pre true method write(int pos,char ch); //[len:int;txt:array of char; //pre len=this.length(); (all i:0<=i<len:txt[i]:=this.read(i)) and len< this.max() and 0<=pos<=len //post this.length() = len +1 and (all i:0<=i<=len:this.read(i):=txt[i]) and this.read(pos) = ch and (all i: pos<=i<=this.length(): this.read(i)=txt[i-1] method delete(int pos); // delete char at pos pos and shift all successive char back to one method max(): int; //pre true //post result=maximum length this text instance can have method length():int //post 0<=result<=this.max() and result=length of text method read(int pos):char; //pre 0<=pos<=this.length() //post result=character at position pos method register(TextObserver x); method unregister(TextObserver x); 31/12/2018 Seminarium CBSE

The TextObserver and TextView INTERFACE TextObserver method insertNotification(int pos); //pre character at position pos has just been inserted method deleteNotification(int pos); //pre character that was at position pos has been deleted INTERFACE TextView EXTENDS TextObserver method text():TextModel //pre true //post result <> null method caretPos():int //post 0<=result<=this.text().length() method type(char ch) //pre caret:=this.caretPos():this.text().length() < this.text().max() //post this.caretPos()=caret+1 and post(this.text().write(caret,ch)) method setCaret(int pos); //pre 0<=pos<=this.text().length() //post this.caretPos()=pos method posFromCoord(int x,int y); //pre (x,y) is valid screen coordinate //post result=x,y-coordinates corresponding to text position pos method insertNotification(int pos); //post display updated and this.caretPos()=pos+1 method deleteNotification(int pos); //post display updated and this.caretPos()=pos 31/12/2018 Seminarium CBSE

Inserting a character Any callback? Text Model Text View Client Display Write insertNotification (Remove caret mark) (Update text display) (Redisplay caret mark) 31/12/2018 Seminarium CBSE

Inserting a character (revised) Text View Text Model It reflects better the situation: TextView depends on the state of TextModel See method Type Client Display Write insertNotification (Remove caret mark) (Update text display) (Redisplay caret mark) 31/12/2018 Seminarium CBSE

Inter-object consistency Control is transferred to other objects while still updating. In the example: Display calls TextView’s map methods But they can be called by other objects too! Multiple observers could be registered Which one gains control of display? Consistency can be achieved by a disciplined programming semaphores synchronized methods monitors 31/12/2018 Seminarium CBSE

Intra-object consistency The real problem: Re-entrance Re-entrance = an object method is invoked while another is still executing. Methods have the right to change the state of their object, but what if it is called on an object that is not in a consistent state? 31/12/2018 Seminarium CBSE

Object re-entrance Class Store var size:Int := 0 rep :Repository method insert(elm int); size:= size+1 rep.add(elm) method check (max) if size < max return true method notify(repository:Repository):Store rep:= repository rep.register(self) Class Repository mystore :Store max = 100 method register(store) mystore:= store method add (elm) if store.check(max) then // code for adding elm to repository User myStore Display Notify(myrepository) Insert(elm) (add(elm) check(max) (Redisplay caret mark) 31/12/2018 Seminarium CBSE

Re-entrance (continued) MyStore in in inconsistent state when the message check(max) is received Obvious solution: Switch the command lines size:= size+1 rep.add(elm) in the code of method insert(elm int) It requires inspection of code, but components must be independently verifiable based on their contracts at interfaces 31/12/2018 Seminarium CBSE

Self-interference & re-entrance Leads to inconsistent object state Re-entrance is necessary Recursive calls (direct or indirect) As for callbacks it can be addressed by: Introducing test functions for clients Adding time-stamps to the state Allowing histories of communication in specification Not using method invocation 31/12/2018 Seminarium CBSE

Multithreading and re-entrance Locking doesn’t solve the re-entrance problem When strict re-entrance is solved, but leads to self-inflicted deadlocks When relaxed(as in Java), suffers by re-entrance as in single threaded systems 31/12/2018 Seminarium CBSE

Histories Alternative to specification contracts Histories are sequences of messages Restricting the permissible traces we can get valid state transitions Permissible traces are hard to be checked dynamically 31/12/2018 Seminarium CBSE

Without method invocation Explicit dependencies between state and events Remember UML state machine obj!recall(book) obj?borrow(book) book on the shelf book on loan by obj obj?return(book) 31/12/2018 Seminarium CBSE