[Zope3-dev] instance- and type-based event subscriptions
Jim Fulton
jim at zope.com
Tue Dec 23 11:50:54 EST 2003
Sometimes, we want to subscribe to events *only* for specific
objects or for specific types of objects. For example, we currently
have notification interfaces, IAddNotifiable and IRemoveNotifiable
that we call when objects are added or removed. These are used to
implement class-specific notification policies.
Similarly, we have a dependency framework, for, essentially, defining
integrity constraints mong objects. We prevent objects from being deleted
if they have dependents. This mechanism is fairly crude. We might, in some
cases, perform some action on a dependent object when the object it depends
on is removed. In any case, we want to be able to subscribe to events on the
affected object.
I'm thinking about providing the following mechanisms:
1. Type-based subscriptions through adapters
For object events, get partial multi adapters from
the affected object and event to ISubscriber. Subscriptions
can thus be registered for any of an object's interfaces, or
even for it's class.
This illustrates a need to provide an option to provide duplicate
partial adapters.
2, Instance-based subscriptions
For object events, we'll adapt the object to ISelfSubscriber:
class IInstanceEventChannel(IEventChannel):
"""Objects that support instance-based subscriptions
"""
and call it's notify method.
Similarly, to subscibe to events for an instance, we'll
get an IInstanceEventChannel adapter and call it's subscribe method.
We'll provide an adapter from IAnnotatable to ISubscriptions.
Note that both of these policies can be implemented with global subscribers
to object events. The policy need not be implemented in the event service
itself.
Jim
--
Jim Fulton mailto:jim at zope.com Python Powered!
CTO (540) 361-1714 http://www.python.org
Zope Corporation http://www.zope.com http://www.zope.org
More information about the Zope3-dev
mailing list