27
SS ZG653 Second Semester,2012-13 1 Topic Architectural Patterns Pipe and Filter

SS ZG653Second Semester,2012-13 1 Topic Architectural Patterns Pipe and Filter

Embed Size (px)

Citation preview

Page 1: SS ZG653Second Semester,2012-13 1 Topic Architectural Patterns Pipe and Filter

SS ZG653Second Semester,2012-13 1

Topic

Architectural Patterns Pipe and Filter

Page 2: SS ZG653Second Semester,2012-13 1 Topic Architectural Patterns Pipe and Filter

SS ZG653Second Semester,2012-13 2

PIPES & FILTERSMud to Structure

Page 3: SS ZG653Second Semester,2012-13 1 Topic Architectural Patterns Pipe and Filter

SS ZG653Second Semester,2012-13 3

Pipes and FiltersThe pipes and filters architectural pattern provides a structure for systems that process a stream of data. Each processing step is encapsulated in a filter component. Data is passed through pipes between adjacent filters. Recombining filters allows you to build families of related systems.

Page 4: SS ZG653Second Semester,2012-13 1 Topic Architectural Patterns Pipe and Filter

SS ZG653Second Semester,2012-13 4

Pipes and Filters• Type of Data Flow Architecture• Filter is a component and pipe is a connector• Filter has interfaces from which a set of inputs can flow

in and a set of outputs can flow out.• Incremental transformation of data by successive

components.• All data does not need to be processed for next filter to

start working.• Any set of filters may be combined in any order,

although reasonable semantics are not guaranteed by this style.

Page 5: SS ZG653Second Semester,2012-13 1 Topic Architectural Patterns Pipe and Filter

SS ZG653Second Semester,2012-13 5

Pipes and FiltersFilter • Independent entities• Does not share state with other filters.• Do not know the identity to upstream and

downstream filters.Pipes• Stateless data stream• Source end feeds filter input and sink receives output.

Page 6: SS ZG653Second Semester,2012-13 1 Topic Architectural Patterns Pipe and Filter

SS ZG653Second Semester,2012-13 6

Pipes and Filters

Lexical Analyzer

Parser

Source File

ASCII Text

Token Stream

Semantic Analysis

Abstract Syntax Tree

Code Generator

Augmented Abstract Syntax Tree

Optimizer

Object Code

Object File

Optimized Object Code

Page 7: SS ZG653Second Semester,2012-13 1 Topic Architectural Patterns Pipe and Filter

SS ZG653Second Semester,2012-13 7

Pipes and Filters• Compilers• Various “translation” systems

Page 8: SS ZG653Second Semester,2012-13 1 Topic Architectural Patterns Pipe and Filter

SS ZG653Second Semester,2012-13 8

Pipes and Filters – 3 part schemaPattern

Context Processing Data StreamsProblem System that must process or transform a stream of input

data.Expect flexibility by exchanging or reordering the processing steps. Possible to build family of such systems.• Future enhancements – exchange processing steps or

recombination• Small processing steps – aid reuse• Non adjacent processing steps do not share information• Different sources of data exist• Store final result in various ways• Explicit storage of intermediate results should be

transparent to users – is error prone if done by users• Multiprocessing the steps

Solution Pipes and filters – data source to data sink

Page 9: SS ZG653Second Semester,2012-13 1 Topic Architectural Patterns Pipe and Filter

SS ZG653Second Semester,2012-13 9

Pipes and Filters• Filter component is a

processing units of the pipeline

• Enriches, refines or transforms its input data

• Enriches – computing and adding information

• Refine – concentrating or extracting information

• Transforms – delivering data in some other representation

ClassFilter

Responsibility• Gets inputs data• Performs a

function on its input data

• Supplies output data

Collaborators• Pipe

Page 10: SS ZG653Second Semester,2012-13 1 Topic Architectural Patterns Pipe and Filter

SS ZG653Second Semester,2012-13 10

Pipes and Filters• Pipe denotes connection

between filters• Data source and first filter• Last filter and Data sink• Synchronises two active

component

ClassPipe

Responsibility• Transfers data• Buffers data• Synchronizes

active neighbors

Collaborators• Data Source• Data Sink• Filter

Page 11: SS ZG653Second Semester,2012-13 1 Topic Architectural Patterns Pipe and Filter

SS ZG653Second Semester,2012-13 11

Pipes and Filters• Data source represents input

to the system• Sequence of data of the

same structure or type

ClassData Source

Responsibility• Delivers input to

processing pipeline

Collaborators• Pipe

Page 12: SS ZG653Second Semester,2012-13 1 Topic Architectural Patterns Pipe and Filter

SS ZG653Second Semester,2012-13 12

Pipes and Filters• Data sink collects results

from end of the pipeline• Active: pulls results from

preceding processing stage• Passive: allows preceding

filter to push or write the results into it

ClassData Sink

Responsibility• Consumes output

Collaborators• Pipe

Page 13: SS ZG653Second Semester,2012-13 1 Topic Architectural Patterns Pipe and Filter

SS ZG653Second Semester,2012-13 13

Dynamics• Scenario I

– Push pipeline [Activity starts with the Data source]– Filter activity started by writing data to the filters– Passive Filter [Use direct calls to the adjacent pipeline]Data Source Filter 1 Filter 2 Data Sink

Write(data)Transform(data)

Write(data)Transform(data)

Write(data)

Page 14: SS ZG653Second Semester,2012-13 1 Topic Architectural Patterns Pipe and Filter

SS ZG653Second Semester,2012-13 14

Dynamics• Scenario II

– Pull pipeline– Control flow is started by the data sink calling for

data

Data Source Filter 1 Filter 2 Data Sink

Read

Read

Read

dataTransform(data)

data

data

Transform(data)

Page 15: SS ZG653Second Semester,2012-13 1 Topic Architectural Patterns Pipe and Filter

SS ZG653Second Semester,2012-13 15

Dynamics• Scenario III

– Push-pull mixed pipeline

Data Source Filter 1 Filter 2 Data Sink

Read

Read

data

Transform(data)

data

Write(data)

Transform(data)

Page 16: SS ZG653Second Semester,2012-13 1 Topic Architectural Patterns Pipe and Filter

SS ZG653Second Semester,2012-13 16

Dynamics• Scenario IV

– All filters actively pull, compute and push data in a loop– Each filter runs its own thread of control– Filters are synchronised by buffering pipe between them

Buffering PipeData Source Filter 1 Filter 2 Data Sink

Read

data

Transform(data)

Read

Write(data)

data

Write(data)

Read

dataTransform(data)

Write(data)

Read

dataTransform(data)

Write(data)

Transform(data)

Page 17: SS ZG653Second Semester,2012-13 1 Topic Architectural Patterns Pipe and Filter

SS ZG653Second Semester,2012-13 17

Implementation# Steps1 Divide the system’s task into a sequence of processing stages

2 Define the data format to be passed along each pipe

3 Decide how to implement each pipe connection

4 Design and implement the filters

5 Design the error handling

6 Set up the processing pipeline

Page 18: SS ZG653Second Semester,2012-13 1 Topic Architectural Patterns Pipe and Filter

SS ZG653Second Semester,2012-13 18

1: Divide the systems tasks into sequence of processing stages

• Each stage must depend on the output of the predecessor

• All stages conceptually connected by data flow

Page 19: SS ZG653Second Semester,2012-13 1 Topic Architectural Patterns Pipe and Filter

SS ZG653Second Semester,2012-13 19

2: Define data format to be passed along each pipe

• Define a uniform format results in the highest flexibility because it makes recombination of filters easy

• Define the end of input marking

Page 20: SS ZG653Second Semester,2012-13 1 Topic Architectural Patterns Pipe and Filter

SS ZG653Second Semester,2012-13 20

3: Decide how to implement each pipe connection

• Decision determines active or passive filter• Using a separate pipe mechanism that

synchronises adjacent active filters provide a more flexible solution

Page 21: SS ZG653Second Semester,2012-13 1 Topic Architectural Patterns Pipe and Filter

SS ZG653Second Semester,2012-13 21

4: Design and implement the filters• Depends on

– Task it must perform– Adjacent pipe

• Active or Passive filters• Performance and tradeoffs• Filter reuse

Page 22: SS ZG653Second Semester,2012-13 1 Topic Architectural Patterns Pipe and Filter

SS ZG653Second Semester,2012-13 22

5: Design the error handling• Never neglect error handling• No global state shared; error handling hard to

address• Strategies in case of error – depend on

domain

Page 23: SS ZG653Second Semester,2012-13 1 Topic Architectural Patterns Pipe and Filter

SS ZG653Second Semester,2012-13 23

6: Setup the processing pipeline• Use of standardised main program• Use of user inputs or choice

Page 24: SS ZG653Second Semester,2012-13 1 Topic Architectural Patterns Pipe and Filter

SS ZG653Second Semester,2012-13 24

Variants

• Tee and Join pipeline– Filters with more then one input and/or more

than one output

Page 25: SS ZG653Second Semester,2012-13 1 Topic Architectural Patterns Pipe and Filter

SS ZG653Second Semester,2012-13 25

Benefits

• No intermediate files necessary, but possible• Flexibility by filter exchange• Flexibility by recombination• Reuse of filter components• Rapid prototyping of pipelines• Efficiency by parallel processing

Page 26: SS ZG653Second Semester,2012-13 1 Topic Architectural Patterns Pipe and Filter

SS ZG653Second Semester,2012-13 26

Liabilities• Sharing state information is expensive or inflexible• Data transformation overhead• Error handling

Page 27: SS ZG653Second Semester,2012-13 1 Topic Architectural Patterns Pipe and Filter

SS ZG653Second Semester,2012-13 27

Known Uses• Find (at least 2) more popular uses and document

them