File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why should we use Event Bus?

 
chaitanya karthikk
Ranch Hand
Posts: 806
Java MySQL Database Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all, I could not understand the importance of GWT event bus. I have gone through the tutorial here. The tutorial explains how to build a Contacts application. The tutorial shows how to use GWT event bus. I have downloaded the zip file available in the same page and ran the application.

Later I created another sample application and started developing it without the use of GWT event bus.

Now I am unable to understand what is the use or importance of GWT event bus. I opened the tutorial application and looked where the author is using the event bus. I could find its usage in AppController.java where he is simply switching between views using History class. I have used History to switch between views in the presenter classes. Later I looked at the tutorial and it says "The Event Bus is a mechanism for a) passing events and b) registering to be notified of some subset of these events.". I could not understand this line.

Can anyone please explain me why should we use event bus, and can anyone please give an example of its usage.

Thank you all in advance. Good day.
 
chaitanya karthikk
Ranch Hand
Posts: 806
Java MySQL Database Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now I am able to use the event bus, but still don't know why should I use and when should I use it. Can anyone please explain. It would be very useful for me.
 
Maneesh Godbole
Saloon Keeper
Posts: 10971
11
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you seen any movie, or a real wedding, where the bride tosses the bouquet? She turns her back and tosses it behind her.
Is she aiming at someone? No. Does it matter to her, who catches it? Not really. That's an event bus analogy right there for you!

Loose coupling. When you want to achieve that, go for using event bus.

 
chaitanya karthikk
Ranch Hand
Posts: 806
Java MySQL Database Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maneesh Godbole wrote:Have you seen any movie, or a real wedding, where the bride tosses the bouquet? She turns her back and tosses it behind her.
Is she aiming at someone? No. Does it matter to her, who catches it? Not really. That's an event bus analogy right there for you!

Loose coupling. When you want to achieve that, go for using event bus.

That is a typical explanation. I could not understand anything. I created 2 contact applications without using event bus and with using event bus. Later I understood that event bus can be used to pass information from one presenter to another. Suppose that I made an rpc call from Presenter1, then I have to change the view and send some information to that view. I can use eventBus.fireEvent(new Event(String dataToBePassed)) and pass the data through the constructor argument and in my AppController I can call get methods from the event and pass it to the other presenter(Presenter2) and from there to its associated view.

Is my understanding right?
 
Maneesh Godbole
Saloon Keeper
Posts: 10971
11
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's not restricted to presenters or views. It is flexible enough to to accomodate any broadcaster consumer pattern. The advantage is the broadcaster does not know nor care who would consume the event. And yes, the event can be used to encapsulate data if required.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic