subscribe on system change
I want to do some logic when there is a change on the system, like when a new class is loaded or when a method change. I don't want to put this logic explicit on the methods of the system who do that. I would like to know if i could subscribe to those special events (method change, new method, changes on a class and so on) so I can do what I want outside those methods. I heard about the Announcements but I don't know if Announcements could help with this problem. Can anyone give me some highlights to do those things? Thanks! (I'm really trying with my english, hope it's understandable) -- Miguel Enrique Campusano Araya Estudiante de IngenierÃa Civil en Computación Universidad de Chile
That depends on what version of Pharo you use. In Pharo 1.4 you can use SystemChangeNotifier to do something like this: SystemChangeNotifier uniqueInstance notify: toSomeObject ofSystemChangesOfItem: #class change: #Added using: #someMethod:. then if a new class is added to the system, SystemChangeNotifier will call #someMethod: on toSomeObject, passing an Event to #someMethod:. You can browse the code on SystemChangeNotifier to see all the notification you can use, and the package "System-Change Notification" to see the events you can receive. In Pharo 2.0 you can do the same thing using SystemAnnouncer: SystemAnnouncer uniqueInstance on: ClassAdded send: #someMethod: to: toSomeObject. You can see the different announcements you can use on browsing the package "System-announcements". In this example #someMethod: will receive an announcement. -- Daniel Galdames El domingo, 14 de octubre de 2012 a las 20:14, Miguel Enrique Campusano Araya escribió:
I want to do some logic when there is a change on the system, like when a new class is loaded or when a method change. I don't want to put this logic explicit on the methods of the system who do that. I would like to know if i could subscribe to those special events (method change, new method, changes on a class and so on) so I can do what I want outside those methods. I heard about the Announcements but I don't know if Announcements could help with this problem.
Can anyone give me some highlights to do those things?
Thanks! (I'm really trying with my english, hope it's understandable)
-- Miguel Enrique Campusano Araya Estudiante de IngenierÃa Civil en Computación Universidad de Chile
Thanks Daniel! and by the way, I'm using Pharo 2.0 -- View this message in context: http://forum.world.st/subscribe-on-system-change-tp4651205p4651326.html Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
Le 15/10/2012 08:10, Daniel Galdames a écrit :
That depends on what version of Pharo you use. In Pharo 1.4 you can use SystemChangeNotifier to do something like this:
SystemChangeNotifier uniqueInstance notify: toSomeObject ofSystemChangesOfItem: #class change: #Added using: #someMethod:.
then if a new class is added to the system, SystemChangeNotifier will call #someMethod: on toSomeObject, passing an Event to #someMethod:. You can browse the code on SystemChangeNotifier to see all the notification you can use, and the package "System-Change Notification" to see the events you can receive.
In Pharo 2.0 you can do the same thing using SystemAnnouncer:
SystemAnnouncer uniqueInstance on: ClassAdded send: #someMethod: to: toSomeObject.
You can see the different announcements you can use on browsing the package "System-announcements". In this example #someMethod: will receive an announcement.
In Pharo 2.0, it could be interesting to use the weak variant of the subscription. SystemAnnouncer uniqueInstance weak on: ClassAdded send: #someMethod: to: toSomeObject. To create a weak link to it. A convenient method when you develop those things is: SystemAnnouncer uniqueInstance unsubscribe: toSomeObject. Because you usually spend time refactoring the #someMethod: above, and it helps knowing how to remove existing triggers. And a nice tool is to look at the announcements as they are produced, with SystemAnnouncer uniqueInstance open These are the tools I found usefull when tracing the system notifications. What I missed? A browser able to show who is subscribing to what. Thierry
-- Daniel Galdames
El domingo, 14 de octubre de 2012 a las 20:14, Miguel Enrique Campusano Araya escribió:
I want to do some logic when there is a change on the system, like when a new class is loaded or when a method change. I don't want to put this logic explicit on the methods of the system who do that. I would like to know if i could subscribe to those special events (method change, new method, changes on a class and so on) so I can do what I want outside those methods. I heard about the Announcements but I don't know if Announcements could help with this problem.
Can anyone give me some highlights to do those things?
Thanks! (I'm really trying with my english, hope it's understandable)
-- Miguel Enrique Campusano Araya Estudiante de IngenierÃa Civil en Computación Universidad de Chile
-- Thierry Goubier CEA list Laboratoire des Fondations des Systèmes Temps Réel Embarqués 91191 Gif sur Yvette Cedex France Phone/Fax: +33 (0) 1 69 08 32 92 / 83 95
participants (4)
-
Daniel Galdames -
Goubier Thierry -
Miguel Campusano -
Miguel Enrique Campusano Araya