Multiple Listeners

Tyler Padley's Avatar

Tyler Padley

04 Mar, 2011 10:04 PM

I seem to be having an issue. I can dispatch an event from one mediator, and it's picked up by another mediator, but not by third. Both the second and third mediators are listening via the context listener. Is there any reason why would one get the event and the other would not?

  1. 1 Posted by krasimir on 04 Mar, 2011 10:13 PM

    krasimir's Avatar

    Hi,

    is that event a custom one? Did you override the clone method?

  2. 2 Posted by Tyler on 04 Mar, 2011 10:17 PM

    Tyler's Avatar

    Hmm. I extended event and overrode clone at that level, but I subclassed that event and didn't override clone in the subclasses. Still, it's strange that one mediator would work over the other. overriding clone in the subclasses makes them both work.

  3. Support Staff 3 Posted by creynders on 05 Mar, 2011 07:25 AM

    creynders's Avatar

    Yep, all Event subclasses need to override clone, even subclasses of subclasses. The reason why the first listening mediator does pick it up, is because it receives the "original" dispatched event with all it's properties filled in. After that the event is cloned and the clone's properties are empty, that's why the next listeners don't receive it.
    Now, WHY events get cloned instead of simply get passed through, I don't know. It seems like a lot of overhead especially for something as essential and common as events.

  4. Support Staff 4 Posted by Till Schneidere... on 05 Mar, 2011 02:06 PM

    Till Schneidereit's Avatar

    That's not entirely true. You need to implement clone if and only if
    you need to preserve some custom properties on your subclass. If you
    don't need to do that, you also don't need to override clone.

    Also, the event isn't cloned between two mediators receiving it.
    Cloning only happens on redispatch, which doesn't happen if you just
    use Mediator#dispatch.

    I suspect what's really going on is that the mediator not receiving
    the event simply doesn't yet exist at the time the event is
    dispatched. To test that, you should add logging to both the event
    dispatching and the mediator creating and see in which order the log
    messages appear.

    If this assumption turns out to be correct, you should check out
    Stray's RelaxedEventMap: It's specifically tailored to help out with
    situations like this:
    https://github.com/Stray/robotlegs-utilities-RelaxedEventMap

  5. 5 Posted by Tyler on 05 Mar, 2011 03:43 PM

    Tyler's Avatar

    @tschneidereit - The mediators were all created and present at the time. Everything gets time to wire up because this event is dispatch in reaction to a user event. It was never hitting the third mediator until I overrode clone in the sublcass.

  6. Support Staff 6 Posted by Till Schneidere... on 05 Mar, 2011 03:50 PM

    Till Schneidereit's Avatar

    Interesting, thanks for following up!

    I think I'll create a unit test just to investigate what's going on,
    as I don't see any reason for that to happen in the code-base.

  7. Stray closed this discussion on 03 Apr, 2011 11:12 AM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac