Tải bản đầy đủ (.pdf) (639 trang)

pattern-oriented software architecture volume 4 a pattern language for distributed computing

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (5.22 MB, 639 trang )


PATTERN-ORIENTED
SOFTWARE
ARCHITECTURE

PATTERN-ORIENTED
SOFTWARE
ARCHITECTURE
A Pattern Language for
Distributed Computing
Volume 4
Frank Buschmann,
Siemens, Munich, Germany
Kevlin Henney,
Curbralan, Bristol, UK
Douglas C. Schmidt,
Vanderbilt University, Tennessee, USA
Copyright  2007 John Wiley & Sons Ltd, The Atrium, Southern Gate, Chichester,
West Sussex PO19 8SQ, England
Telephone (
+44) 1243 779777
Email (for orders and customer service enquiries):
Visit our Home Page on www.wileyeurope.com or www.wiley.com
All Rights Reserved. No part of this publication may be reproduced, stored in a retrieval system or
transmitted in any form or by any means, electronic, mechanical, photocopying, recording,
scanning or otherwise, except under the terms of the Copyright, Designs and Patents Act 1988 or
under the terms of a licence issued by the Copyright Licensing Agency Ltd, 90 Tottenham Court
Road, London W1T 4LP, UK, without the permission in writing of the Publisher. Requests to the
Publisher should be addressed to the Permissions Department, John Wiley & Sons Ltd, The


Atrium, Southern Gate, Chichester, West Sussex PO19 8SQ, England, or emailed to
, or faxed to (
+44) 1243 770620.
Front cover Image Copyright
 2007 Yann Arthus-Bertrand/Altitude
Designations used by companies to distinguish their products are often claimed as trademarks.
All brand names and product names used in this book are trade names, service marks,
trademarks or registered trademarks of their respective owners. The Publisher is not associated
with any product or vendor mentioned in this book.
This publication is designed to provide accurate and authoritative information in regard to the
subject matter covered. It is sold on the understanding that the Publisher is not engaged in
rendering professional services. If professional advice or other expert assistance is required, the
services of a competent professional should be sought.
Other Wiley Editorial Offices
John Wiley & Sons Inc., 111 River Street, Hoboken, NJ 07030, USA
Jossey-Bass, 989 Market Street, San Francisco, CA 94103-1741, USA
Wiley-VCH Verlag GmbH, Boschstr. 12, D-69469 Weinheim, Germany
John Wiley & Sons Australia Ltd, 42 McDougall Street, Milton, Queensland 4064, Australia
John Wiley & Sons (Asia) Pte Ltd, 2 Clementi Loop #02-01, Jin Xing Distripark, Singapore 129809
John Wiley & Sons Canada Ltd, 6045 Freemont Blvd, Mississauga, Ontario, L5R 4J3, Canada
Wiley also publishes its books in a variety of electronic formats. Some content that appears
in print may not be available in electronic books.
British Library Cataloguing in Publication Data
A catalogue record for this book is available from the British Library
ISBN-13: 978-0-470-05902-9 (hbk)
Typeset in 10/13 Bookman-Light by Laserwords Private Limited, Chennai, India
Printed and bound in Great Britain by Bell & Bain, Glasgow
This book is printed on acid-free paper responsibly manufactured from sustainable forestry
in which at least two trees are planted for each one used for paper production.
For Anna, Beb

´
e

, and Martina
Frank Buschmann
For Carolyn, Stefan, and Yannick
Kevlin Henney
For Lori, Bronson, Mom, and Dad
Douglas C. Schmidt
†Beb
´
e, July 3, 1999

Table of Contents
Foreword xv
About This Book xvii
About The Authors xxiii
Guide To The Reader xxvii
Part I Some Concepts 1
1 On Patterns and Pattern Languages 3
1.1 Patterns Introduced 4
1.2 Inside Patterns 6
1.3 Between Patterns 10
1.4 Into Pattern Languages 13
1.5 Patterns Connected 15
2 On Distributed Systems 17
2.1 Benefits of Distribution 18
2.2 Challenges of Distribution 20
2.3 Technologies for Supporting Distribution 22
2.4 Limitations of Middleware 32

3 On the Pattern Language 33
3.1 Intent, Scope, and Audience 34
3.2 Origins and Genesis 35
viii Table of Contents
3.3 Structure and Content 36
3.4 Presentation 44
3.5 Practical Use 49
Part II A Story 53
4 Warehouse Management Process Control 57
4.1 System Scope 58
4.2 Warehouse Management Process Control 60
5 Baseline Architecture 65
5.1 Architecture Context 66
5.2 Partitioning the Big Ball of Mud 67
5.3 Decomposing the Layers 68
5.4 Accessing Domain Object Functionality 71
5.5 Bridging the Network 72
5.6 Separating User Interfaces 76
5.7 Distributing Functionality 79
5.8 Supporting Concurrent Domain Object Access 82
5.9 Achieving Scalable Concurrency 85
5.10 Crossing the Object-Oriented/Relational Divide 87
5.11 Configuring Domain Objects at Runtime 89
5.12 Baseline Architecture Summary 90
6 Communication Middleware 95
6.1 A Middleware Architecture for Distributed
Systems 96
6.2 Structuring the Internal Design of the
Middleware 100
6.3 Encapsulating Low-level System Mechanisms . 103

6.4 Demultiplexing ORB Core Events 105
6.5 Managing ORB Connections 108
6.6 Enhancing ORB Scalability 111
6.7 Implementing a Synchronized Request Queue 114
6.8 Interchangeable Internal ORB Mechanisms 116
Table of Contents ix
6.9 Consolidating ORB Strategies 118
6.10 Dynamic Configuration of ORBs 121
6.11 Communication Middleware Summary 124
7 Warehouse Topology 129
7.1 Warehouse Topology Baseline 130
7.2 Representing Hierarchical Storage 131
7.3 Navigating the Storage Hierarchy 133
7.4 Modeling Storage Properties 135
7.5 Varying Storage Behavior 137
7.6 Realizing Global Functionality 140
7.7 Traversing the Warehouse Topology 142
7.8 Supporting Control Flow Extensions 144
7.9 Connecting to the Database 146
7.10 Maintaining In-Memory Storage Data 147
7.11 Configuring the Warehouse Topology 149
7.12 Detailing the Explicit Interface 151
7.13 Warehouse Topology Summary 153
8 The Story Behind The Pattern Story 157
Part III The Language 163
9 From Mud To Structure 167
Domain Model ** 182
Layers ** 185
Model-View-Controller ** 188
Presentation-Abstraction-Control 191

Microkernel ** 194
Reflection * 197
Pipes and Filters ** 200
Shared Repository ** 202
Blackboard 205
Domain Object ** 208
x Table of Contents
10 Distribution Infrastructure 211
Messaging ** 221
Message Channel ** 224
Message Endpoint ** 227
Message Translator ** 229
Message Router ** 231
Publisher-Subscriber ** 234
Broker ** 237
Client Proxy ** 240
Requestor ** 242
Invoker ** 244
Client Request Handler ** 246
Server Request Handler ** 249
11 Event Demultiplexing and Dispatching 253
Reactor ** 259
Proactor * 262
Acceptor-Connector ** 265
Asynchronous Completion Token ** 268
12 Interface Partitioning 271
Explicit Interface ** 281
Extension Interface ** 284
Introspective Interface ** 286
Dynamic Invocation Interface * 288

Proxy ** 290
Business Delegate ** 292
Facade ** 294
Combined Method ** 296
Iterator ** 298
Enumeration Method ** 300
Batch Method ** 302
Table of Contents xi
13 Component Partitioning 305
Encapsulated Implementation ** 313
Whole-Part ** 317
Composite ** 319
Master-Slave * 321
Half-Object plus Protocol ** 324
Replicated Component Group * 326
14 Application Control 329
Page Controller ** 337
Front Controller ** 339
Application Controller ** 341
Command Processor ** 343
Template View ** 345
Transform View ** 347
Firewall Proxy ** 349
Authorization ** 351
15 Concurrency 353
Half-Sync/Half-Async ** 359
Leader/Followers ** 362
Active Object ** 365
Monitor Object ** 368
16 Synchronization 371

Guarded Suspension ** 380
Future ** 382
Thread-Safe Interface * 384
Double-Checked Locking 386
Strategized Locking ** 388
Scoped Locking ** 390
Thread-Specific Storage 392
xii Table of Contents
Copied Value ** 394
Immutable Value ** 396
17 Object Interaction 399
Observer ** 405
Double Dispatch ** 408
Mediator * 410
Command ** 412
Memento ** 414
Context Object ** 416
Data Transfer Object ** 418
Message ** 420
18 Adaptation and Extension 423
Bridge ** 436
Object Adapter ** 438
Chain of Responsibility * 440
Interpreter 442
Interceptor ** 444
Visitor ** 447
Decorator 449
Execute-Around Object ** 451
Template Method * 453
Strategy ** 455

Null Object ** 457
Wrapper Facade ** 459
Declarative Component Configuration * 461
19 Modal Behavior 463
Objects for States * 467
Methods for States * 469
Collections for States ** 471
Table of Contents xiii
20 Resource Management 473
Container * 488
Component Configurator * 490
Object Manager ** 492
Lookup ** 495
Virtual Proxy ** 497
Lifecycle Callback ** 499
Task Coordinator * 501
Resource Pool ** 503
Resource Cache ** 505
Lazy Acquisition ** 507
Eager Acquisition ** 509
Partial Acquisition * 511
Activator ** 513
Evictor ** 515
Leasing ** 517
Automated Garbage Collection ** 519
Counting Handle ** 522
Abstract Factory ** 525
Builder * 527
Factory Method ** 529
Disposal Method ** 531

21 Database Access 533
Database Access Layer ** 538
Data Mapper ** 540
Row Data Gateway ** 542
Table Data Gateway ** 544
Active Record 546
22 A Departing Thought 549
xiv Table of Contents
Glossary 553
References 573
Index of Patterns 587
Index of Names 593
Subject Index 595
Foreword
The patterns movement has been around for over a decade now, and
has gone through the usual cycle of inflated expectations, backlash,
and quiet acceptance. Frank, Doug, and Kevlin have been there the
whole time, lauded and scoffed at, but above all quietly collecting
good ideas from the field and describing them. The POSA series of
books is rightly regarded as one of the most solid elements in the
patterns literature, and every volume has a space in my library.
Earlier POSA volumes were traditional patterns books, describing
patterns in a range of specific areas, mostly with patterns that hadn’t
been written up before. This book is different. Distributed Computing
is a very wide topic and even the patterns we’ve captured so far is far
more than would fit in a single volume. Indeed they are spread over
multiple books, both within and outside the POSA series. This book’s
mission is to pull these patterns together. As a result you’ve got many
more patterns here than you’d usually find, and consequentially a
much terser description. Some of the patterns described here aren’t

primarily about distribution, but have some relevance for distributed
system work. As a result the descriptions in this book highlight that
usage, summarizing a pattern in a distributed systems context.
This book is also about more than the individual patterns—it’s also
about how they relate. Any system contains multiple patterns used
together, but I for one find it harder to talk about inter-relationships
than the individual patterns. A book like this cannot dodge this
question, so here you’ll find a lot of advice on how to combine
patterns with distribution.
xvi Foreword
Distribution is a hard problem and often causes trouble. Indeed I’m
often quoted for my tongue-in-cheek First Law of Distributed Object
Design: ‘Don’t distribute your objects.’ I wrote my first law for a good
reason—distribution makes software harder, and as a result I always
recommend avoiding it when you can. But however great my desire to
question every distribution boundary, the reality is that distribution
is an essential part of many software systems. And since distribution
is hard, it’s particularly important to take care over its design—which
is why this book is also an important addition to a developer’s library.
Martin Fowler
About This Book
Distributed computing is connecting the world and leveling playing
fields [Fri06]. The ubiquity of the Web and e-commerce today exem-
plify a common motivation for distributed computing: the ability to
connect to and access vast quantities of geographically dispersed
information and services. The popularity of instant messaging and
chat rooms on the Internet underscores another common motiva-
tion: staying connected to family, friends, colleagues, and customers.
Other motivators for distributed computing include enhancing per-
formance, scalability, and fault tolerance, as well as reducing costs

by sharing expensive hardware and peripherals.
Given the importance of distributed computing in our professional
and personal lives, many patterns in the software literature focus
on this topic [POSA1] [POSA2] [POSA3] [Lea99] [VSW02] [VKZ04]
[HoWo03] [PLoPD1] [PLoPD2] [PLoPD3] [PLoPD4] [PLoPD5]. Unfor-
tunately, many of these patterns are described in relative isolation,
referencing few other patterns, most of which are in the same publica-
tion. Despite the utility of each individual pattern, there is no holistic
view of distributed computing that emphasizes how relevant patterns
complete and complement each other. Building complex distributed
systems therefore remains largely a dark art mastered only by a few
wizards and gurus.
To provide a more holistic view, this book—the fourth volume of
the Pattern-Oriented Software Architecture (POSA) series—describes
a single pattern language that links many patterns relevant to
distributed computing. Each pattern in this language either deals
directly with distributed computing, or plays an important support-
ing role in that context. Our pattern language thus provides a guide
to—and a communication vehicle for—the best practices in key areas
of distributed computing.
xviii About This Book
Intended Audience
Our focus is on the design and implementation of software for dis-
tributed computing systems. The main audience for this book is
therefore professional software architects or advanced students who
are involved in developing software for distributed computing sys-
tems, both designing new applications and improving and refactoring
existing ones. Our pattern language presents a rich set of patterns
aimed at helping architects to create sustainable designs for dis-
tributed systems, and which address their requirements thoughtfully

and professionally.
A secondary audience for this book is application developers who
use component and communication middleware in their professional
work. Our pattern language provides developers with an overview of
the current state-of-the-practice in designing distributed systems, so
that they can better understand how to use middleware effectively. A
third group who can benefit from our pattern language is project and
product managers. The language can give managers a deeper under-
standing of the essential capabilities of systems whose development
they are leading, and provide a useful vocabulary for communicating
with software architects and developers.
We do not however intend end-users or customers to use our pattern
language directly. While judicious use of real-world metaphors might
make the material accessible to this audience, it would require an
alternative presentation of the language. Moreover, the book is not
intended as a general tutorial on distributed computing. Although
we discuss many aspects of this subject, and include an extensive
glossary, readers need prior familiarity with core distributed com-
puting concepts and mechanisms such as deadlock, transactions,
synchronization, scheduling, and consensus. Additional information
on topics related to distributed computing, such as the design of
networking protocols and operating systems, can be found in the
references.
About This Book xix
Structure and Content
This book is arranged in three parts: some concepts, a story, and the
pattern language itself.
Part I, Some Concepts, introduces the context of the book: the core
pattern concepts necessary for an understanding of the book, an
overview of the benefits and challenges of distributed computing, a

summary of technologies for supporting distribution, and an intro-
duction to our pattern language.
Part II, AStory, describes how a real-world process control system
for warehouse management was designed using our pattern lan-
guage for distributed computing. The story focuses on three areas
of this software system: its baseline architecture, its communication
middleware, and its warehouse topology representation.
Part III, The Language, forms the main part of the book. It contains
a pattern language for distributed computing that addresses the
following technical topics relevant to the construction of distributed
systems:

Specifying an initial software baseline architecture

Understanding communication middleware

Event demultiplexing and dispatching

Interface partitioning

Component partitioning

Application control

Concurrency

Synchronization

Object interaction


Adaptation and extension

Modal behavior

Resource management

Database access.
xx About This Book
Each chapter introduces the topic area it addresses, summarizes key
challenges, and then presents a set of patterns that help master these
challenges. In total, our pattern language for distributed computing
contains 114 patterns and connects to more than 150 patterns pre-
sented in other publications. It is thus one of the largest—if not the
largest—software pattern language documented to date.
Although distributed computing is the language’s focus, many parts
of it have broader applicability. For example, most applications must
be adaptable and extensible in some way, and each software system
needs well-designed interfaces and components. For selected tech-
nical areas, our pattern language can therefore serve as a general
guide to the best practices in modern software development, and is
therefore not limited to distributed computing.
The book ends with a short reflection on our pattern language for dis-
tributed computing, a glossary of frequently used terms, an extensive
list of references to work in the field, a pattern index, a general subject
index, and an index that lists everyone who helped us shape the book.
There are undoubtedly properties and patterns of distributed sys-
tems that we have omitted, or which will emerge over time through
the application and extension of the pattern language in practice.
If you have comments, constructive criticism, or suggestions for
improving the style and content of this book, please send them to

us via electronic mail to
lines for subscription can be found on the patterns home page
at This link also provides an
important source of information on many aspects of patterns, such
as available and forthcoming books, conferences on patterns, papers
on patterns, and so on.
About This Book xxi
Acknowledgments
It is a pleasure for us to thank the many people who supported us in
creating this book, either by sharing their knowledge with us or by
reviewing earlier drafts of its various parts.
Champion review honors go to Michael Kircher, our shepherd, who
reviewed all our material in depth, focusing on its correctness, com-
pleteness, consistency, and quality. Michael’s feedback significantly
increased the quality of the material in this book.
In addition, we presented parts of the language at three EuroPLoP
pattern conferences, and also to several distribution and pattern
experts. Ademar Aguimar, Steve Berczuk, Alan O’Callaghan, Ekata-
rina Chtcherbina, Jens Coldewey, Richard Gabriel, Ian Graham,
Prashant Jain, Nora Koch, Doug Lea, Klaus Marquardt, Andrey
Nechypurenko, Kristian Sørensen, James Siddle, Michael Stal, Steve
Vinoski, Markus V
¨
olter, Oliver Vogel, and Uwe Zdun provided us
with extensive feedback, which led to many minor—and also some
major—revisions of the language and its presentation.
Many thanks go to Mai Skou Nielsen, who took the photos of Kevlin
and Frank when they met at the JAOO 2006 conference in Aarhus,
Denmark. Anton Brøgger helped locate details about the photo we
present in the chapter on interface partitioning patterns. Publicis

Kommunikationsagentur GmbH and Lutz Buschmann permitted us
to use photos from their collections in this book.
Special thanks go to Lothar Borrmann and Reinhold Achatz for their
managerial support and backing at the software engineering labs of
Corporate Technology of Siemens AG, Munich, Germany.
Very special thanks go to our editor, Sally Tickner, our former editor
Gaynor Redvers-Mutton, and everyone else at John Wiley & Sons
who made it possible to publish this book. It was Gaynor who con-
vinced us to write this POSA volume despite heavy loads in our
daily work as software professionals. Sally, in turn, had an enormous
amount of patience with us during the years we spent completing
the manuscript. Very special thanks also go to Steve Rickaby, of
xxii About This Book
WordMongers Ltd, our copy editor, for enhancing our written mate-
rial. This is the fourth POSA book fostered by Steve, and we look
forward to working with him on forthcoming volumes.
Last but not least, we thank our families for their patience and
support during the writing of this book!

×