google-code-export / mvp4g

Automatically exported from code.google.com/p/mvp4g
1 stars 0 forks source link

An infinite loop when processing broadcast events. #111

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I have the following a hierarchical structure of modules:
MainModule(ChildModules:Module2)
MainModuleEventBus{
  @Event(broadcastTo = ILogoutHandler.class, passive = true)
  public void logout();
}
Module2(ChildModules:Module3) extends ILogoutHandler
Module2EventBus{
  @Event(broadcastTo = ILogoutHandler.class, passive = true)
  public void logout();
} 
Module3 extends ILogoutHandler
Module3EventBus{
  @Event(broadcastTo = ILogoutHandler.class, passive = true)
  public void logout();
} 

Module2 and Module3 have several handlers of logout event. But in generated 
Module2Impl
public void logout(){
 ..
 Module3.logout();
 ..
 // handles.logout();
}
and in Module3Impl
public void logout(){
 ..
 parentEventBus.logout()//Module2.logout();
 ..
 // handles.logout();
}
And when you call MainModuleEventBus.logout () is an infinite loop. 
forwardToParent = false doesn't help

Original issue reported on code.google.com by Evgeny.M...@gmail.com on 21 Mar 2012 at 9:16

GoogleCodeExporter commented 9 years ago
Mvp4g doesn't prevent event loop.

The best workaround is to have 2 events, one that goes from parent to children 
and another one that parent will broadcast to children (the parent must not 
extends the broadcast interface).

For example, you can have:

@Events(forwardToParent = true)
void logoutAsked();

@Events(broadcastTo = ILogoutHandler.class)
void logout();

Only the root module will handle the logoutAsked event by sending the logout 
event.

//One presenter of root module
void onLogoutAsked() {
   eventBus.logout();
}

Original comment by plcoir...@gmail.com on 22 Mar 2012 at 12:45