The Object-Oriented Design and Implementation of the Reactor

Total Page:16

File Type:pdf, Size:1020Kb

The Object-Oriented Design and Implementation of the Reactor The Design and Implementation of the Reactor An Object-Oriented Framework for Event Demultiplexing (Part 2 of 2) Douglas C. Schmidt [email protected] http://www.cs.wustl.edu/schmidt/ Department of Computer Science Washington University, St. Louis 63130 An earlier version of this paper appeared in the September I/O-based and/or timer-based demultiplexing mechanisms. 1993 issue of the C++ Report. The following paragraphs describe the primary features of- fered by the Reactor framework: 1 Introduction Export Uniform Object-Oriented Interfaces: Appli- cations using the Reactor do not access the lower-level This is the second half of the third article in a series that de- I/O demultiplexing system calls directly. Instead, they in- scribes techniques for encapsulating existing operating sys- herit from a common Event Handler abstract base class tem (OS) interprocess communication (IPC) services using to form composite concrete derived classes (as illustrated object-oriented (OO) C++ wrappers. In the ®rst half of this in Figure 1). The Event Handler base class speci®es a article, a client/server application example was presented to uniform interface consisting of virtual methods that handle motivate the utilityof wrappers that encapsulate event demul- (1) synchronous input, output, and exceptions and (2) timer- tiplexing mechanisms [1]. Event demultiplexing is useful for based events. Applications create objects of these derived developing event-driven network servers that receive and classes and register them with instances of the Reactor. process data arriving from multiple clients simultaneously. Automate Event Handler Dispatching: When events The previous article also examined the advantages and dis- occur, the Reactor automatically invokes the appropri- advantages of several alternative I/O demultiplexing schemes ate virtual method event handler(s) belonging to the pre- such as non-blockingI/O,multipleprocess or thread creation, registered derived class objects. Since C++ objects are reg- and synchronous I/O demultiplexing (via the select and istered with the Reactor (as opposed to stand-alone sub- poll system calls). routines), any context information associated with an object This article focuses on the design and implementation of is retained between invocations of its methods. This is par- an object-oriented framework called the Reactor.The ticularly useful for developing ªstatefulº services that retain Reactor provides a portable interface to an integrated col- information in between client invocations. lection of extensible, reusable, and type-secure C++ classes Support Transparent Extensibility: The functionality select poll that encapsulate and enhance the and event of both the Reactor and its registered objects may be ex- demultiplexing mechanisms [2]. To help simplify network tended transparently without modifying or recompiling ex- programming, the Reactor combines the demultiplexing isting code. To accomplish this, the Reactor framework of synchronous I/O-based events together with timer-based employs inheritance, dynamic binding, and parameterized events. When these events occur, the Reactor automati- types to decouple the lower-level event demultiplexing and cally dispatches the method(s) of previously registered ob- service dispatching mechanisms from the higher-level appli- jects to perform application-speci®ed services. cation processing policies. Example low-level mechanisms This article is organized as follows: Section 2 describes include (1) detecting events on multiple I/O handles, (2) the primary features offered by the Reactor framework; handling timer expiration, and (3) invoking the appropriate Section 3 outlines the object-oriented design and implemen- method event handler(s) in response to events. Likewise, tation of the framework; Section 4 presents a distributed application-speci®ed policies include (1) connection estab- logging example that demonstrates how the Reactor sim- lishment, (2) data transmission and reception, and (3) pro- pli®es the development of concurrent, event-driven network cessing service requests from other participating hosts. applications; and Section 5 discusses concluding remarks. Increase Reuse: The Reactor's demultiplexing and dispatching mechanisms may be reused by many network ap- 2 Primary Features of the Reactor plications. By reusing rather than redeveloping these mech- anisms, developers are free to concentrate on higher-level The Reactor provides an object-oriented interface that sim- application-related issues, rather than repeatedly wrestling pli®es the development of distributedapplications that utilize with lower-level event demultiplexing details. In addition, 1 subsequent bug-®xes and enhancements are transparently shared by all applications that utilize the Reactor's com- ponents. Conversely, developers that access select and : Logging : Logging : Logging REGISTERED poll directly must reimplement the same demultiplexing Handler Handler Acceptor OBJECTS LEVEL and dispatching code for every network application. More- LEVEL : Event : Event : Event over, any modi®cations and improvements to this code must Handler Handler Handler APPLICATION be replicated manually in all related applications. APPLICATION Enhance Type-Security: The Reactor shields applica- 1: handle_input() tion developers from error-prone,low-level details associated with programming existing I/O demultiplexing system calls. :Timer : Handle These details involve setting and clearing bitmasks, handling Table : Signal LEVEL Queue LEVEL Handlers timeouts and interrupts, and dispatching ªcall-backº meth- FRAMEWORK FRAMEWORK : Reactor ods. In particular, the Reactor eliminates several subtle causes of errors with poll and select that involve the OS EVENT DEMULTIPLEXING INTERFACE misuse of I/O handles and fd set bitmasks. Reactor LEVEL Improve Portability: The also shields appli- LEVEL KERNEL cations from differences between select and poll that KERNEL impede portability. As illustrated in Figure 5, the Reactor Figure 1: The Reactor Inheritance Hierarchy exports the same interface to applications, regardless of the underlying event demultiplexingsystem calls. Moreover, the Reactor's object-oriented architecture improves its own in- contains support for multi-threading. In general, a single in- ternal portability. For example, porting the Reactor from stance of the Reactor is active in a thread at any point in a select-based OS platform to a poll-based platform re- time. However, there may be multiple different instances of quired only a few well-de®ned changes to the framework. Reactor objects running in separate threads in a process. The framework provides the necessary synchronization op- In addition to simplifying application development, the erations to prevent race conditions [4]. Reactor also performs its demultiplexing and dispatching tasks ef®ciently. In particular, its event dispatching logic improves upon common techniques that use select di- 3.1 Platform-Independent Class Components rectly. For instance, the select-based Reactor uses The following paragraphs summarize the salient charac- an ACE Handle Set class (described in Section 3.2) that teristics of the three platform-independent classes in the avoids examining fd set bitmasks one bit at a time in many Reactor:theACE Time Value, ACE Timer Queue, circumstances. An article in a future issue of the C++ Report and ACE Event Handler classes: will empirically evaluate the performance of the Reactor and compare it against a non-object-oriented solution written ACE Time Value: This class provides a C++ wrap- in C that accesses I/O demultiplexing system calls directly. per that encapsulates an underlying OS platform's date and time structure (such as the struct timeval data type on UNIX and POSIX platforms). The timeval structure 3 The Object-Oriented Design and Im- contains two ®elds that represent time in terms of seconds and microseconds. However, other OS platforms use differ- plementation of the Reactor ent representations, so the ACE Time Value class abstracts these details to provide a portable C++ interface. This section summarizes the object-oriented design of the The primary methods in the ACE Time Value class are Reactor framework's primary class components, focus- illustrated in Figure 2. The ACE Time Value wrapper ing on the interfaces and strategic design decisions. Where uses operator overloading to simplify time-based compar- appropriate, tactical design decisions and certain implemen- isons within the Reactor. Overloading permits the use of tation details are also discussed. Section 3.1 outlines the OS standard arithmetic syntax for relational expressions involv- platform-independent components; Section 3.2 covers the ing time comparisons. For example, the following code cre- platform-dependent components. ates two ACE Time Value objects constructed by adding The Reactor was originally modeled after a C++ wrap- user-supplied command-line arguments to the current time, per for select called the Dispatcher that is available and then displaying the appropriate ordering relationship be- with the InterViews distribution [3]. The Reactor frame- tween the two objects: work described here includes several additional features. For example, the Reactor operates transparently on top of int main (int argc, char *argv[]) both the System V Release 4 poll interface and select, { if (argc != 3) { which is available on both UNIX and PC platforms (via cerr << "usage: " << argv[0] the WINSOCK API). In addition, the Reactor framework
Recommended publications
  • Desktop Migration and Administration Guide
    Red Hat Enterprise Linux 7 Desktop Migration and Administration Guide GNOME 3 desktop migration planning, deployment, configuration, and administration in RHEL 7 Last Updated: 2021-05-05 Red Hat Enterprise Linux 7 Desktop Migration and Administration Guide GNOME 3 desktop migration planning, deployment, configuration, and administration in RHEL 7 Marie Doleželová Red Hat Customer Content Services [email protected] Petr Kovář Red Hat Customer Content Services [email protected] Jana Heves Red Hat Customer Content Services Legal Notice Copyright © 2018 Red Hat, Inc. This document is licensed by Red Hat under the Creative Commons Attribution-ShareAlike 3.0 Unported License. If you distribute this document, or a modified version of it, you must provide attribution to Red Hat, Inc. and provide a link to the original. If the document is modified, all Red Hat trademarks must be removed. Red Hat, as the licensor of this document, waives the right to enforce, and agrees not to assert, Section 4d of CC-BY-SA to the fullest extent permitted by applicable law. Red Hat, Red Hat Enterprise Linux, the Shadowman logo, the Red Hat logo, JBoss, OpenShift, Fedora, the Infinity logo, and RHCE are trademarks of Red Hat, Inc., registered in the United States and other countries. Linux ® is the registered trademark of Linus Torvalds in the United States and other countries. Java ® is a registered trademark of Oracle and/or its affiliates. XFS ® is a trademark of Silicon Graphics International Corp. or its subsidiaries in the United States and/or other countries. MySQL ® is a registered trademark of MySQL AB in the United States, the European Union and other countries.
    [Show full text]
  • Input for Winforms
    ComponentOne Input for WinForms ComponentOne, a division of GrapeCity 201 South Highland Avenue, Third Floor Pittsburgh, PA 15206 USA Website: http://www.componentone.com Sales: [email protected] Telephone: 1.800.858.2739 or 1.412.681.4343 (Pittsburgh, PA USA Office) Trademarks The ComponentOne product name is a trademark and ComponentOne is a registered trademark of GrapeCity, Inc. All other trademarks used herein are the properties of their respective owners. Warranty ComponentOne warrants that the media on which the software is delivered is free from defects in material and workmanship, assuming normal use, for a period of 90 days from the date of purchase. If a defect occurs during this time, you may return the defective media to ComponentOne, along with a dated proof of purchase, and ComponentOne will replace it at no charge. After 90 days, you can obtain a replacement for the defective media by sending it and a check for $2 5 (to cover postage and handling) to ComponentOne. Except for the express warranty of the original media on which the software is delivered is set forth here, ComponentOne makes no other warranties, express or implied. Every attempt has been made to ensure that the information contained in this manual is correct as of the time it was written. ComponentOne is not responsible for any errors or omissions. ComponentOne’s liability is limited to the amount you paid for the product. ComponentOne is not liable for any special, consequential, or other damages for any reason. Copying and Distribution While you are welcome to make backup copies of the software for your own use and protection, you are not permitted to make copies for the use of anyone else.
    [Show full text]
  • Actionscript 3.0 Cookbook.Pdf
    ActionScript 3.0 Cookbook By Joey Lott, Darron Schall, Keith Peters ............................................... Publisher: O'Reilly Pub Date: October 01, 2006 ISBN: 0-596-52695-4 Pages: 592 Table of Contents | Index Well before Ajax and Microsoft's Windows Presentation Foundation hit the scene, Macromedia offered the first method for building web pages with the responsiveness and functionality of desktop programs with its Flash-based "Rich Internet Applications". Now, new owner Adobe is taking Flash and its powerful capabilities beyond the Web and making it a full-fledged development environment. Rather than focus on theory, the ActionScript 3.0 Cookbook concentrates on the practical application of ActionScript, with more than 300 solutions you can use to solve a wide range of common coding dilemmas. You'll find recipes that show you how to: Detect the user's Flash Player version or their operating system Build custom classes Format dates and currency types Work with strings Build user interface components Work with audio and video Make remote procedure calls using Flash Remoting and web services Load, send, and search XML data And much, much more ... Each code recipe presents the Problem, Solution, and Discussion of how you can use it in other ways or personalize it for your own needs, and why it works. You can quickly locate the recipe that most closely matches your situation and get the solution without reading the whole book to understand the underlying code. Solutions progress from short recipes for small problems to more complex scripts for thornier riddles, and the discussions offer a deeper analysis for resolving similar issues in the future, along with possible design choices and ramifications.
    [Show full text]
  • Windows Powershell Best Practices Windows Powershell Best Practices
    Windows PowerShell Best Practices Windows PowerShell Best Practices Expert recommendations, pragmatically applied Automate system administration using Windows PowerShell best practices—and optimize your operational efficiency. With this About the Author practical guide, Windows PowerShell expert and instructor Ed Ed Wilson, MCSE, CISSP, is a well-known Wilson delivers field-tested tips, real-world examples, and candid scripting expert and author of “Hey Windows Scripting Guy!”—one of the most popular advice culled from administrators across a range of business and blogs on Microsoft TechNet. He’s written technical scenarios. If you’re an IT professional with Windows several books on Windows scripting PowerShell experience, this book is ideal. for Microsoft Press, including Windows PowerShell 2.0 Best Practices and Windows PowerShell Scripting Guide. Discover how to: PowerShell • Use Windows PowerShell to automate Active Directory tasks • Explore available WMI classes and methods with CIM cmdlets • Identify and track scripting opportunities to avoid duplication • Use functions to encapsulate business logic and reuse code • Design your script’s best input method and output destination • Test scripts by checking their syntax and performance • Choose the most suitable method for running remote commands • Manage software services with Desired State Configuration Wilson BEST PRACTICES microsoft.com/mspress ISBN 978-0-7356-6649-8 U.S.A. $59.99 55999 Canada $68.99 [Recommended] 9 780735 666498 Operating Systems/Windows Server Celebrating 30 years! Ed Wilson 666498_Win_PowerShell_Best_Practices.indd 1 4/11/14 10:30 AM Windows PowerShell Best Practices Ed Wilson 666498_book.indb 1 12/20/13 10:50 AM Published with the authorization of Microsoft Corporation by: O’Reilly Media, Inc.
    [Show full text]
  • Powershell Notes for Professionals ™
    PowerShell Notes for Professionals ™ PowerShellNotes for Professionals 100+ pages of professional hints and tricks Disclaimer This is an unocial free book created for educational purposes and is GoalKicker.com not aliated with ocial PowerShell™ group(s) or company(s). Free Programming Books All trademarks and registered trademarks are the property of their respective owners Contents About ................................................................................................................................................................................... 1 Chapter 1: Getting started with PowerShell .................................................................................................... 2 Section 1.1: Allow scripts stored on your machine to run un-signed ........................................................................ 2 Section 1.2: Aliases & Similar Functions ....................................................................................................................... 2 Section 1.3: The Pipeline - Using Output from a PowerShell cmdlet ........................................................................ 3 Section 1.4: Calling .Net Library Methods .................................................................................................................... 4 Section 1.5: Installation or Setup .................................................................................................................................. 5 Section 1.6: Commenting ..............................................................................................................................................
    [Show full text]
  • Windows Embedded CE Operating System Components
    Windows Embedded CE Operating System Components Core Catalog Core C6G** Professional Plus Applications - End User ActiveSync File Sync Inbox Sync Pocket Outlook Database Sync CAB File Installer/Uninstaller Games Freecell Solitaire Help Remote Desktop Connection Remote Desktop Protocol (RDP) Audio Playback Redirection Cut/Copy/Paste Clipboard Redirection File Storage Redirection Filtered File Storage Redirection License Information Printer Redirection Serial and Parallel Port Redirection Smart Card Redirection User Interface Dialog Boxes Window s Netw ork Projector Sample Netw ork Projector Terminal Emulator Windows Messenger WordPad PRO version Applications and Services Development .NET Compact Framew ork 2.0 .NET Compact Framew ork 2.0 .NET Compact Framew ork 2.0 String Resources .Net Compact Framework 2.0 Localized String Resources String Resources Chinese(PRC) String Resources Chinese(Taiw an) String Resources French(France) String Resources German(Germany) String Resources Italian(Italy) String Resources Japanese(Japan) String Resources Korean(Korea) String Resources Portuguese(Brazil) String Resources Spanish(International Sort) .NET Compact Framew ork 2.0 - Headless .NET Compact Framew ork 2.0 String Resources - Headless .Net Compact Framework 2.0 Localized String Resources - Headless String Resources Chinese(PRC) – Headless String Resources Chinese(Taiw an) – Headless String Resources French(France) – Headless String Resources German(Germany) – Headless String Resources Italian(Italy) – Headless String Resources Japanese(Japan)
    [Show full text]
  • Accessibility in Windows 8
    Accessibility in Windows 8 Overview of accessibility in Windows 8, tutorials, and keyboard shortcuts Published by Microsoft Corporation, Trustworthy Computing One Microsoft Way Redmond, Washington 98052 Copyright 2012 Microsoft Corporation. All rights reserved. No part of the contents of this document may be reproduced or transmitted in any form or by any means without the written permission of the publisher. For permissions, visit www.microsoft.com. Microsoft and Windows are trademarks of Microsoft Corporation in the United States and/or other countries. Find further information on Microsoft Trademarks (http://www.microsoft.com/about/legal/en/us/IntellectualProperty/Trademarks/EN-US.aspx). Table of Contents Overview of Accessibility in Windows 8 .................................................................................................. 7 What’s new in Windows 8 accessibility ...................................................................................................................................7 Narrator and touch-enabled devices .................................................................................................................................................. 7 Magnifier and touch-enabled devices ............................................................................................................................................... 9 Ease of Access .............................................................................................................................................. 12 Make
    [Show full text]
  • Javafx 2.0 Dr
    1 <Insert Picture Here> JavaFX 2.0 Dr. Stefan Schneider Chief Technologist ISV Engineering The following is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle. 3 JavaFX 2.0 Agenda • Overview <Insert Picture Here> • Details • Architecture • Roadmap 4 What is JavaFX? 5 JavaFX is the evolution of the Java rich client platform, designed to address the needs of today’s and tomorrow’s customers. 6 Who is JavaFX for? 7 Target Developers • Current Java Developers • Former Java Developers • Web Developers • New Developers 8 What makes JavaFX special? 9 JavaFX defines itself as being a well designed, cross platform application development platform. It is fast. It is flexible. It delivers exceptional value to developers and end users. It is competitive. Most importantly, it leverages the massive existing Java eco system. Nobody else offers the complete package – exceptional developer experience, user experience, cross platform development and massive ecosystem. 10 TIOBE Index Popularity of a Language 11 The Java Eco System • Over 9 million Java developers • Java is taught in universities around the globe • Every major company uses Java 12 Value Proposition for Client Java • Leverage existing Java investment • Easier to find and train developers • Reduce risk by reducing complexity 13 Why is JavaFX important? 14 JavaFX encourages companies to use Java on the client and the server.
    [Show full text]
  • A Chinese Mobile Phone Input Method Based on the Dynamic and Self-Study Language Model
    A Chinese Mobile Phone Input Method Based on the Dynamic and Self-study Language Model Zhu Qiaoming, Li Peifeng, Gu Ping, Qian Peide School of Computer Science & Technology of Soochow University,Suzhou,215006 {qmzhu, pfli, pgu ,pdqian}@suda.edu.cn Abstract. This paper birefly introduces a Chinese digital input method named as CKCDIM (CKC Digital Input Method) and then applies it to the Symbian OS as an example, and it also proposes a framework of input method which adopted the Client/Server architecture for the handheld computers. To improve the performance of CKCDIM, this paper puts forward a dynamic and self-study language model which based on a general language model and user language model, and proposes two indexes which are the average number of pressed-keys (ANPK) and the hit rate of first characters (HRFC) to measure the performance of the input method. Meanwhile, this paper brings forward a modified Church-Gale smoothing method to reduce the size of general language model to meet the need of mobile phone. At last, the experiments prove that the dynamic and self-study language model is a steady model and can improve the performance of CKCDIM. Key Words: Chinese Digital Input Method, Architecture of Input Method, Dynamic and Self-study Language Model, HRFC, ANPK 1 Introduction With the developing of communication technology and the popularization of the mobile phone in China, the use of text message in mobile phone is growing rapidly. According to CCTV financial news report, the total number of Short Message Service use will grow from 300 billions in 2005 to 450 billions in 2006 in China.
    [Show full text]
  • Overcoming Limitations of the Hololens for Use in Product Assembly
    https://doi.org/10.2352/ISSN.2470-1173.2019.2.ERVR-179 © 2019, Society for Imaging Science and Technology Overcoming Limitations of the HoloLens for Use in Product Assembly Jack Miller, Melynda Hoover, Eliot Winer; Iowa State University - Ames, Iowa Abstract use in an AR work instruction assembly application. The research presented here will focus entirely on the development of the Augmented Reality (AR) is an emerging technology that could application and the novel techniques used to mitigate the limitations greatly increase training efficiency and effectiveness for assembly of the HoloLens. This application was also used to conduct a user processes. In fact, studies show that AR may reduce time and study comparing the effectiveness of work instructions delivered via errors by as much as 50%. While many devices are available to an AR HMD, AR tablet, tablet model-based instructions and display AR content, the use of Head Mounted Displays (HMDs) is desktop model-based instructions [2]. The results of this study are the most interesting for manufacturing and assembly as they free presented in a separate paper. For the study, due to all the custom up the user’s hands. Due to the emerging nature of this technology, enhancements made to the HMD system, it was necessary to there are many limitations including input, field of view, tracking validate that work instructions and other parts of the system were and occlusion. The work presented in this paper explores the use of functioning together properly. To accomplish this, a separate data the Microsoft HoloLens to deliver AR work instructions for visualization application was developed.
    [Show full text]
  • Silk4net User Guide Micro Focus 575 Anton Blvd., Suite 510 Costa Mesa, CA 92626
    Silk Test 15.5 Silk4NET User Guide Micro Focus 575 Anton Blvd., Suite 510 Costa Mesa, CA 92626 Copyright © Micro Focus 2014. All rights reserved. Portions Copyright © 1992-2009 Borland Software Corporation (a Micro Focus company). MICRO FOCUS, the Micro Focus logo, and Micro Focus product names are trademarks or registered trademarks of Micro Focus IP Development Limited or its subsidiaries or affiliated companies in the United States, United Kingdom, and other countries. BORLAND, the Borland logo, and Borland product names are trademarks or registered trademarks of Borland Software Corporation or its subsidiaries or affiliated companies in the United States, United Kingdom, and other countries. All other marks are the property of their respective owners. 2014-06-26 ii Contents Licensing Information ........................................................................................7 Silk4NET ..............................................................................................................8 Silk Test Product Suite ........................................................................................................8 Product Notification Service ................................................................................................ 9 Contacting Micro Focus ...................................................................................................... 9 Information Needed by Micro Focus SupportLine .................................................. 10 What's New in Silk4NET ...................................................................................11
    [Show full text]
  • Ohiou1090939388.Pdf (573.32
    A RE-CONFIGURABLE HARDWARE-IN-THE-LOOP FLIGHT SIMULATOR A thesis presented to the faculty of the Russ College of Engineering and Technology of Ohio University in partial fulfillment of the requirements for the degree Master of Science Eric Root June 2004 This Thesis Entitled A RE-CONFIGURABLE HARDWARE-IN-THE-LOOP FLIGHT SIMULATOR BY ERIC ROOT has been approved for the School of Electrical Engineering and Computer Science and the Russ College of Engineering and Technology by Maarten Uijt de Haag Assistant Professor of Electrical Engineering and Computer Science R. Dennis Irwin Dean, Russ College of Engineering and Technology ROOT, ERIC. M.S. June 2004. EECS A Re-Configurable Hardware-in-the-Loop Flight Simulator (70pp) Director of Thesis: Maarten Uijt de Haag This thesis describes the development of a fixed base flight simulator capable of hardware-in-the-loop testing of aviation electronics, or “avionics”. The system is composed of a pilot controlled 6 degree-of-freedom aircraft model, a flight display, and a hardware interface to an ARINC 429 avionics databus. Avionics can be connected to this databus for testing. These systems are combined in a modular fashion allowing easy re- configuration for use with various aircraft models, and testing of avionics using databuses other than ARINC 429. This modular design is achieved by using an aircraft model constructed in Matlab’s Simulink, and by relaying the model data to the display and ARINC 429 interface using the UDP network protocol. Approved: Maarten Uijt de Haag Assistant Professor of EECS Acknowledgments I would like to thank Dr.
    [Show full text]