Currently, I am using an EventBus/PubSub architecture/pattern with Scala (and JavaFX) to implement a simple note organizing app (sort of like an Evernote client with some added mind mapping functionality) and I have to say that I really like EventBus over the observer pattern.
Here are some EventBus libraries :
https://code.google.com/p/guava-libraries/wiki/EventBusExplained
http://eventbus.org (currently seems to be down) this is the one I am using in my implementation.
http://greenrobot.github.io/EventBus/
Here is a comparison of EventBus libraries : http://codeblock.engio.net/37/
EventBus is related to the publish-subscribe pattern.
However !
Recently, I took the Reactive course by Coursera and started to wonder whether using RXJava instead of EventBus would simplify the event handling code even more in a single threaded application ?
I would like to ask about the experiences of people who programmed using both technologies (some kind of eventbus library and some form of the reactive extensions (RX)): was it easier to tackle event handling complexity using RX than with an event bus architecture given that there was no need to use multiple threads ?
I am asking this because I have heard in the Reactive Lectures on Coursera that RX leads to much cleaner code than using the observer pattern (i.e. there is no "callback hell"), however I did not find any comparison between EventBus architecture vs RXJava. So it's clear that both EventBus and RXJava are better than the observer pattern but which is better in a single threaded applications in terms of code clarity and maintainability ?
If I understand correctly the main selling point of RXJava is that it can be used to produce responsive applications if there are blocking operations (e.g. waiting for response from a server).
But I don't care about asychronicity at all, all I care about is keeping the code clean, untangled and easy to reason about in a single threaded application.
In that case, is it still better to use RXJava than EventBus ?
I think EventBus would be a simpler and cleaner solution and I don't see any reason why I should use RXJava for a single threaded application in favour of a simple EventBus architecture.
But I might be wrong!
Please correct me if I am wrong and explain why RXJava would be better than a simple EventBus in case of a single threaded application where no blocking operations are carried out.
Observable
class (actuallyObservableValue
is closer to RX' observable). I'm currently looking into creating an adapter between the two. If this were possible, you could simply use scalafx'sbind
directive, which is nice and declarative!a.events().subscribe(b::handle)
is much more explicit thaneventBus.register(b)
somewhere andeventBus.post(evt)
somewhere else. Furthermore, the producer's API does not state what types of events it publishes to the event bus. On the other hand, if you have a component that has a method returningEventStream<E>
and another one returningEventStream<F>
, it is clear that this component produces events of typeE
and events of typeF
.