I use vaadin + spring IOC + google guava eventbus. Resources recommends to use guava eventbus as singleton. But when I do that I have the following problem;
-
Let’s say I run the application on 3 different browsers at the same time, so I have 3 different instances of my application.
-
then for example when an I press a button on one browser and fire an event, I notice that my related listener method with the @subscribe annotation gets called 3 times!
Is this is a normal behaviour I would expect because I use eventbus as singleton? If not what is going on here? MainController is a spring managed bean with a a custom Vaadin Application Scope
class MainController{
public MainController() throws DAOException, Exception {
EventBusFactory.getEventBusInstance().register(this);
}
@Subscribe
public void addFacetEvent(FacetAddedEvent event) throws DAOException {
getTreeTableView().addToList(event.getData());
}
}
class EventBusFactory{
public static EventBus getEventBusInstance() {
if(eventBus==null){
eventBus=new EventBus();
}
return eventBus;
}
}
P.s I also hesitate in Vaadin should I to use guava eventbus or guava gwt event bus?
Thanks
Short answer: It’s normal and expected behaviour in this configuration (you have three Vaadin Applications and hence three
MainControllerinstances managed with singleEventBus).By custom Vaadin Application Scope did you mean scope from this Vaadin addon?
Anyway, it’s simple to reproduce your situation having prototype-scoped MainController bean and Vaadin App like this:
and
MainControllerclass:When you do the following:
you’ll get the following output:
You should now see that singleton
EventBusis managing two application-wideMainControllerbeans and each is recieving event (because it’s resolved by globalEventBus).Trying to guess what do you want to achieve, I’d say that you need create application-wide event bus bean:
About P.S.: We use standard Guava in our Vaadin project extensively, no need for GWT version.