Broker Revisited
Total Page:16
File Type:pdf, Size:1020Kb
Broker Revisited Michael Kircher, Klaus Jank, Christa Schwanninger, Michael Stal {Michael.Kircher,Klaus.Jank,Christa.Schwanninger, Michael.Stal}@siemens.com Markus Voelter [email protected] Copyright © 2004, Kircher, Voelter, Jank, Schwanninger, Stal D5-1 After having written the Remoting Patterns book [VKZ04], we felt that it was necessary to take a look at fundamental pattern in that context: Broker of [POSA1]. This revised pattern description reflects the current state of discussion. Main changes are in the responsibilities as well as the participants area of the original Broker pattern: • Finding remote objects has been separated out. Possible solutions therefore are documented as Lookup pattern in [POSA3]. • The original Broker pattern has a Broker participant, which responsibility is the transmission of requests from clients to server, as well as the transmission of responses and exceptions back to the client. This participant has been replaced by a client-side part called Requestor and a server-side part called Invoker. • The original Broker pattern contains a client-side and server-side proxy participant, which encapsulate system-specific functionality such as marshaling of requests and responses and mediation between client and requestor, and invoker and servant, respectively. Broker Revisited replaces these participants by encapsulating their responsibilities within other participants. Proxies are only needed when remote invocations are expected to be invoked as if they were local invocations. As this is not in every known use the case, we made them optional. They are not part of the core responsibility of the Broker Revisited pattern. • Since proxies when needed should be able to be created at runtime, they shouldn’t contain any system-specific functionality. Another reason why client proxies have been made optional is that location transparency is not always necessary. • Broker Revisited focuses on remote communication, host-local communication is only an exception/special-case. • The Bridge participant of the original Broker pattern has been separated out, because interoperability issues such as type system transparency are handled by an appropriate network and marshaling protocol. D5-2 Broker Revisited The Broker Revisited pattern connects clients with remote objects by mediating invocations from clients to remote objects while encapsulating the details of network communication. Example Suppose, you are going to design an innovative framework for home automation where a central network allows to connect different actuators and sensors. The framework should be capable of integrating heterogeneous devices such as VCRs, TVs, notebooks, lighting systems, PDAs, refrigerators, coolers, or security sensors. It provides connectivity using fixed network cables as well as wireless communication lines. External access to the E- Home system is possible via secured Internet access. Central command and control services help to monitor and modify the system’s behavior or malfunctioning. Users and administrators might deploy custom services that leverage multiple devices to allow emerging behavior such as triggering events on one device when other events on different devices occur. Examples could be a recording service where the recording of a television broadcast is triggered by a central clock or the activation of the cooling system by an external telephone call. Services will be implemented by the different vendors of the devices. In order to make all this possible, the services have to collaborate. But the services are located on various controllers in the house, connected through a network between them and software running on those devices. It should be possible to change the collaborations easily and services should not be expected to always run on the same controller. To make the framework successful it is necessary to make it easy for vendors to provide new services quickly, without much overhead in learning how to develope software for the framework. Context A system that consists of multiple distributed objects that need to interact with each other synchronously or asynchronously. Problem Distributed software systems face many challenges that do not arise in single-process software. One major challenge is the communication across unreliable networks. Other challenges are the integration of heterogeneous components into coherent applications, as well as the efficient usage of networking resources. If developers of distributed systems must master all these challenges within their application code, they likely will loose their primary focus: developing application code that resolves their domain-specific responsibilities well. Communication across networks is more complex than local communication, because remote communication concerns have to be considered, e.g. connections need to be established, invocation parameters have to be converted into a network-capable format and transmitted, and a new set of possible errors has to be coped with. This requires handling invocations to local objects differently than invocations of remote objects. Additionally, the tangling of remote communication concerns with the overall application structure complicates the application logic. The following forces must be addressed: • Location Independence—The location of the remote objects should not be hard-wired into client applications. It should be possible to run remote objects on different machines without adaptation of the client's program code. D5-3 • Separation of Concerns—Application logic and remote communication concerns should be well separated to manage complexity and allow for evolution of each concern independent of the other. • Resource Management—Network and other communication resources have to be managed efficiently to minimize footprint and overhead of distributed systems. • Type System Transparency—Differences between type systems should be coped with transparently. • Portability—Platform dependencies should be encapsulated and separated from the application logic. Solution Separate the communication functionality of a distributed system from the application functionality by isolating all communication related concerns. Introduce a client-side requestor and a server-side invoker to mediate invocations between client and remote object. The client-side requestor provides an interface to construct and forward invocations to the server-side invoker. The invoker dispatches incoming requests to the remote object and returns potential results of remote object invocations to the requestor. A marshaler on each side of the communication path handles the transformation of requests and responses from programming-language native data types into a byte array that can be sent across the wire, and vice versa. The details of communication and management of communication resources is hidden from the client and the remote object by the requestor and invoker. Further, the invoker provides a registration interfaces. This allows remote object implementations, so called servants, to be registered and made accessible to clients. Structure The following participants form the structure of the Broker Revisited pattern: A client interacts with a remote object. A requestor forwards requests to an invoker across the network. An invoker invokes requests on a servant. It adapts the interface of the servant, so that the other participants can stay independent of any remote object specifics. Depending on the implementation, this invoker-internal Adapter [GoF] can be decoupled and large parts of the invoker can serve multiple remote objects. A servant implements a remote object the clients wants to use, whereas the remote object may represent an actual object, a component, or a service. A marshaler transforms between invocation parameters/results and a serialized format. D5-4 The following CRC cards describe the responsibilities and collaborations of the participants Class Collaborator Client • Requestor Class Collaborator Requestor • Invoker Responsibility • Marshaler • Invokes remote objects on the requestor • Collects all invocation Responsibility information, such as the • Provides an invocation remote object reference interface, where clients and the invocation can hand over the request parameters, in a request object. object. • Marshals the invocation parameters on invocation, and de-marshal the returned results using the marshaler. Class Collaborator • Uses communication Invoker • Marshaler resources, such as • Requestor network connections, • Servant threads, and possibly manages those. • Sends invocations to Responsibility remote objects, • Allows servants to be respectively the invoker registered. instances they are • Receives requests from the registered with. transport layer. • Hands over the request to • Demarshals request the transport layer. parameters using the • Waits for responses from marshaler, and marshals remote objects and blocks results of the invocation in clients until the result can a response using the be returned. marshaler. • Invokes operations on servants using the request Class Collaborator parameters. Servant • Uses the communication resources and possibly Responsibility manages those. • Implements the remote • Sends responses back to object’s functionality. the requestor. Class Collaborator Marshaler Responsibility • De-/Marshals invocation parameters and results. D5-5 The dependencies between the participants are illustrated by the following class diagram. Marshaler Servant Client serialize () method A () deserialize