Skip to content

02. Application Loader

Frank Hossfeld edited this page May 1, 2018 · 13 revisions

Application Loader

Mvp4g2 provides a mechanism to execute asynchronous actions during application start. Once all asynchronous action(s) are executed, the control can be return to the MVP4G2 framework by calling finishLoadCommand.finishLoading();.

Creating a application loader

You need to create a class that implements IsApplicationLoader. This interface defines a method that you have to override:

  • load: this method will be called during application start and before the @Start-event is fired. When you're done executing your actions, you have to call finishLoadCommand.finishLoading(); to return the control to MVP4G2 and continue the application start process.

Here is an example of an application loader:

public class MyApplicationLoader
  implements IsApplicationLoader {

  @Override
  public void load(FinishLoadCommand finishLoadCommand) {
    // do the application loading
    finishLoadCommand.finishLoading();
  }
}

If you have to do more than one server call inside the loader, you should take a look at sema4g.

Setting a loader

To set a loader for an application, you need to add your loader to the @Application annotation and set the value of the loader attribute to your loader class.

@Application(eventBus = MyEventBus.class,
             loader = MyApplicationLoader.class)
interface MyApplication
  extends IsApplication {
}

Handling application loader failure

In case a loading error occured that prevents the application from starting, it is a good practice to inform the user about the error using a popup (or something else) and route the application to a technical error page.