Upload
cecilia-washington
View
212
Download
0
Embed Size (px)
Citation preview
JMLC 2003, 26.08.2003, Klagenfurt AustriaChair of Software Engineering
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 AustriaChair of Software Engineering
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 AustriaChair of Software Engineering
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 Observer pattern follow the event-driven approach
JMLC 2003, 26.08.2003, Klagenfurt AustriaChair of Software Engineering
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 AustriaChair of Software Engineering
Use of the Event Library
Using the Event Library consists only of 3 steps:
1. PUBLISHERdefines an event type
2. SUBSCRIBERsubscribes a feature of an object to an event type
3. PUBLISHERpublishes an event (of a certain event type)
JMLC 2003, 26.08.2003, Klagenfurt AustriaChair of Software Engineering
Example: Event Library in action
JMLC 2003, 26.08.2003, Klagenfurt AustriaChair of Software Engineering
Class SENSOR
class SENSOR
feature -- Access
temperature: INTEGER-- Container temperature
humidity: INTEGER-- Container humidity
pressure: INTEGER-- Container pressure
end -- class SENSOR
JMLC 2003, 26.08.2003, Klagenfurt AustriaChair of Software Engineering
Class SENSOR
class SENSOR
feature -- Access
temperature: INTEGER-- Container temperature
feature -- Element change
set_temperature (a_temperature: INTEGER) is-- Set temperature to a_temperature.
requirevalid_temperature: a_temperature > -100 and a_temperature <
1000 do
temperature := a_temperature ensure
temperature_set: temperature = a_temperature end
end -- class SENSOR
JMLC 2003, 26.08.2003, Klagenfurt AustriaChair of Software Engineering
(1) Publisher defines an event type
class SENSOR
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.
invarianttemperature_event_not_void: temperature_event /= Void
end -- class SENSOR
EVENT_TYPE [EVENT_DATA -> TUPLE]
[40, 60]
[25]
[]
conforms to
conforms to
JMLC 2003, 26.08.2003, Klagenfurt AustriaChair of Software Engineering
(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 AustriaChair of Software Engineering
(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.
requirean_action_not_void:
an_action /= Voidan_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 AustriaChair of Software Engineering
(3) Publisher publishes an event
class SENSOR
feature -- Access
temperature: INTEGER-- Container temperature
feature -- Element change
set_temperature (a_temperature: INTEGER) is-- Set temperature to a_temperature.
requirevalid_temperature: a_temperature > -100 and a_temperature < 1000
dotemperature := a_temperature temperature_event.publish ([temperature])
ensuretemperature_set: temperature = a_temperature
end
feature – Eventstemperature_event: EVENT_TYPE [TUPLE [INTEGER]]
end -- class SENSOR
JMLC 2003, 26.08.2003, Klagenfurt AustriaChair of Software Engineering
(3) Publisher publishes an event
class SENSOR…
feature -- Element change
set_temperature (a_temperature: INTEGER) is-- Set temperature to a_temperature.
requirevalid_temperature: a_temperature > -100 and a_temperature < 1000
dotemperature := a_temperature temperature_event.publish ([temperature])
ensuretemperature_set: temperature = a_temperature
end
feature – Eventstemperature_event: EVENT_TYPE [TUPLE [INTEGER]]
end -- class SENSOR
Class EVENT_TYPE
publish (arguments: EVENT_DATA) is-- Publish all not suspended actions from the subscription list.
requirearguments_not_void: arguments /= Void
EVENT_TYPE [EVENT_DATA -> TUPLE]
JMLC 2003, 26.08.2003, Klagenfurt AustriaChair of Software Engineering
(3) Publisher publishes an event
class SENSOR…
feature -- Element change
set_temperature (a_temperature: INTEGER) is-- Set temperature to a_temperature.
requirevalid_temperature: a_temperature > -100 and a_temperature < 1000
dotemperature := a_temperature temperature_event.publish ([temperature])
ensuretemperature_set: temperature = a_temperature
end
feature – Eventstemperature_event: EVENT_TYPE [TUPLE [INTEGER]]
end -- class SENSOR
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 AustriaChair of Software Engineering
Architecture
Classification according to Eugster P. Th. [3] Space decoupling
The publisher and the subscribed class do not know each other Flow decoupling
Publishers should be not blocked, while publishing events Time decoupling
Publishers 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 AustriaChair of Software Engineering
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 AustriaChair of Software Engineering
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 AustriaChair of Software Engineering
References
1. Arslan V.: Event Library, at http://se.inf.ethz.ch/people/arslan
2. Eiffel Software Inc.: Agents, iteration and introspection, athttp://archive.eiffel.com/doc/manuals/language/agent/agent.pdf
3. 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
4. Gamma E., Helm R., Johnson R., Vlissides J.: Design Patterns: Elements of Reusable Object-Oriented Software, 1st edition, Addison-Wesley, 1995.
5. 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.
6. 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 AustriaChair of Software Engineering
Questions ?
Thank you foryour attention!