A consistent listener implementation

Mark Finkle mfinkle at mozilla.com
Tue May 6 21:07:50 PDT 2014


Message Bus or Event Bus or Publish / Subscribe or Subject / Observer 

Great for decoupling code. Gecko implements this in nsIObserverService and we have our own messaging system for JS <-> Java. It works well. 

We fall down when dealing with Java-only communication. We created a multi-listener in Tabs.java with the OnTabsChangedListener and it's not as nice as we'd like: 
http://mxr.mozilla.org/mozilla-central/source/mobile/android/base/Tabs.java#535 

----- Original Message -----

> My initial response that any generalization of Event Listening is
> indistinguishable from an EventBus.
Agreed 

> I'm generally in favour of EventBuses, but would raise two points which have
> bitten me in the past:

> * if the event bus / generalized listener manager is does not handle
> threading, then this leads to a class of threading bugs. I ding Otto for
> this reason (here's a PR implementing that behaviour ).
> * keeping the wiring separate and away from the implementation.
> * some careful thought needs to go into making sure we're not chucking around
> undifferentiated/untyped message or data objects. Otto is pretty good for
> this, but probably a bit too simple.
I don't know. I like easy to create messages. Creating a calss for all message types is Java's way of adding coupling back into an event bus. Boooo Java! 

> > perhaps it's time to start thinking about consistent use of messaging for
> > inter-component communication.
> 

> The new NativeJSObject stuff in the new sendMessageToJava is a good start,
> though there is too much registering, deregistering and switching for my
> tastes.

> My f2f discussions with mfinkle would indicate he's not impressed by more RPC
> type implementations.
Indeed. Message (event) buses are for messages (events) and not to replicate functions. If you find yourself creating a "return" message (event) you might be using the wrong tool. 

That said, I'm OK with look into a message bus for the Java-only code. Use moderation. If we see messages (events) being used willy-nilly, we should clamp down. Don't throw away actual valid uses for OO encapsulation, there are so few of them to begin with. 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/mobile-firefox-dev/attachments/20140506/9d81dde3/attachment.html>


More information about the mobile-firefox-dev mailing list