Software Architectures



Similar documents
The Java I/O System. Binary I/O streams (ascii, 8 bits) The decorator design pattern Character I/O streams (Unicode, 16 bits)

Patterns in Software Engineering

Decorator Pattern [GoF]

Software Engineering

KWIC Implemented with Pipe Filter Architectural Style

Architecture Design & Sequence Diagram. Week 7

Programming Languages

Fundamentals of Java Programming

Introduction to Java

language 1 (source) compiler language 2 (target) Figure 1: Compiling a program

Chapter 6, The Operating System Machine Level

Lecture 9. Semantic Analysis Scoping and Symbol Table

Scoping (Readings 7.1,7.4,7.6) Parameter passing methods (7.5) Building symbol tables (7.6)

02 B The Java Virtual Machine

CMSC 132: Object-Oriented Programming II. Design Patterns I. Department of Computer Science University of Maryland, College Park

Today s Outline. Computer Communications. Java Communications uses Streams. Wrapping Streams. Stream Conventions 2/13/2016 CSE 132

CS 1302 Ch 19, Binary I/O

Semantic Analysis: Types and Type Checking

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.

C Compiler Targeting the Java Virtual Machine

Spring 2011 Prof. Hyesoon Kim

Inside the PostgreSQL Query Optimizer

Architectural Patterns: From Mud to Structure

The C Programming Language course syllabus associate level

Building a Multi-Threaded Web Server

Java (12 Weeks) Introduction to Java Programming Language

Static vs. Dynamic. Lecture 10: Static Semantics Overview 1. Typical Semantic Errors: Java, C++ Typical Tasks of the Semantic Analyzer

Last Class: OS and Computer Architecture. Last Class: OS and Computer Architecture

Compiler Construction

What is an I/O Stream?

Advanced Analysis and Design

Interpreters and virtual machines. Interpreters. Interpreters. Why interpreters? Tree-based interpreters. Text-based interpreters

Sources: On the Web: Slides will be available on:

Introduction to Software Paradigms & Procedural Programming Paradigm

Principles of Software Construction: Objects, Design, and Concurrency. Design Case Study: Stream I/O Some answers. Charlie Garrod Jonathan Aldrich

INPUT AND OUTPUT STREAMS

1) The postfix expression for the infix expression A+B*(C+D)/F+D*E is ABCD+*F/DE*++

The Sun Certified Associate for the Java Platform, Standard Edition, Exam Version 1.0

AP Computer Science Java Subset

AP Computer Science AB Syllabus 1

Topics. Introduction. Java History CS 146. Introduction to Programming and Algorithms Module 1. Module Objectives

Programming Language Pragmatics

Course Title: Software Development

Moving from CS 61A Scheme to CS 61B Java

picojava TM : A Hardware Implementation of the Java Virtual Machine

C++ Programming Language

1/20/2016 INTRODUCTION

Computer Programming I

AQA GCSE in Computer Science Computer Science Microsoft IT Academy Mapping

Java SE 8 Programming

Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C

Lecture 3. Arrays. Name of array. c[0] c[1] c[2] c[3] c[4] c[5] c[6] c[7] c[8] c[9] c[10] c[11] Position number of the element within array c

1 of 1 24/05/ :23 AM

public static void main(string[] args) { System.out.println("hello, world"); } }

Symbol Tables. Introduction

Objects for lexical analysis

Java SE 7 Programming

Information Systems Analysis and Design CSC John Mylopoulos. Software Architectures Information Systems Analysis and Design CSC340

The programming language C. sws1 1

CHAPTER 5 INTELLIGENT TECHNIQUES TO PREVENT SQL INJECTION ATTACKS

Web Development in Java

Chapter 5 Names, Bindings, Type Checking, and Scopes

Chapter 2: Remote Procedure Call (RPC)

From Control Loops to Software

WRITING DATA TO A BINARY FILE

Systems Integration: Co C mp m onent- t bas a e s d s o s ftw ft a w r a e r e ngin i eeri r n i g

Partitioning under the hood in MySQL 5.5

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

Learning Outcomes. Networking. Sockets. TCP/IP Networks. Hostnames and DNS TCP/IP

Java Interview Questions and Answers

An Overview of Java. overview-1

Lexical Analysis and Scanning. Honors Compilers Feb 5 th 2001 Robert Dewar

Decomposition into Parts. Software Engineering, Lecture 4. Data and Function Cohesion. Allocation of Functions and Data. Component Interfaces

Advanced compiler construction. General course information. Teacher & assistant. Course goals. Evaluation. Grading scheme. Michel Schinz

Introduction to Embedded Systems. Software Update Problem

The ConTract Model. Helmut Wächter, Andreas Reuter. November 9, 1999

CSCI 3136 Principles of Programming Languages

JAVA - FILES AND I/O

1 The Java Virtual Machine

PART-A Questions. 2. How does an enumerated statement differ from a typedef statement?

10CS35: Data Structures Using C

COMPUTER SCIENCE. 1. Computer Fundamentals and Applications

Creating a Simple, Multithreaded Chat System with Java

Crash Course in Java

SOFT 437. Software Performance Analysis. Ch 5:Web Applications and Other Distributed Systems

Structural Design Patterns Used in Data Structures Implementation

Software Architecture

SMock A Test Platform for the Evaluation of Monitoring Tools

Software Life-Cycle Management

IEC The Fast Guide to Open Control Software

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

Compiling Object Oriented Languages. What is an Object-Oriented Programming Language? Implementation: Dynamic Binding

Glossary of Object Oriented Terms

Chapter 13: Query Processing. Basic Steps in Query Processing

First Java Programs. V. Paúl Pauca. CSC 111D Fall, Department of Computer Science Wake Forest University. Introduction to Computer Science

Java SE 7 Programming

Transcription:

Software Architectures 2 SWS Lecture 1 SWS Lab Classes Hans-Werner Sehring Miguel Garcia Arbeitsbereich Softwaresysteme (STS) TU Hamburg-Harburg HW.Sehring@tuhh.de Miguel.Garcia@tuhh.de http://www.sts.tu-harburg.de/teaching/ss-05/swarch/entry.html Summer term 2005 Software Systems Department. All rights reserved. 4. Pipes & Filters Architectures 1. Motivation and Fundamental Concepts 2. Revisiting Object-Oriented Analysis, Design, and Implementation 3. Design Patterns 4. Pipes & Filters Architectures 5. Event-based Architectures 6. Layered Architectures & Persistence Management 7. Framework Architectures 8. Component Architectures 3.2 Chapter 4 1

Learning Objectives of Chapter 4 Students should be able to describe pipes & filters architectures and their variations, to explain the (dis-)advantages of pipes & filters architectures compared with object-oriented systems architectures, to relate pipes & filters to the design of the Java IO libraries and to apply the decorator pattern in their own system designs. Recommended Reading [ShGa96] Section 2 & Section 4 [GHJV95] Iterator (p. 257) [GHJV95] Decorator (p. 175) [BMRSS96] Section 2.1 + 2.2 Bruce Eckel: Thinking in Java, Prentice Hall, 1998. Chapter 10: The Java IO-System 3.3 The Pipes and Filters Architectural Pattern System Components: Filters process streams of data A filter encapsulates a processing step (algorithm) Topology: A Pipe connects a source and a sink component A pipe delivers an (infinite) stream of data Interaction: Data (message) exchange Filters can be recombined freely to build families of related systems. Purely data-driven interaction. Example: Unix shell: cat input.txt grep "text" sort > output.txt grep sort input.txt output.txt 3.4 Chapter 4 2

Example: P&F Compiler Architecture (1) Sources & Sinks, Input & Output Streams Flexible composability Aggregation / Decomposition of Filters Unicode Character Stream Token Stream Decorated Abstract Syntax Abstract Syntax Tree Nodes Tree Nodes Machine Code Generator Bytecode Optimizer Machine Code Stream Scanner Parser Semantic Checker Bytecode Generator Bytecode Stream + + + Error Message Stream 3.5 Example: P&F Compiler Architecture (2) class Math { public static int min (int a, int b) { return a < b? a : b ; }// min }// class Math class 7 Math { 3 6 public static 1 2 4 5 int... Sc Par SC 1 7 3 6 2 4 5 BC Gen mov ax, [BP] mov dx, [BP-2] 0 iload_0 1 iload_1 2 if_icmpge 7 5 iload_0 6 ireturn 7 iload_1 8 ireturn + + + 3 40 expected ")" 4 32 incompatible type 3.6 Chapter 4 3

Example: Virtual Instrumentation (1) Product: National Instruments, LabVIEW 3.7 Example: Virtual Instrumentation (2) 3.8 Chapter 4 4

Example: Java Studio for Java Beans 3.9 Class Responsibility Cards (CRC) Class: Filter Responsibilty Gets input data Performs a function on its input data Supplies output data Collaborators: Pipe Class: Pipe Responsibilty Transfers data. Buffers data Synchronizes active neighbors Collaborators: Data source Datasink Filter Class: Data Source Responsibilty Delivers a data stream Collaborators: Pipe Class: Data Sink Responsibilty Consumes a data stream Collaborators: Pipe 3.10 Chapter 4 5

Driving Forces leading to P&F Architectures Future system enhancements should be possible by exchanging processing steps or by a recombination of steps, even by users of the systems Small processing steps are easier to reuse in different contexts than large components (e.g.pretty-printer in compiler) Non adjacent processing steps do not share information Different sources of input data exist (network, terminal, file,...) It should be possible to present or store final results in various ways Explicit storage of intermediate results for further processing may be introduced. Synchronization of processing steps is not essential sequential execution parallel execution (pipelining) There is no need for a closed feedback loop 3.11 Filter Basic activities of filters (often combined in a single filter) enrich input data (e.g. by data from a data store or computed values) refine input data (e.g. filter out uninteresting input, sort input) transform input data (e.g. from streams of words to streams of sentences) There are two strategies to construct a filter: An Active Filter drives the data flow on the pipes A Passive Filter is driven by the data flow on the (input/output) pipes In a P&F-Architecture there has to be at least one active filter This active filter can be the environment of the system (e.g. user-input) (Persistent) collections can be used to buffer the data passed through pipes: files, arrays, dictionaries, trees,... 3.12 Chapter 4 6

Pipe A pipe is a first-class object A pipe transfers data from one data source to one data sink A pipe may implement a (bounded / unbounded) buffer Pipes between two threads of a single process (e.g. Java Streams) stream may contain references to shared language objects Pipes between two processes on a single host computer (e.g. Unix Named Pipes) stream may contain references to shared operating system objects (files!) Pipes between two processes in a distributed system (e.g. Internet Sockets) stream contents limited to raw bytes protocols implement higher-level abstractions (e.g. pass pipes as references, pass CORBA object references) 3.13 Composition Rules Sequential Composition Unix: F1 F2 F1 F2 Parallel Composition Unix: F1 & F2 F1 F2 Tee & Join Tee Join Restriction to Linear Composition Tee 3.14 Chapter 4 7

Example: Tee & Join in Unix Task: Print a sorted list of words that occur more than once mknod pipea p mknod pipeb p sort pipea > pipeb & cat file1 tee pipea sort -u comm -13 - pipeb > file2 pipea sort pipeb file1 cat tee sort comm file2 3.15 Active Filters The filter is an active process or thread that performs a loop, pulling its input from and pushing its output down the pipeline while (true) { Element x = inputpipe.read (...) ; outputpipe.write (f (x)) ; } Blocking read Blocking write Filter Many command-line-oriented operating systems provide an input stream and an output stream as a parameter to each program. (standard input / standard output) 3.16 Chapter 4 8

Producer / Consumer Problem Concurrent (autonomous) activity of producer and consumer Data-driven synchronization has to be supported by the operating system (process scheduler) or the programming-language runtime system (thread scheduler) Active Filter: Producer Active Filter: Consumer write /4 read produce consume Buffer / Pipe Petri-Net models possible concurrent execution paths. 3.17 Example: Production process (1) For Details, see: Informatik für Ingenieure II Chapter 9 Order Customer acquired Transition activated build wings build body build wheels Autonomous Subsystem Final assembly Finished airplane State Transition Mark 3.18 Chapter 4 9

Example: Production process (2) Order Customer acquired Parallelism created! build wings build body build wheels Final assembly Finished airplane 3.19 Example: Production process (3) Order Customer acquired Synchronisation through transition Final assembly! build wings build body build wheels Final assembly Finished airplane 3.20 Chapter 4 10

Example: Production process (4) Order Customer acquired Synchronisation through transition Final assembly! build wings build body build wheels Final assembly Finished airplane 3.21 Example: Production process (5) Order Customer acquired Synchronisation through transition Final assembly! build wings build body build wheels Final assembly Finished airplane 3.22 Chapter 4 11

Example: Production process (6) Order Customer acquired build wings build body build wheels Final assembly Finished airplane 3.23 Alternative Step in Production process Order Customer acquired The selection of the transition that triggers next is non-deterministic! build wings build body build wheels Final assembly Finished airplane 3.24 Chapter 4 12

Passive Filters: Pull Strategy The filter is a passive object that is driven by the subsequent pipeline element that pulls output data from the filter. InputStream read () : int java.io.inputstream in the Java Class Library ByteArray InputStream StringBuffer InputStream File InputStream Piped InputStream MyPullFilter int read () { int x = myinput.read () ; return f (x) ; } treat an active filter like a passive one 3.25 Scenario: Two Passive Pull Filters Data Source (pull) Filter 1 (pull) Filter 2 (pull) Data Sink (pull) read read read data f1 data f2 data 3.26 Chapter 4 13

Passive Filters: Push Strategy The filter is a passive object that is driven by the previous pipeline element that pushes input data into the filter. OutputStream write (b : int) java.io.outputstream in the Java Class Library ByteArray OutputStream File OutputStream Piped OutputStream MyPushFilter void write (int b) { myoutput.write (f (b)) ; } Treat an active filter like a passive one 3.27 Scenario: Two Passive Push Filters Data Source (push) Filter 1 (push) Filter 2 (push) Data Sink (push) write(data) f1 write(data) f2 write(data) 3.28 Chapter 4 14

A First Comparison of Architectures OO System Architecture Objects passed as arguments of messages by reference Shared everything (data, code, threads) Very large number of object links Object creation defined by other objects Frequent bidirectional object exchange between objects Focus on control flow (mostly sequential) Everything is an object small-grain system structuring dynamic object links Pipes & Filter Architecture Data values passed as copies between filters Shared nothing Very small number of pipes Filters and topology defined outside of the filters Unidirectional data flow Focus on data flow (highly concurrent) Filters have a complex internal structure that cannot be described by pipes and filters alone large-grain system structuring mostly static pipe topology 3.29 Implementation Issues Identify the processing steps (re-using existing filters as far as possible) Define the data format to be passed along each pipe Define end-of-stream symbol Decide how to implement each pipe connection (active / passive) Design and implement the filters Design error handling 3.30 Chapter 4 15

Stream Data Formats Tradeoff compatibility & reusability vs. type safety everything is a stream stream of Persons, stream of Texts Popular Stream Data Formats raw byte stream stream of ASCII text lines with line separator record stream (record attributes are strings, separated by tabulator or comma) nested record stream (record attribute is in turn a sequence) stream representing a tree traversal (inner nodes / leaf nodes enumerated in preorder, postorder, inorder) typed stream with a header containing its type information (e.g. column headings) event streams (event name and event arguments) (internal streams in a programming language: stream of object references) 3.31 Benefits of P&F Architectures No intermediate data structures necessary (but possible) (Pipeline processing subsumes batch processing) Archive Stream of letters Scan Letter Stream of bit images Tee OCR Stream of documents Flexibility through filter exchange Flexibility by recombination Reuse of filter components Rapid prototyping Parallel processing in a multiprocessor environment Dispatch task Stream of customer requests 3.32 Chapter 4 16

Limitations of P&F Architectures Sharing state information is expensive or inflexible Efficiency loss in a single processor environment cost of transferring data data dependencies between stream elements (e.g. sorting, tree traversal) cost of context switching (in particular for non-buffered pipes) Data transformation overhead data on the stream objects in memory Difficulty of coordinated error handling 3.33 P&F in Java: The Decorator Design Pattern Intent: Attach additional responsibilities to an object dynamically. Combine multiple responsibilities without subclassing. Motivation: Possible responsibilities of a Pipe / Stream Buffering the data Formatting / parsing of integers, floating point numbers,... Keeping track of the current line number (for error reporting) Provide a single character "lookahead" without actually consuming the character mystream alinenumberinputstream abufferedstream astringbufferinputstream mystringbuffer 3.34 Chapter 4 17

Remember: The Decorator Pattern Component operation() ConcreteComponent operation() Decorator operation() component.operation(); ConcreteDecoratorA operation() addedstate ConcreteDecoratorB operation() addedbehavior() addedbehavior(); super.operation(); 3.35 Decorator Pattern for Input / Output Streams Classes from the Java class library Component = InputStream / OutputStream Concrete Component = FileInputStream,... / FileOutputStream, Decorator = FilterInputStream / FilterOutputStream ConcreteDecorator = BufferedInputStream / PushbackInputStream / BufferedOutputStream, CipherInputStream / CipherOutputStream, DataInputStream / DataOutputStream, LineNumberInputStream, The classes FilterInputStream and FilterOutputStream define the common interface (and default implementations). Programmers have to compose these streams dynamically: mystringbuffer = new StringBuffer ("This is a sample string to be read") ; FilterInputStream mystream = new LineNumberInputStream ( new BufferedInputStream ( new StringBufferInputStream ( mystringbuffer))) ; mystream.read () ; mystream.line () ; 3.36 Chapter 4 18