A Family of Design Patterns for Application-Level Gateways
Total Page:16
File Type:pdf, Size:1020Kb
A Family of Design Patterns for Application-Level Gateways Douglas C. Schmidt [email protected] http://www.cs.wustl.edu/schmidt/ Department of Computer Science Washington University, St. Louis 63130 (TEL) 314-935-7538, (FAX) 314-935-7302 This paper appeared in the journal Theory and Practice of among software solutions for different applications in the Object Systems, special issue on Patterns and Pattern Lan- same domain. guages, Wiley & Sons, Vol. 2, No. 1, December 1996. Capturing and articulating the essence and commonality of successful communication software is important for several reasons: Abstract It helps guide the design choices of developers who Abstract are building new communication systems ± By under- standing the potential traps and pitfalls in their domain, developers can select suitable architectures, protocols, Developers of communication software must confront recur- and platform features without wasting time and effort ring design challenges involving robustness, ef®ciency, and implementing inef®cient or error-prone solutions. extensibility. Many of these challenges are independent of the application-speci®c requirements. Successful developers It preserves important design information for program- resolve these challenges by applying appropriate design pat- mers who enhance and maintain existing software ± terns. However, these patterns have traditionallybeen locked Often, this information is locked in the minds of the in the minds of expert developers or buried within complex original developers. If this design information is not system source code. The primary contribution of this pa- documented explicitly, however, it will be lost over per is to describe a family of design patterns that underly time, thereby increasing maintenance costs and decreas- many object-oriented communication software systems. In ing software quality. addition to describing each pattern separately, the paper il- The purpose of this paper is to illustrate an effective way to lustrates how knowledge of the relationships and trade-offs document the essence of successful communication software among patterns helps guide the construction of reusable com- by describing key design patterns used to build application- munication software frameworks. level Gateways, which route messages between Peers dis- tributed throughout a communication system. Design patterns represent successful solutions to problems 1 Introduction that arise when building software [1]. Capturing and articu- lating key design patterns helps to enhance software quality Building,maintaining,and enhancing high quality communi- by addressing fundamental challenges in large-scale system cation systems is hard. Developers must have a deep under- development. These challenges include communication of standing of many complex issues such as service initializa- architectural knowledge among developers; accommodating tion and distribution, concurrency control, ¯ow control, error new design paradigms or architectural styles; resolving non- handing, and event loop integration. Successful communi- functional forces such as reusability, portability, and exten- cation software created by experienced software developers sibility; and avoiding development traps and pitfalls that are embodies solutions to these issues. usually learned only by costly trial and error. It is often dif®cult, however, to separate the essence of This paper presents the object-oriented architecture and successful software solutions from the details of a particular design of an application-level Gateway in terms of implementation. Even when software is written using well- the design patterns used to guide the construction of structured object-oriented frameworks and components, it reusable and Gateway-speci®c frameworks and compo- can be hard to identify key roles and relationships. More- nents. Application-level Gateways have stringent require- over, OS platform features (such as the absence or presence ments for reliability, performance, and extensibility. There- of multi-threading) or requirements (such as best-effort vs. fore, they are excellent exemplars for presenting the struc- fault tolerance error handling) are often different. These dif- ture, participants, and consequences of key design patterns ferences can mask the underlying architectural commonality that appear in many communication software systems. 1 PEERS : Output PEERS : Map : Routing : Input Channel Manager Table Channel : Message : SOCK Queue : SOCK 5: recv_msg() Stream Stream 1: send : Reactor send_ _msgmsg() 2: recv_recv_msgmsg()() : Output () 3: route_route_msgmsg()() : Input Channel Channel : Connector : Acceptor : Message msg()() : SOCK Queue : SOCK Stream 4: send_msgsend_ : SOCK : Map Stream Manager : SOCK Connector Acceptor GATEWAY OUTGOING INCOMING GATEWAY MESSAGES MESSAGES CONNECTION CONNECTION REQUEST REQUEST Figure 1: The Structure and Collaboration of Peers and the Gateway The patterns described in this paper were discovered while building a wide range of communication systems including Figure 2: The Object-Oriented Gateway Software Archi- on-line transaction processing systems, telecommunication tecture switch management systems [2], electronic medical imag- ing systems [3], and parallel communication subsystems [4]. architecture for application-level Gateways.1 This architec- Although the speci®c application requirements in these sys- ture is based on extensive experience developing connection- temswerequitedifferent, thecommunication softwaredesign oriented Gateways for various commercial and research com- challenges were very similar. Therefore, although the exam- munication systems. After building multiple Gateway sys- ples in this paper focus on Gateways, the patterns embody tems it became clear that the software architecture of these design expertise that can be reused broadly in the communi- systems was largely independent of the protocols used to cation domain. route messages to Peers. This realization enabled the compo- The remainder of this paper is organized as follows: Sec- nents depicted in Figure 2 to be reused for the communication tion 2 outlines an object-oriented software architecture for software subsystems of many other projects. The ability to application-level Gateways; Section 3 examines the design reuse these components so widely stems from two factors: patterns that form the basis for reusable communication soft- ware, using application-level Gateways as an example; Sec- Understanding the actions and interactions of key de- tion 4 compares these patterns with those described in related sign patterns within the domain of communication soft- work; and Section 5 presents concluding remarks. ware: Patterns capture the structure and collaboration of participants in a software architecture at a higher level than source code and object-oriented design models that focus on individual objects and classes. Some of the communication 2 An Object-Oriented Software Archi- software patterns described in this paper have been docu- tecture for Application-level Gate- mented individually [7, 8, 9]. Although individual pattern descriptions capture valuable design expertise,complex com- ways munication software systems embody scores of patterns. Un- derstanding the relationships among these patterns is essen- This paper examines framework components and design pat- tial to document, motivate, and resolve dif®cult challenges terns that comprise and motivate the object-oriented architec- that arise when building communication software. There- ture of application-level Gateways developed by the author fore, Section 3 describes the interactions and relationships and his colleagues. A Gateway is a Mediator [1] that de- among these patterns in terms of a family of design patterns couples cooperating Peers throughout a network and allows for communication software. These design patterns work them to interact without having direct dependencies on each together to solve complex problems within the domain of other [5]. As shown in Figure 1, messages routed through communication software. the Gateway contain payloads encapsulated in routing mes- sages. 1Relationships between components are illustrated throughoutthis paper using Booch notation [6]. In this ®gure solid clouds indicate objects; nesting Figure 2 illustrates the structure, associations, and internal indicates composition relationships between objects; and undirected edges and external collaborations among objects within a software indicate an association exists between two objects. 2 Developing an object-oriented framework that imple- To increase system ¯exibility, connections can be estab- ments these design patterns: Recognizing the patterns lished in two ways: that commonly occur in many communication software sys- 1. From the Gateway to the Peers ± which is typically tems helped shape the development of reusable framework done whenever the Gateway ®rst starts up to establish components. The Gateway systems this paper is based the initial system con®guration of Peers; upon were implemented with the ADAPTIVE Communica- tion Environment (ACE) software [10]. ACE provides an 2. From a Peer to the Gateway ± which is typicallydone integrated framework of reusable C++ wrappers and compo- once the system is running whenever a new Peer wants nents that perform common communication software tasks. to send or receive routing messages. These tasks include event demultiplexing, event handler dis- In a large system, several scores of Peers may be con- patching, connection