[Zope3-dev] EventService, references, and subscription semantics

Steve Alexander steve@cat-box.net
Tue, 26 Feb 2002 09:01:40 +0000


Shane Hathaway wrote:
>
> That sounds reasonable for this case, but I don't think we've had enough
> time to think to be designing a service yet.  Maybe we have, but I'd like
> us to leave room for adding an event subscriber that either provides its
> own reference, or doesn't need to use a reference at all.
 >
> Hmm, maybe that's not a problem: the addSubscriber() method of the event
> service (or whatever the method is called) might accept either a reference
> object or some other kind of object; if the object is not a reference then
> the event service tries to make one for it.  That's a similar pattern to
> what getAdapter() does.

I suggest that this isn't the job of the subscribe() method of the 
EventService. The ReferenceService (as in the diagram in my last email) 
could just return the object if it already implements IReference.


> I think IReferenceLookup is the wrong name--I think what you want is
> something like IReferenceGenerator.  The IReferenceGenerator is only used
> when creating a reference, not when dereferencing one, which the name
> "IReferenceLookup" tends to imply (although the implementation might, at
> its option, refer to the IReferenceGenerator that created it in order to
> dererence.)

Sure. It is good to have more accurately descriptive names :-)

So, heres what we have so far. I guess I should put this on a wiki soon.


Either an object can be its own IReference, or the object's context 
provides a utility to say how to make an appropriate kind of reference, 
or the IReferenceGenerator utility/service provides IReferences, based 
on sensible zcml configured defaults.


       Root  :-- IReferenceGenerator (service/utility)
      /    \
     Bar   Foo
    /        \
  Baz        LDAPUserFolder   :-- IReferenceGeneratorForContext (utility)
                \
                 LDAP Principal Object


So, object Baz gets the LDAP Principal Object (let's call it "user"). It 
wants to store a reference to user. Baz might well be an IEventService, 
or other kind of ISubscribable object.

   1: Baz gets the IReferenceGenerator service

   2: Baz passes user to the IReferenceGenerator service

   3: If user implements IReference, the IReferenceGenerator service
      simply returns user as its own IReference.

   4: Otherwise, the IReferenceGenerator service examines user's context
      wrapper, and walks the wrapper looking for an
      IReferenceGeneratorForContext utility.

   5: The IReferenceGenerator service passes user to the
      IReferenceGeneratorForContext utility, which returns an appropriate
      IReference object.

   6: If the IReferenceGeneratorForContext service returns None, or if it
      can't be found, the IReferenceGenerator service does whatever it
      is configured (by zcml directives perhaps) to do, such as return
      a simple default IReference for the object.


What about comparing IReferences. I think I'd like IReference to 
implement __cmp__ or something, and have some appropriate semantics.

--
Steve Alexander