Re: Thoughts on EventManager & async posting

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Wed Nov 26 2003 - 16:21:51 EST

  • Next message: Andrus Adamchik: "Re: Thoughts on EventManager & async posting"

    On Nov 24, 2003, at 9:32 AM, Holger Hoffstätte wrote:

    > Wouldn't it be easier for the event poster to not have to make this
    > decision and instead let each recipient handle this for himself? I
    > guess
    > the preference could be set at registration time (in addListener()) and
    > the entire management could be implemented for example by separation of
    > the notification queues into immediate and asynchronous receivers.

    One does not conflict with the other. I have nothing against having
    asynchronous receivers, and setting this in the "addListener". I think
    it is very useful (I agree that in most cases sender shouldn't guess
    about the receivers behavior), and with current improved
    synchronization it will only lock the subject, not the whole
    EventManager. Also if we can take advantage of the existing pool of
    dispatch threads in the EventManager, this would be even better ;-).

    On the other hand I'd like to preserve asynchronous send capability. I
    guess it won't hurt if it stays around. I still think I don't have a
    full picture of all possible cases.

    > Originally I wanted to use Doug Lea's excellent Concurrent utilities
    > for
    > this (something we should probably do anyway - see
    > http://gee.cs.oswego.edu/dl/classes/EDU/oswego/cs/dl/util/concurrent/)

    Looks interesting. I can't see where we can use it in Cayenne right
    away, but it looks like a very nice library.

    A few additional notes - to make EventManager more friendly and less
    confusing I suggest a few API changes:

    1. Instead of postEvent(..) and postEvent(...,boolean), I suggest self
    explanatory "postNow", "postLater" methods.

    2. Change "addListener" to throw a runtime exception instead of
    NoSuchMethodException. This will make the code cleaner. Currently I am
    writing a small scope/cayenne Swing application (see
    andrus-sandbox/examples/HRSwingBrowser), and having to wrap all
    "addListener" calls in try/catch is a real hassle, especially since
    most listeners implement an interface known upfront, so "catch" block
    usually looks like that:

       catch(NoSuchMethodException ex) {
         // this will never happen!!
         // but we need to satisfy the compiler
       }

    :-)
    Andrus



    This archive was generated by hypermail 2.0.0 : Wed Nov 26 2003 - 16:21:57 EST