introduction to design patterns for middleware · introduction to design patterns for middleware 2...

46
Introduction to design patterns for middleware Denis Conan CCN/CSC7321 octobre 2019 Revision : 545

Upload: others

Post on 13-Feb-2020

16 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Introduction to design patterns for middleware · Introduction to design patterns for middleware 2 Design patterns # 14 2.4 Writing patterns Name : Higher abstraction which conveys

# 1

Introduction to designpatterns for middleware

Denis Conan

CCN/CSC7321octobre 2019

Revision : 545

Page 2: Introduction to design patterns for middleware · Introduction to design patterns for middleware 2 Design patterns # 14 2.4 Writing patterns Name : Higher abstraction which conveys

Introduction to design patterns for middleware

# 2

Foreword

■ The sources of this presentation are :♦ S. Krakowiak (Université Joseph Fourier), “Patrons et canevas pour

l’intergiciel”, ICAR 2006 French Speaking Summer School on Middleware andConstruction of Distributed Applications, Autrans, France, August 2006.▶ URL of the slides in French :

http://sardes.inrialpes.fr/ecole/2006/ICAR-06-Intro.pdf

♦ S. Krakowiak “Chapitre 1 : Introduction à l’intergiciel” dans “Intergiciel etConstruction d’Applications Réparties”, 2006,http://sardes.inrialpes.fr/ecole/livre/pub/Chapters/Intro/intro.html

♦ S. Krakowiak “Chapitre 2 : Patrons et canevas pour l’intergiciel” dans“Intergiciel et Construction d’Applications Réparties”, 2006,http://sardes.inrialpes.fr/ecole/livre/pub/Chapters/Patterns/patterns.html

♦ S. Krakowiak “Middleware Architecture with Patterns and Frameworks”,2007, http://sardes.inrialpes.fr/~krakowiak/MW-Book/ (see the first twochapters)

Télécom SudParis — INF — octobre 2019 — CCN/CSC7321 2/46

Page 3: Introduction to design patterns for middleware · Introduction to design patterns for middleware 2 Design patterns # 14 2.4 Writing patterns Name : Higher abstraction which conveys

Introduction to design patterns for middleware

# 3

♦ E. Gamma, R. Helm, R. Johnson, J. Vlissides “Design Patterns : Elements ofReusable Object-Oriented Software”, Addison-Wesley, 1994▶ Has been translated in French

♦ F. Buschmann, R. Meunier, H. Rohnert, P. Sommerlad and M. Stal“Pattern-Oriented Software Architecture : Volume 1, A System of Patterns”,Wiley, 1996

♦ D.C. Schmidt, M. Stal, H. Rohnert and F. Buschmann “Pattern-OrientedSoftware Architecture, Volume 2, Patterns for Concurrent and NetworkedObjects”, Wiley, 2000.

♦ Buschmann, K. Henney and D.C. Schmidt “Pattern-Oriented SoftwareArchitecture, Volume 4, A Pattern Language for Distributed Computing”,Wiley, 2007

Télécom SudParis — INF — octobre 2019 — CCN/CSC7321 3/46

Page 4: Introduction to design patterns for middleware · Introduction to design patterns for middleware 2 Design patterns # 14 2.4 Writing patterns Name : Higher abstraction which conveys

Introduction to design patterns for middleware

# 4

Outline

1 Distributed system organisation with a middleware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52 Design patterns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 Patterns for distributed interaction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164 Patterns for composition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 315 Patterns for coordination . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41

Télécom SudParis — INF — octobre 2019 — CCN/CSC7321 4/46

Page 5: Introduction to design patterns for middleware · Introduction to design patterns for middleware 2 Design patterns # 14 2.4 Writing patterns Name : Higher abstraction which conveys

Introduction to design patterns for middleware

# 5

1 Distributed system organisation with a middleware

Application Application Application Application

OperatingSystem

OperatingSystem

OperatingSystem

OperatingSystem

Standard dataprotocol

Communication subsystem / Network

Specific API

Standard APIStandard API

Specific API

Middleware

Télécom SudParis — INF — octobre 2019 — CCN/CSC7321 5/46

Page 6: Introduction to design patterns for middleware · Introduction to design patterns for middleware 2 Design patterns # 14 2.4 Writing patterns Name : Higher abstraction which conveys

Introduction to design patterns for middleware

# 6

2 Design patterns

2.1 Objectives of the pattern orientation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72.2 Some design pattern examples for middleware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82.3 Definition of design patterns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132.4 Writing patterns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142.5 Classifying patterns. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .15

Télécom SudParis — INF — octobre 2019 — CCN/CSC7321 6/46

Page 7: Introduction to design patterns for middleware · Introduction to design patterns for middleware 2 Design patterns # 14 2.4 Writing patterns Name : Higher abstraction which conveys

Introduction to design patterns for middleware 2 Design patterns

# 7

2.1 Objectives of the pattern orientation

Each pattern describes a problem that occurs over and over again in our environment,and then describes the core of the solution to that problem, in such a way that you canuse this solution a million times over, without ever doing it the same way twice. a

■ Present the design principles of middleware architecture in a systematic way♦ Identify the main design and implementation problems♦ Exhibit the main design solutions relevant to middleware construction♦ Illustrate the patterns in frameworks in the teaching unit

■ Well known software design patterns :♦ Factory♦ Singleton♦ Iterator

a. Alexander, Christopher (1977). A Pattern Language : Towns, Buildings, Construction. OxfordUniversity Press.

Télécom SudParis — INF — octobre 2019 — CCN/CSC7321 7/46

Page 8: Introduction to design patterns for middleware · Introduction to design patterns for middleware 2 Design patterns # 14 2.4 Writing patterns Name : Higher abstraction which conveys

Introduction to design patterns for middleware 2 Design patterns

# 8

2.2 Some design pattern examples for middleware

2.2.1 Example 1 : A client/server middleware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92.2.2 Example 2 : Integration of legacy applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102.2.3 Example 3 : Adaptation to client resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112.2.4 Example 4 : Monitoring and control of networked equipments . . . . . . . . . . . . . . . . . 12

Télécom SudParis — INF — octobre 2019 — CCN/CSC7321 8/46

Page 9: Introduction to design patterns for middleware · Introduction to design patterns for middleware 2 Design patterns # 14 2.4 Writing patterns Name : Higher abstraction which conveys

2 Design patterns 2.2 Some design pattern examples for middleware

# 9

2.2.1 Example 1 : A client/server middleware

Pre−compiler

IDL

NameServer

ServerClient

client stub (RPC)stub (CORBA)proxy (DCOM)

server stub (RPC)skeleton (CORBA)stub (DCOM)

Binding object

... ...

Binding

Factory

Session

Télécom SudParis — INF — octobre 2019 — CCN/CSC7321 9/46

Page 10: Introduction to design patterns for middleware · Introduction to design patterns for middleware 2 Design patterns # 14 2.4 Writing patterns Name : Higher abstraction which conveys

2 Design patterns 2.2 Some design pattern examples for middleware

# 10

2.2.2 Example 2 : Integration of legacy applications

New

component

Legacy

application

Legacy

application

Legacy

application

New

component

proprietary

interface

standard

interface

standard

interfaceInter−applications "exchange bus"

Wrapper Wrapper

Wrapper

Télécom SudParis — INF — octobre 2019 — CCN/CSC7321 10/46

Page 11: Introduction to design patterns for middleware · Introduction to design patterns for middleware 2 Design patterns # 14 2.4 Writing patterns Name : Higher abstraction which conveys

2 Design patterns 2.2 Some design pattern examples for middleware

# 11

2.2.3 Example 3 : Adaptation to client resources

Proxy

Télécom SudParis — INF — octobre 2019 — CCN/CSC7321 11/46

Page 12: Introduction to design patterns for middleware · Introduction to design patterns for middleware 2 Design patterns # 14 2.4 Writing patterns Name : Higher abstraction which conveys

2 Design patterns 2.2 Some design pattern examples for middleware

# 12

2.2.4 Example 4 : Monitoring and control of networkedequipments

■ Physical organisation ■ Logical organisation

Message bus

Télécom SudParis — INF — octobre 2019 — CCN/CSC7321 12/46

Page 13: Introduction to design patterns for middleware · Introduction to design patterns for middleware 2 Design patterns # 14 2.4 Writing patterns Name : Higher abstraction which conveys

Introduction to design patterns for middleware 2 Design patterns

# 13

2.3 Definition of design patterns

■ Definition (not limited to program design)♦ A set of design rules (element definitions, element composition principles,

rules of usage) that allow the designer to answer a class of specific needs in aspecific environment

■ Properties♦ Elaborated from the experience acquired : Class of problems, capture of the

solution elements common to those problems♦ Defines design principles, not specific to the implementation♦ Provides an aid to documentation : Common terminology, even formal

description (“pattern language”)

Télécom SudParis — INF — octobre 2019 — CCN/CSC7321 13/46

Page 14: Introduction to design patterns for middleware · Introduction to design patterns for middleware 2 Design patterns # 14 2.4 Writing patterns Name : Higher abstraction which conveys

Introduction to design patterns for middleware 2 Design patterns

# 14

2.4 Writing patterns

■ Name : Higher abstraction which conveys the essence of the pattern succinctly■ Intent : Short statement stating what the pattern does, its rationale, and the

particular design issue or problem addressed■ Motivation and context : Scenario illustrating the class of problems addressed ;

should be as generic as possible■ Problem : Requirements, desirable properties of the solution ; constraints of the

environment■ Solution

♦ Structure : Static aspects, i.e. components, relationships ; may be depicted ina classes/components diagram

♦ Interactions : Dynamic aspects, i.e. run-time behaviour, life-cycle ; may bedepicted in a communications/sequence/timing diagram

■ Also known as & related patterns : Other well-known names & closely relatedpatterns

Télécom SudParis — INF — octobre 2019 — CCN/CSC7321 14/46

Page 15: Introduction to design patterns for middleware · Introduction to design patterns for middleware 2 Design patterns # 14 2.4 Writing patterns Name : Higher abstraction which conveys

Introduction to design patterns for middleware 2 Design patterns

# 15

2.5 Classifying patterns

■ Architectural : Large scale, structural organisation, subsystems and relationshipsbetween them

■ Design : Small scale, commonly recurring structure within a particular context■ Idioms : Language specific, how to implement a particular aspect in a given

language■ And many more : Software process, requirement elicitation, analysis, etc.

Télécom SudParis — INF — octobre 2019 — CCN/CSC7321 15/46

Page 16: Introduction to design patterns for middleware · Introduction to design patterns for middleware 2 Design patterns # 14 2.4 Writing patterns Name : Higher abstraction which conveys

Introduction to design patterns for middleware

# 16

3 Patterns for distributed interaction

3.1 Asynchronous call, synchronous call, buffered message. . . . . . . . . . . . . . . . . . . . . . . . . .173.2 Call-back and Inversion of control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183.3 Reflection : Observe and act on its own state and behaviour . . . . . . . . . . . . . . . . . . . . 193.4 Factory : Entity creation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213.5 Proxy : Representative for remote access . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233.6 Wrapper or Adapter : Interface transformation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 253.7 Interceptor : Adaptable service provision . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 273.8 Similarities and differences between the previous patterns . . . . . . . . . . . . . . . . . . . . . . . 29

Télécom SudParis — INF — octobre 2019 — CCN/CSC7321 16/46

Page 17: Introduction to design patterns for middleware · Introduction to design patterns for middleware 2 Design patterns # 14 2.4 Writing patterns Name : Higher abstraction which conveys

Introduction to design patterns for middleware 3 Patterns for distributed interaction

# 17

3.1 Asynchronous call, synchronous call, buffered message

a:Process

request

b:Process

requesthandler

reply

Synchronous call

wait

a:Process

send msg 3

send msg 2

send msg 1deliver msg 1

deliver msg 2

deliver msg 3

Systemm:MsgPassing

ask for a msg

ask for a msg

ask for a msg

a:Process

event/message

b:Process

event/messagehandler

b:Process

wait

Buffered messagesAsynchronous event(push) (pull)

Télécom SudParis — INF — octobre 2019 — CCN/CSC7321 17/46

Page 18: Introduction to design patterns for middleware · Introduction to design patterns for middleware 2 Design patterns # 14 2.4 Writing patterns Name : Higher abstraction which conveys

Introduction to design patterns for middleware 3 Patterns for distributed interaction

# 18

3.2 Call-back and Inversion of control

A:ProcessA:Process B:ProcessB:Process

callbackcallback

controlled by Bservice request for A

The service request for Ais triggered from the outsidethrough B, which controls A

service request

result

Inversion of controlSynchronous call with callback

A callback is first registeredand later called asynchronously.

The control flow is no more under the responsability ofthe application but controlled by the framework.

Télécom SudParis — INF — octobre 2019 — CCN/CSC7321 18/46

Page 19: Introduction to design patterns for middleware · Introduction to design patterns for middleware 2 Design patterns # 14 2.4 Writing patterns Name : Higher abstraction which conveys

Introduction to design patterns for middleware 3 Patterns for distributed interaction

# 19

3.3 Reflection : Observe and act on its own state and behaviour

■ Context : Support different types of variations/adaptations of an application■ Problem : Particular variations must be hidden to the client■ Solution

♦ Make the system self-aware▶ Select aspects of its structure and behaviour accessible for adaptation

⋆ Objectify/reify information about properties and variant aspects of theapplication’s structure, behaviour, and state into a set of meta-objects

♦ Split the architecture into two major parts▶ Meta-level : Self-representation of the system in meta-objects

⋆ Type structures, algorithms, or even function call mechanisms▶ Base level : Application logic

⋆ Uses the meta-objects to remain independent of those aspects thatchange

♦ An interface is specified for manipulating the meta-objects▶ Meta-Object Protocol responsible for performing changes

Télécom SudParis — INF — octobre 2019 — CCN/CSC7321 19/46

Page 20: Introduction to design patterns for middleware · Introduction to design patterns for middleware 2 Design patterns # 14 2.4 Writing patterns Name : Higher abstraction which conveys

Introduction to design patterns for middleware 3 Patterns for distributed interaction

# 20

■ Architecture principle

Client ObjectA MetaObjectA

1 2

483,75,6

Client MetaObjectA

1

7

ObjectA

2

63

4

MetaObject

Factory

5

Télécom SudParis — INF — octobre 2019 — CCN/CSC7321 20/46

Page 21: Introduction to design patterns for middleware · Introduction to design patterns for middleware 2 Design patterns # 14 2.4 Writing patterns Name : Higher abstraction which conveys

Introduction to design patterns for middleware 3 Patterns for distributed interaction

# 21

3.4 Factory : Entity creation

■ Context : Applications organised as a set of distributed entities■ Problem

♦ Dynamically create multiple instances of an entity type♦ Desirable properties

▶ Instances should be parameterised▶ Evolution should be easy, i.e. no hard-coded decisions

♦ Constraints : Distributed environment, i.e. no single address space■ Solution

♦ Abstract factory : Defines a generic interface and organisation for creatingentities ; the actual creation is deferred to concrete factories that actuallyimplement the creation methods

♦ A further degree of flexibility is achieved by using Factory Factory, that is thecreation mechanism itself is parameterised

Télécom SudParis — INF — octobre 2019 — CCN/CSC7321 21/46

Page 22: Introduction to design patterns for middleware · Introduction to design patterns for middleware 2 Design patterns # 14 2.4 Writing patterns Name : Higher abstraction which conveys

3 Patterns for distributed interaction 3.4 Factory : Entity creation

# 22

3.4.1 Sequence diagram of Factory

ff:FactoryFactory

f:Factory

s:Servant

request for creation

returnservant’s reference

create

optional

c:Client

request for removal

create

remove

optional

Télécom SudParis — INF — octobre 2019 — CCN/CSC7321 22/46

Page 23: Introduction to design patterns for middleware · Introduction to design patterns for middleware 2 Design patterns # 14 2.4 Writing patterns Name : Higher abstraction which conveys

Introduction to design patterns for middleware 3 Patterns for distributed interaction

# 23

3.5 Proxy : Representative for remote access

■ Context : A client needs access to the services by some entity (the “servant”)■ Problem

♦ Define an access mechanism that does not involve▶ Hard-coding the location of the servant into the client code▶ Deep knowledge of the communication protocols by the client

♦ Desirable properties▶ Access should be efficient at run-time and secure▶ Programming should be simple : No difference between local and remote

access♦ Constraints : Distributed environment (no single address space)

■ Solutions♦ Use a local representative of the server on the client side that isolates the

client from the communication system and the servant♦ Keep the same interface for the representative as for the servant♦ Define a uniform proxy structure to facilitate automatic generation

Télécom SudParis — INF — octobre 2019 — CCN/CSC7321 23/46

Page 24: Introduction to design patterns for middleware · Introduction to design patterns for middleware 2 Design patterns # 14 2.4 Writing patterns Name : Higher abstraction which conveys

3 Patterns for distributed interaction 3.5 Proxy : Representative for remote access

# 24

3.5.1 Sequence diagram of Proxy

s:Servant

service request

c:Client p:Proxy

service request

result

pre−processing

e.g., marshalling

post−processing

result

e.g., unmarshalling

Interface I

Télécom SudParis — INF — octobre 2019 — CCN/CSC7321 24/46

Page 25: Introduction to design patterns for middleware · Introduction to design patterns for middleware 2 Design patterns # 14 2.4 Writing patterns Name : Higher abstraction which conveys

Introduction to design patterns for middleware 3 Patterns for distributed interaction

# 25

3.6 Wrapper or Adapter : Interface transformation

■ Context : Clients requesting services ; servers providing services ; services definedby interfaces

■ Problem♦ Reuse an existing server by modifying either its interface or some of its

functions in order to satisfy the needs of a client (or class of clients)♦ Desirable properties : Should be run-time efficient ; should be adaptable

because the needs may change and may not be anticipated ; should be itselfreusable (generic)

■ Solutions♦ The wrapper screens the server by intercepting method calls to its interface♦ Each call is prefixed by a prologue and followed by an epilogue in the wrapper♦ The parameters and results may need to be converted

Télécom SudParis — INF — octobre 2019 — CCN/CSC7321 25/46

Page 26: Introduction to design patterns for middleware · Introduction to design patterns for middleware 2 Design patterns # 14 2.4 Writing patterns Name : Higher abstraction which conveys

3 Patterns for distributed interaction 3.6 Wrapper or Adapter : Interface transformation

# 26

3.6.1 Sequence diagram of Wrapper/Adapter

s:Servant

service request

c:Client w:Wrapper

service request 2

result 2

result

Interface I1

Interface I2

pre−processing

post−processing

Télécom SudParis — INF — octobre 2019 — CCN/CSC7321 26/46

Page 27: Introduction to design patterns for middleware · Introduction to design patterns for middleware 2 Design patterns # 14 2.4 Writing patterns Name : Higher abstraction which conveys

Introduction to design patterns for middleware 3 Patterns for distributed interaction

# 27

3.7 Interceptor : Adaptable service provision

■ Context : Service provision (in a general setting)♦ Client-server, peer-to-peer, high-level to low-level♦ May be uni- or bi-directional, synchronous or asynchronous

■ Problem♦ Transform the service (adding new treatments), by different means

▶ Interposing a new layer of processing (like wrapper)▶ Changing the destination (may be conditional)

♦ Constraints : Services may be added/removed dynamically■ Solutions

♦ Create interposition entities (statically or dynamically). These entities▶ Intercept calls (and/or return statements) and insert specific processing,

that may be based on content analysis▶ May redirect call to a different target▶ May use call-backs

Télécom SudParis — INF — octobre 2019 — CCN/CSC7321 27/46

Page 28: Introduction to design patterns for middleware · Introduction to design patterns for middleware 2 Design patterns # 14 2.4 Writing patterns Name : Higher abstraction which conveys

3 Patterns for distributed interaction 3.7 Interceptor : Adaptable service provision

# 28

3.7.1 Sequence diagram of Interceptor

si:SupportingInfrastructure

createc:Client

create

s:Servant

i:Interceptor

service requestInterface I

Interface I

use service

callback

result

Télécom SudParis — INF — octobre 2019 — CCN/CSC7321 28/46

Page 29: Introduction to design patterns for middleware · Introduction to design patterns for middleware 2 Design patterns # 14 2.4 Writing patterns Name : Higher abstraction which conveys

Introduction to design patterns for middleware 3 Patterns for distributed interaction

# 29

3.8 Similarities and differences between the previous patterns

■ Wrapper Vs. Proxy♦ Wrapper and Proxy have a similar structure

▶ Proxy preserves the interfacesVs. Wrapper transforms the interface

▶ Proxy often (not always) involves remote accessVs. Wrapper is usually on-site

■ Wrapper Vs. Interceptor♦ Wrapper and Interceptor have a similar function which is behavioural

reflection▶ Wrapper transforms the interface

Vs. Interceptor transforms the functionality (may completely screenservant)

■ Reflection Vs. Interceptor♦ Interceptor provides a means to implement reflective mechanisms

▶ Not the only way to implement reflection (others = language, byte codetransformation, etc.)

Télécom SudParis — INF — octobre 2019 — CCN/CSC7321 29/46

Page 30: Introduction to design patterns for middleware · Introduction to design patterns for middleware 2 Design patterns # 14 2.4 Writing patterns Name : Higher abstraction which conveys

Introduction to design patterns for middleware 3 Patterns for distributed interaction

# 30

▶ Interceptor exposes only part of the state of the base level♦ Reflection can define a type of interception mechanism in the form of a

meta-object protocol

Télécom SudParis — INF — octobre 2019 — CCN/CSC7321 30/46

Page 31: Introduction to design patterns for middleware · Introduction to design patterns for middleware 2 Design patterns # 14 2.4 Writing patterns Name : Higher abstraction which conveys

Introduction to design patterns for middleware

# 31

4 Patterns for composition

4.1 Principle of de/composition in distribution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 324.2 Contract : Qualified required/offered interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 334.3 Layer or Abstract machine or Protocol stack : Vertical decomposition . . . . . . . . . . . 344.4 Multi-tier architecture : Horizontal decomposition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 354.5 Component/Container : Contract + Factory + Interceptor + extra-functionalities384.6 Composite with sharing : Component + Vertical decomposition + Sharing . . . . . . 39

Télécom SudParis — INF — octobre 2019 — CCN/CSC7321 31/46

Page 32: Introduction to design patterns for middleware · Introduction to design patterns for middleware 2 Design patterns # 14 2.4 Writing patterns Name : Higher abstraction which conveys

Introduction to design patterns for middleware 4 Patterns for composition

# 32

4.1 Principle of de/composition in distribution

■ Objective♦ Ease the design

▶ Show the design approach through the means of the structure▶ Show off the interfaces and the dependencies

♦ Ease the evolution▶ Apply the encapsulation principle▶ Standardise the exchanges

■ Examples♦ Multi-level structure

▶ “Vertical” decomposition : e.g., LayerVs. “horizontal” decomposition : e.g. Multi-tierVs. both of them : e.g. Middle-tier/Component

♦ Leverage the concept of Contract▶ From “simple” interfaces to

Offered/server, required/client, and internal and external interfaces

Télécom SudParis — INF — octobre 2019 — CCN/CSC7321 32/46

Page 33: Introduction to design patterns for middleware · Introduction to design patterns for middleware 2 Design patterns # 14 2.4 Writing patterns Name : Higher abstraction which conveys

Introduction to design patterns for middleware 4 Patterns for composition

# 33

4.2 Contract : Qualified required/offered interfaces

Contract

ServerClient

Client/required Server/providedinterfaceinterface

conformance

■ Four levels of contract

1. Syntactic contract : Types of operations, verified statically

2. Behavioural contract : Dynamic behaviour (semantics) of operations,assertion-based

3. Synchronisation contract : Interactions between operations, synchronisation

4. Quality of service contract : extra-functional aspects such as performance,availability, security

Télécom SudParis — INF — octobre 2019 — CCN/CSC7321 33/46

Page 34: Introduction to design patterns for middleware · Introduction to design patterns for middleware 2 Design patterns # 14 2.4 Writing patterns Name : Higher abstraction which conveys

Introduction to design patterns for middleware 4 Patterns for composition

# 34

4.3 Layer or Abstract machine or Protocol stack : Verticaldecomposition

■ Context : Complex “local” system design■ Problem : Define different levels of abstraction/refinement■ Solution : Vertical decomposition with levels, and upper and lower interfaces

Level I+1

Level I

Level I−1

Base level

Interface I−1

Interface I

interface I−1

Downcall

interface I

Upcall

Télécom SudParis — INF — octobre 2019 — CCN/CSC7321 34/46

Page 35: Introduction to design patterns for middleware · Introduction to design patterns for middleware 2 Design patterns # 14 2.4 Writing patterns Name : Higher abstraction which conveys

Introduction to design patterns for middleware 4 Patterns for composition

# 35

4.4 Multi-tier architecture : Horizontal decomposition

■ Context : Complex distributed system ; incremental upgrade■ Problem : Evolution of the client and the server sides, load-balancing, scalability■ Solution : Horizontal decomposition into tiers, separation of system functionalities

ApplicationData

managementinterface

User

(c)

ApplicationData

management

(a)

Applicationinterface

User Datamanagement

(b)

Télécom SudParis — INF — octobre 2019 — CCN/CSC7321 35/46

Page 36: Introduction to design patterns for middleware · Introduction to design patterns for middleware 2 Design patterns # 14 2.4 Writing patterns Name : Higher abstraction which conveys

4 Patterns for composition 4.4 Multi-tier architecture : Horizontal decomposition

# 36

4.4.1 Focus on presentation tier : The MVC pattern

■ Context : Management of the client view or user interface■ Problem : Confusion in the roles of objects prevents evolution.■ Solution : Separate the data (Model), the HMI on screen (View) and the control

logic (Controller) which is the glue between the two■ Proposed in 1978-79 by Trygve Reenskaug et al. from XEROX PARC for the

Smalltalk language

Télécom SudParis — INF — octobre 2019 — CCN/CSC7321 36/46

Page 37: Introduction to design patterns for middleware · Introduction to design patterns for middleware 2 Design patterns # 14 2.4 Writing patterns Name : Higher abstraction which conveys

4 Patterns for composition 4.4 Multi-tier architecture : Horizontal decomposition

# 37

4.4.2 MVC pattern vs 3-tier architecture

■ MVC pattern♦ Focus on the presentation layer to improve code evolutivity♦ Triangular architecture : The view sends updates to the controller, the

controller updates the model, and the view gets updated directly from themodel.

■ vs 3-tier architecture style♦ Focus on the distribution of the architecture to favor scalability♦ Linear architecture : The presentation tier never communicates directly with

the data tier. Communication goes through the middle tier.

Télécom SudParis — INF — octobre 2019 — CCN/CSC7321 37/46

Page 38: Introduction to design patterns for middleware · Introduction to design patterns for middleware 2 Design patterns # 14 2.4 Writing patterns Name : Higher abstraction which conveys

Introduction to design patterns for middleware 4 Patterns for composition

# 38

4.5 Component/Container : Contract + Factory + Interceptor+ extra-functionalities

■ Context : Distributed application accessing extra-functional services■ Problem : Control life-cycle ; separate business/extra-functional parts■ Solution :

♦ Contract to make explicit server and client interfaces♦ Container that implement Factory + Interceptor to manage extra-functional

services

Client Component

Access to extra−functional services: transaction, security, etc.

service request

Server interface

Container/MembraneConfiguration

Interceptor Interceptor

Client interface

life−cycle

Télécom SudParis — INF — octobre 2019 — CCN/CSC7321 38/46

Page 39: Introduction to design patterns for middleware · Introduction to design patterns for middleware 2 Design patterns # 14 2.4 Writing patterns Name : Higher abstraction which conveys

Introduction to design patterns for middleware 4 Patterns for composition

# 39

4.6 Composite with sharing : Component + Verticaldecomposition + Sharing

■ Context♦ Part-whole hierarchies of components

■ Problem♦ Make the client simple

▶ Ignore the difference between composite entities and individualcomponents

♦ A component can have more than one parent♦ Make it easier to add new kinds of components♦ Make the design overly general

■ Solution♦ Abstract component entity which represents both a primitive or a composite♦ Control the content of composite components♦ Extend the reference/naming system to explicitly express sharing

Télécom SudParis — INF — octobre 2019 — CCN/CSC7321 39/46

Page 40: Introduction to design patterns for middleware · Introduction to design patterns for middleware 2 Design patterns # 14 2.4 Writing patterns Name : Higher abstraction which conveys

4 Patterns for composition 4.6 Composite with sharing : Component + Vertical decomposition + Sharing

# 40

4.6.1 Example of the Fractal Component Model

■ É. Bruneton, T. Coupaye, M. Leclercq, V. Quéma, and J.-B. Stéfani “The FractalComponent Model and Its Support in Java” Software–Practice and Experience,36(11), pp. 1257–1284, September 2006

membranecontroller

interfacesclient server

componentsub−

comp.

sharedcomp.

primitive

component

composite

Télécom SudParis — INF — octobre 2019 — CCN/CSC7321 40/46

Page 41: Introduction to design patterns for middleware · Introduction to design patterns for middleware 2 Design patterns # 14 2.4 Writing patterns Name : Higher abstraction which conveys

Introduction to design patterns for middleware

# 41

5 Patterns for coordination

5.1 Naming : White pages service . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 425.2 Trading : Yellow pages service . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 435.3 Publish/subscribe or Observer or Event channel : Change-propagation mechanism445.4 Pipes and filters : Structure for processing streams of data . . . . . . . . . . . . . . . . . . . . . 46

Télécom SudParis — INF — octobre 2019 — CCN/CSC7321 41/46

Page 42: Introduction to design patterns for middleware · Introduction to design patterns for middleware 2 Design patterns # 14 2.4 Writing patterns Name : Higher abstraction which conveys

Introduction to design patterns for middleware 5 Patterns for coordination

# 42

5.1 Naming : White pages service

■ Context : clients and servers distributed over the network■ Problem

♦ Obtain a (distributed) reference to an entity♦ Only the logical name is known by the client

■ Solution♦ The server registers its reference under a logical name to a name server♦ The name server has a “well-known” reference♦ The client retrieves the server’s reference by providing the logical name♦ Logical names are organised as a hierarchy

ServerClient

NamingContext

NameServerA

NamingContext

NameServerB

service request

resolve()

resolve() register()

Télécom SudParis — INF — octobre 2019 — CCN/CSC7321 42/46

Page 43: Introduction to design patterns for middleware · Introduction to design patterns for middleware 2 Design patterns # 14 2.4 Writing patterns Name : Higher abstraction which conveys

Introduction to design patterns for middleware 5 Patterns for coordination

# 43

5.2 Trading : Yellow pages service

■ Context : clients and servers distributed over the network■ Problem

♦ Obtain a (distributed) reference to an entity♦ Only a property characterising the server is known by the client : Service

name...■ Solution

♦ The client specifies its requets by providing properties of the required service♦ The trader answers by giving a set of server’s references matching the client’s

query

Server

Offers/properties Offers/properties

Client

TraderA TraderB

service request

query()

query() register()

Télécom SudParis — INF — octobre 2019 — CCN/CSC7321 43/46

Page 44: Introduction to design patterns for middleware · Introduction to design patterns for middleware 2 Design patterns # 14 2.4 Writing patterns Name : Higher abstraction which conveys

Introduction to design patterns for middleware 5 Patterns for coordination

# 44

5.3 Publish/subscribe or Observer or Event channel :Change-propagation mechanism

■ Context♦ Keep the state of cooperating components synchronised

■ Problem♦ Be notified about state changes in a particular entity♦ Number and identities of dependent entities not known a priori♦ Explicit polling not feasible or not efficient♦ Notifiers and notified entities not tightly coupled

■ Solution♦ Notifier also called publisher or subject : Maintains a registry of subscribers♦ Notified entities also called subscribers or observers : Subscribe to notification♦ Push model (publisher sends all changes)

Vs. pull model (publisher sends nature of data change and subscriber getsretrieves data)

Télécom SudParis — INF — octobre 2019 — CCN/CSC7321 44/46

Page 45: Introduction to design patterns for middleware · Introduction to design patterns for middleware 2 Design patterns # 14 2.4 Writing patterns Name : Higher abstraction which conveys

5 Patterns for coordination 5.3 Publish/subscribe or Observer or Event channel : Change-propagation mechanism

# 45

5.3.1 Example of OMG CORBA Event channel

OptionalprocessboundaryPublisher

Channel

Event

Optionalprocessboundary Subscriber

Subscriber

ProxyProxyPublisher Subscriber

ProxyProxyPublisher

Télécom SudParis — INF — octobre 2019 — CCN/CSC7321 45/46

Page 46: Introduction to design patterns for middleware · Introduction to design patterns for middleware 2 Design patterns # 14 2.4 Writing patterns Name : Higher abstraction which conveys

Introduction to design patterns for middleware 5 Patterns for coordination

# 46

5.4 Pipes and filters : Structure for processing streams of data

■ Context : Distributed application processing data streams■ Problem

♦ Flexibility by reordering/recombining processing steps♦ Small processing steps are easier to reuse in a different setting♦ Non-adjacent steps do not share information

■ Solution♦ Each processing step is encapsulated in a filter component♦ Data is passed through pipes between adjacent filters♦ Filters are the processing units of the pipeline

▶ Consume data incrementally to achieve low latency and enable parallelism♦ Push mode Vs. pull mode Vs. active mode (pull + push)

Télécom SudParis — INF — octobre 2019 — CCN/CSC7321 46/46