Download
event library an object oriented library for event driven design n.
Skip this Video
Loading SlideShow in 5 Seconds..
Event Library: an object-oriented library for event-driven design PowerPoint Presentation
Download Presentation
Event Library: an object-oriented library for event-driven design

Event Library: an object-oriented library for event-driven design

193 Views Download Presentation
Download Presentation

Event Library: an object-oriented library for event-driven design

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. Event Library: an object-oriented library for event-driven design Volkan Arslan, Piotr Nienaltowski, Karine Arnout Chair of Software Engineering, ETH Zurich, Switzerland http://se.inf.ethz.ch{Volkan.Arslan, Piotr.Nienaltowski, Karine.Arnout}@inf.ethz.ch JMLC 2003, 26.08.2003, Klagenfurt Austria

  2. Overview • Motivation • Use of the Event Library • Example: Event Library in action • Architecture of the Event Library • Conclusion and future work JMLC 2003, 26.08.2003, Klagenfurt Austria

  3. Event-driven programming • Event-driven programming is very popular, especially for GUI applications • Facilitates the separation of concerns:application layer and GUI • Publish/Subscribe and Observerpattern follow the event-driven approach JMLC 2003, 26.08.2003, Klagenfurt Austria

  4. Event Library Make things as simple as possible, but not simpler. (A. Einstein) Turn the Observer pattern to a simple, reusable, but powerful library  Event Library JMLC 2003, 26.08.2003, Klagenfurt Austria

  5. Use of the Event Library Using the Event Library consists only of 3 steps: • PUBLISHERdefines an event type • SUBSCRIBERsubscribes a feature of an object to an event type • PUBLISHERpublishes an event (of a certain event type) JMLC 2003, 26.08.2003, Klagenfurt Austria

  6. Example: Event Library in action JMLC 2003, 26.08.2003, Klagenfurt Austria

  7. Class SENSOR classSENSOR feature -- Access temperature: INTEGER --Container temperature humidity: INTEGER --Container humidity pressure: INTEGER --Container pressure end -- classSENSOR JMLC 2003, 26.08.2003, Klagenfurt Austria

  8. Class SENSOR classSENSOR feature -- Access temperature: INTEGER --Container temperature feature -- Element change set_temperature (a_temperature: INTEGER)is -- Set temperature to a_temperature. require valid_temperature: a_temperature > -100 and a_temperature < 1000 do temperature :=a_temperature ensure temperature_set: temperature =a_temperature end end -- classSENSOR JMLC 2003, 26.08.2003, Klagenfurt Austria

  9. (1) Publisher defines an event type classSENSOR feature -- Access temperature: INTEGER --Container temperature feature -- Element change set_temperature (a_temperature: INTEGER)is -- Set temperature to a_temperature. ... feature --Events temperature_event: EVENT_TYPE [TUPLE [INTEGER]] --Event associated with attribute temperature. invariant temperature_event_not_void: temperature_event /= Void end -- classSENSOR EVENT_TYPE [EVENT_DATA -> TUPLE] [] conforms to [25] conforms to [40, 60] JMLC 2003, 26.08.2003, Klagenfurt Austria

  10. (2) Subscription to an event type In subscriber class MAIN_WINDOW Sensor.temperature_event.subscribe (agent application_window_1.display_temperature (?)) In the subscribed class APPLICATION_WINDOW display_temperature (a_temperature: INTEGER)is -- Update the text of temperature_value_label -- with a_temperature. do … end JMLC 2003, 26.08.2003, Klagenfurt Austria

  11. (2) Subscription to an event type In class MAIN_WINDOW (Subscriber) Sensor.temperature_event.subscribe (agent application_window_1.display_temperature (?)) Class EVENT_TYPE subscribe (an_action: PROCEDURE [ANY, EVENT_DATA])is -- Add an_action to the subscription list. require an_action_not_void: an_action /= Void an_action_not_already_subscribed: not has (an_action) ensure an_action_subscribed: count = old count + 1 and has (an_action) EVENT_TYPE [EVENT_DATA -> TUPLE] JMLC 2003, 26.08.2003, Klagenfurt Austria

  12. (3) Publisher publishes an event classSENSOR feature -- Access temperature: INTEGER --Container temperature feature -- Element change set_temperature (a_temperature: INTEGER)is -- Set temperature to a_temperature. require valid_temperature: a_temperature > -100 and a_temperature < 1000 do temperature :=a_temperature temperature_event.publish ([temperature]) ensure temperature_set: temperature =a_temperature end feature – Events temperature_event: EVENT_TYPE [TUPLE [INTEGER]] end -- classSENSOR JMLC 2003, 26.08.2003, Klagenfurt Austria

  13. (3) Publisher publishes an event classSENSOR … feature -- Element change set_temperature (a_temperature: INTEGER)is -- Set temperature to a_temperature. require valid_temperature: a_temperature > -100 and a_temperature < 1000 do temperature :=a_temperature temperature_event.publish ([temperature]) ensure temperature_set: temperature =a_temperature end feature – Events temperature_event: EVENT_TYPE [TUPLE [INTEGER]] end -- classSENSOR Class EVENT_TYPE publish (arguments: EVENT_DATA)is -- Publish all not suspended actions from the subscription list. require arguments_not_void: arguments /= Void EVENT_TYPE [EVENT_DATA -> TUPLE] JMLC 2003, 26.08.2003, Klagenfurt Austria

  14. (3) Publisher publishes an event classSENSOR … feature -- Element change set_temperature (a_temperature: INTEGER)is -- Set temperature to a_temperature. require valid_temperature: a_temperature > -100 and a_temperature < 1000 do temperature :=a_temperature temperature_event.publish ([temperature]) ensure temperature_set: temperature =a_temperature end feature – Events temperature_event: EVENT_TYPE [TUPLE [INTEGER]] end -- classSENSOR Class EVENT_TYPE publish (arguments: EVENT_DATA)is -- Publish all not suspended actions from the subscription list. do do_all (agent{PROCEDURE [ANY, EVENT_DATA]}.call (arguments)) end EVENT_TYPE [EVENT_DATA -> TUPLE] JMLC 2003, 26.08.2003, Klagenfurt Austria

  15. Architecture Classification according to Eugster P. Th. [3] • Space decouplingThe publisher and the subscribed class do not know each other • Flow decouplingPublishers should be not blocked, while publishing events • Time decouplingPublishers and subscribed objects do not have to participate actively in the interaction at the same time (e.g. distributed setting) JMLC 2003, 26.08.2003, Klagenfurt Austria

  16. Conclusion Event Library is simple to use • Consists of only one class EVENT_TYPE • Publisher, Subscriber and Subscribed object • Supports full event-driven programming • Type safe • For advanced needs, class EVENT_TYPE is extendible It relies on powerful language mechanism • Genericity (including constrained genericity) • Tuples • Agents • Inheritance JMLC 2003, 26.08.2003, Klagenfurt Austria

  17. Future work Extension of the Event Library • “Conditional Event subscription” possible when inline agents are introduced to the language • Use of concurrency (SCOOP) in order to obtain flow and time decoupling • Guaranteeing response times for subscribed objects when an event of a certain event type is triggered. • General publish-subscribe mechanism available as Web Service (time decoupling) JMLC 2003, 26.08.2003, Klagenfurt Austria

  18. References • Arslan V.: Event Library, at http://se.inf.ethz.ch/people/arslan • Eiffel Software Inc.: Agents, iteration and introspection, athttp://archive.eiffel.com/doc/manuals/language/agent/agent.pdf • Eugster P. Th., Felber P., Guerraoui R., Kermarrec A.-M.: The Many Faces of Publish/Subscribe, Technical Report 200104 athttp://icwww.epfl.ch/publications/documents/IC_TECH_REPORT_200104.pdf • Gamma E., Helm R., Johnson R., Vlissides J.: Design Patterns: Elements of Reusable Object-Oriented Software, 1st edition, Addison-Wesley, 1995. • Meyer B.: The power of abstraction, reuse and simplicity: an object-oriented library for event-driven design, at http://www.inf.ethz.ch/~meyer/ongoing/events.pdf. • Nienaltowski P., Arslan V.: SCOOPLI: a library for concurrent object-oriented programming on .NET, in Proceedings of the 1st International Workshop on C# and .NET Technologies, University of West Bohemia, 5-8 February 2003, Pilsen, Czech Republic. JMLC 2003, 26.08.2003, Klagenfurt Austria

  19. Questions ? Thank you foryour attention! JMLC 2003, 26.08.2003, Klagenfurt Austria