1 / 39

Fundamental architectural styles

Fundamental architectural styles. Continued - Part 2. Fundamental architectural styles. Outline and bibliography: Layers [POSA1] – in 2.2 Pipes and Filters [POSA1] – in 2.2 Blackboard; with its variants: Repository, Active Database [POSA1] – in 2.2

etracey
Download Presentation

Fundamental architectural styles

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Fundamental architectural styles Continued - Part 2

  2. Fundamental architectural styles • Outline and bibliography: • Layers • [POSA1] – in 2.2 • Pipes and Filters • [POSA1] – in 2.2 • Blackboard; with its variants: Repository, Active Database • [POSA1] – in 2.2 • Event-driven (Implicit Invocation); variants: Publisher-Subscriber, Event-Bus • [POSA1] – from 3.6 • S. Gupta, J. Hartkopf, S. Ramaswamy: Event Notifier, a Pattern for Event Notification, in Java Report, 1998 (republished as chapter 11 in the book More Java Gems, Cambridge University Press, 2000) http://sites.google.com/site/jeffhartkopf/notifier • Optional reading: • David Garlan, Mary Shaw, An Introduction to Software Architecture, online http://www.cs.cmu.edu/afs/cs/project/able/ftp/intro_softarch/intro_softarch.pdf PART 2

  3. The Event-driven architectural style(Publisher-Subscriber, Event Bus) Bibliography: [POSA1] – din cap. 3.6 S. Gupta, J. Hartkopf, S. Ramaswamy: Event Notifier, a Pattern for Event Notification, in Java Report, 1998 (republished as chapter 11 in the book More Java Gems, Cambridge University Press, 2000) http://sites.google.com/site/jeffhartkopf/notifier

  4. The Event-driven style • Event driven systems are based on implicit invocation: instead of invoking a procedure directly, a component can broadcast one or more events. Other components in the system can register an interest in an event by associating a procedure with the event. When the event is announced the system itself invokes all of the procedures that have been registered for the event. Thus an event announcement ``implicitly'' causes the invocation of procedures in other modules.. Event Service op Obj1 Obj2 Obj1 Obj2 op Explicit invocation Implicit invocation

  5. Characteristics of Event-driven • The components of an application do not interact directly with each other, but through implicit invocation • The implicit invocation is facilitated by an infrastructure called Event Service • Implicit invocation may happen according to the variants • Publisher/Subscriber Direct • Event Channel (Event Bus)

  6. Publisher-Subscriber Direct • Examples: • Mechanisms in some programming languages: Java Event – Listener, C# Event – delegate • The Callback Mechanism, the Observer pattern • ReactiveX, reactive Java http://reactivex.io/intro.htmlhttps://github.com/ReactiveX/RxJava • In all these cases the subscriber knows the publisher

  7. Event Channel (Event Bus) Publisher Publisher Subscriber Subscriber Event Channel (Event Bus) Publisher Publisher Subscriber Subscriber Publish Event Receive Event

  8. Event Channel - Description • The central element = types of Events • Publishers: components that produce events, but they do not know the identity of the components that will “consume” these events. • It is possible that different publishers produce the same types of events. • Subscribers: components that receive certain types of events, but do not know and are not interested to know the identity of the components who publish these events (Subscriber) • It is possible that a Subscriber is interested in several different types of events • It is possible that a component is in the same time Publisher and Subscriber (for different event types) • The participants (Publishers or Subscribers) can be dynamically added or removed in the system • New event types can be dynamically added • Components (Publishers and Subscribers) are loosely coupled, they could be located in different processes

  9. The structure of an event-driven application Components (Elements): Publishers, Subscribers Connectors (Relations): publish event, subscribe to event type Infrastructure: Event Channel (Event Bus). Usually it is not part of the application ! Publisher Publisher Subscriber Subscriber Event Channel (Event Bus) Publisher Publisher Subscriber Subscriber

  10. The structure of an event-driven application Infrastructure Event Channel (Event Bus): EventChannel: subscribe(Subscriber, Event); publish(Event) Subscriber: notify(Event) Publisher Publisher Subscriber Subscriber Event Channel (Event Bus) Publisher Publisher Subscriber Subscriber

  11. Event Channel – Models of communication • Usually, when an event is received by (one or more) Subscribers, a data transfer will follow, from the Publisher who generated the event to the receiving Subscribers. • There are 4 models of communication, according to the type of data transfer: • Push: Publisher is the active source that initiates the transfer, while Subscriber is a passive destination. Event Channel = Notifier • Pull: Subscriber is active and initiates (requests) the data transfer from a passive source (Publisher) . Event Channel = Procurer • Hybrid Push/Pull: Publishers and Subscribers are active initiators of the transfers, which occur between buffers of the Event Channel = Queue • Hybrid Pull/Push: Publishers and Subscribers are passive components, the Event Channel has the initiative of the data transfers = Intelligent Agent

  12. Push: Notifier Active behaviour Passive behaviour Publisher Subscriber Push data Push data Notifier Publish Event Receive Event Data Transfer

  13. Pull: Procurer Passive behaviour Active behaviour Publisher Subscriber Pull data Pull data Procurer Publish Event Receive Event Data Transfer

  14. Hybrid Push/Pull: Queue Active behaviour Active behaviour Publisher Subscriber Pull data Push data Queue Publish Event Receive Event Data Transfer

  15. Hybrid Pull/Push: Intelligent Agent passive behaviour passive behaviour Publisher Subscriber Push data Pull data Intelligent Agent Publish Event Receive Event Data Transfer

  16. Discussion: compare the 4 combinations of Push/Pull • Advantages/disadvantages • Utility (examples) • Implementation

  17. The structure of an event-driven application Components (Elements): Publishers, Subscribers Connectors (Relations): publish event, subscribe to event type Infrastructure: Event Channel (Event Bus). Usually, it is not part of the application ! It can be a general purpose messaging/ event middleware like Java Message Service, CORBA message service, etc Publisher Publisher Subscriber Subscriber Event Channel (Event Bus) Publisher Publisher Subscriber Subscriber

  18. Example: A Network Management System Managed Objects Management System Router Hub Console Paging Managed Objects: network elements to be monitored; they are in a big number, of different types, and can dynamically appear and disappear (be on and off). When they are on, their activity is monitored by elements from the Management System. Monitored events: errors (of different degrees of severity), performance indicators Management System: comprises elements such as consoles, pagers, e-mail. Each element of the management system can be configured to receive notifications of certain types of monitored events.

  19. Example – A Network Management System • We solve the Network Management problem in event-driven style • We assume that there is an Event Service (EventBus) infrastructure, offering an API with following facilities: • subscribe • publish • inform - in all Subscribers • Managed Objects: Publishers • Management System: Subscribers

  20. Example – contd. • Event types:

  21. Example – contd. • A Subscriber: public class PagingSystem extends Subscriber {   public PagingSystem() {     FaultEvent event = new FaultEvent();     CriticalFaultFilter filter = new CriticalFaultFilter(); EventService.instance().subscribe(filter.getClass(), filter, this);   }   public void inform(Event event) {     // Assumes that this subscriber has only subscribed to FaultEvent     FaultEvent faultEvent = (FaultEvent) event;     // Respond to the event     System.out.println("Critical Fault Event occurred:" + faultEvent);   } }

  22. Example – contd. • A Publisher: public class Router {   public static void triggerPublication() { Event event = new FaultEvent(FaultEvent.CRITICAL); EventService.instance().publish(event); } }

  23. Event Service Infrastructures • Infrastructures that provides a subscribe-publish-notify API to be used by applications • Event Bus, in-process: • Guava (Google Core Libraries for Java) Event Bus: https://github.com/google/guava/wiki/EventBusExplained • Akka event bus http://doc.akka.io/docs/akka/current/java/event-bus.html • Event Channel (Event Bus) inter-process: part of middleware for distributed computing • Java Message Service (JMS)

  24. How to implement an Event Bus infrastructure ? • S. Gupta, J. Hartkopf, S. Ramaswamy: Event Notifier, a Pattern for Event Notification, in Java Report, 1998 (republished as chapter 11 in the book More Java Gems, Cambridge University Press, 2000) http://sites.google.com/site/jeffhartkopf/notifier

  25. Steps towards the design of a simple in-process Event-Bus • Starting point: The Network Management System example Management System Managed Objects Router Hub Console Paging

  26. Network Management Example:Try 1: A direct connections solution Managed Objects Management System • Problems: • Solution is not scalable: Every Managed object must transmit notifications to all Management System objects • Every change in Management System (example: adding e-mail Notification) affects all Managed Objects

  27. Network Management Example:Try 2: A solution using Mediator Managed Objects Management System • Any change in Management System (example: adding e-mail Notification) affects only the Mediator • Better scalability (number of dependencies is n+m instead of n*m) • Problems: • It does not support dynamic adaptation and differentiation of the management system (example - every managed object should be monitored by a subset (maybe a dynamically variable one) of objects from the Management System

  28. Network Management Example:Try 3: A solution with Observer Managed Objects Management System • Managed Objects must not know in advance the set of management system objects that are watching them • Problems: • Every object from the management system must know every managed object that is of its interest • Disadvantages: • Number of managed objects can be very big • Managed objects may appear and disappear

  29. Network Management Example:Try 4: The Event Channel Solution Subscriber Publisher Managed Objects Management System EventChannel Console Hub Paging System Router Assures a better decoupling between Managed Objects and Management System Managed Objects do not know the identity of objects in Management System Objects in Management System do not know the identity of managed Objects, only the types of events generated by these

  30. Event Channel - Applicability • When an object should be able to notify other objects of an event without needing to know who these objects are or what they do in response. • When an object needs to be notified of an event, but does not need to know where the event originated. • When more than one object can generate the same kind of event. • When some objects are interested in a broader classification of events, while others are interested in a narrower classification. • When an object may be interested in more than one kind of event. • When you need to dynamically introduce new kinds of events. • When objects participating in notification may be dynamically introduced or removed, as in distributed systems. • When you need to filter out events based on arbitrary criteria.

  31. Detailed Implementation of the Event Channel as an Event Notifier [Gupta, Hartkopf, Ramaswamy] • Participants: • Event: A common ancestor type for all events. • ConcreteEvent (example: FaultEvent): Represents a specific occurrence, possibly containing data about that occurrence. • Publisher (Hub, Router) Emits or produces events. • Subscriber: Defines an interface for all objects that need to handle events. • ConcreteSubscriber (Console, PagingSystem) Registers for events, and handles events by implementing the Subscriber interface. • EventService intermediary between subscriber and publisher. • Filter: Responsible for discarding events not of interest to a subscriber.

  32. Dynamic scenario • Scenario: • Concrete Subscriber registers with Event Channel, specifies the event types of interest and optionally a filter • Concrete Publisher announces the EventChannel when an event is produced • EventChannel determines which Concrete Subscribers are interested by the event and their filter applies to the current event • Event Channel notifies the Concrete subscribers

  33. Event Notifier Implementation: Discussion • Subscription is based on event types and not on identity of the publisher • Publishers and Subscribers are independent. Coupling between them is reduced to knowing the set of allowed events • Subscribing to a certain event type automatically comprises all its subtypes • Filtering of events discriminates further according to other event attributes (ex: source of event, associated data, etc) • Disadvantage: type safety vs generality: • Class • isKindOf method in Event • Disadvantage: Event Service is a point of bottleneck – performance and reliability. Solution: several different EventServices, each specialized for a certain category of events • Optional features:: Advertisment and Discovery of available Event Types

  34. Hybrid Event-Driven Architectures • Active Database: Event-Driven combined with Blackboard • Distributed Event Notification: Event-Driven combined with Broker

  35. Fundamental architectural styles:Conclusions (1) • They describes ways of structuring a system from different viewpoints: • Module viewpoint (static structure): Layers • Component & connector viewpoint (dynamic, runtime structure): Pipes-Filters, Blackboard, Event-driven • They describe elementary structures • In real systems, they may appear “pure” or “hybrids”

  36. Fundamental architectural styles:Conclusions (2) • The choice of the architectural style has an important influence over the systems properties ! • For further reading: David Garlan, Mary Shaw, An Introduction to Software Architecture, Technical Report Carnegie-Mellon University, no CMU-CS-94-166, http://www.cs.cmu.edu/afs/cs/project/able/ftp/intro_softarch/intro_softarch.pdf • Experiments: a problem is implemented according to different style and they study the impact of the style on the systems properties • Lab Assignment: “The Furniture Factory”

  37. Fundamental architectural styles:Conclusions (3) • The fundamental archit styles are general structuring solutions, that can be applied independent on a certain programming paradigm or technology • The components may have different granularities, from objects, components, and up to whole application that are integrated according to these patterns • For further reading: Enterprise Integration Patterns • Book: Enterprise Integration Patterns, by Gregor Hohpe and Bobby Woolf, A Martin Fowler Signature Book, Addison Wesley, 2004 • Site: http://www.eaipatterns.com/ • Shared Database (Repository): http://www.eaipatterns.com/SharedDataBaseIntegration.html • Pipes and Filters: http://www.eaipatterns.com/PipesAndFilters.html • Messaging (Event-Driven) http://www.eaipatterns.com/Messaging.html

More Related