This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes GWT and the fly likes Why should we use Event Bus? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Frameworks » GWT
Bookmark "Why should we use Event Bus?" Watch "Why should we use Event Bus?" New topic
Author

Why should we use Event Bus?

chaitanya karthikk
Ranch Hand

Joined: Sep 15, 2009
Posts: 800

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.


Love all, trust a few, do wrong to none.
chaitanya karthikk
Ranch Hand

Joined: Sep 15, 2009
Posts: 800

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

Joined: Jul 26, 2007
Posts: 10270
    
    8

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.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
chaitanya karthikk
Ranch Hand

Joined: Sep 15, 2009
Posts: 800

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

Joined: Jul 26, 2007
Posts: 10270
    
    8

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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Why should we use Event Bus?