This week's book giveaway is in the Programmer Certification forum.
We're giving away four copies of OCP Oracle Certified Professional Java SE 21 Developer Study Guide: Exam 1Z0-830 and have Jeanne Boyarsky & Scott Selikoff on-line!
See this thread for details.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Why should we use Event Bus?

 
Ranch Hand
Posts: 806
MySQL Database Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
MySQL Database Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
MySQL Database Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Wanna see my flashlight? How about this tiny ad?
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic