Version 4.10.0

hirondelle.web4j
Interface StartupTasks


public interface StartupTasks

Perform startup tasks.

See BuildImpl for important information on how this item is configured. BuildImpl.forStartupTasks() returns the configured implementation of this interface.

Allows the application programmer to perform any needed initialization tasks.

These tasks are performed only once, upon startup (caveat below). For example, the application may need to place items into application scope. Here's an example implementation taken from an example application.

See ConnectionSource.init(java.util.Map), for startup tasks related to database connections.

Startup tasks often depend on a database. If all of your databases are running when your app starts up, then all startup tasks will be completed during start-up.

However, sometimes a database may be down when your application starts up. In that case, web4j will keep track of which databases are down. Later, when a request comes into its Controller, it will re-test each offending database, to see if it's now running; when the database is seen to be running, then web4j will then pass the name of the database to startApplication(ServletConfig, String). (This processing takes place after startup, and thus, in a multi-threaded environment. The framework performs the necessary external synchronization of this class.)


Method Summary
 void startApplication(ServletConfig aConfig, String aDatabaseName)
          Perform any startup tasks needed by the application.
 

Method Detail

startApplication

void startApplication(ServletConfig aConfig,
                      String aDatabaseName)
                      throws AppException
Perform any startup tasks needed by the application.

Possible tasks include:

This method is called by WEB4J near the end of startup processing. It's first called with an empty String for the database name; this is intended for any tasks that may be unrelated to any database at all. It's then called again, once for each database defined by ConnectionSource.getDatabaseNames() (in the iteration order of the Set returned by that method).

Example of a typical implementation:

public void startApplication(ServletConfig aConfig, String aDbName) throws DAOException {
  if (!Util.textHasContent(aDbName)){
    //tasks not related to any db
  }
  else if (ConnectionSrc.DEFAULT.equals(aDbName)){
    //tasks related to this db
  }
  else if (ConnectionSrc.TRANSLATION.equals(aDbName)){
    //tasks related to this db
  }
}

This method is called N+1 times by the framework, where N is the number of databases. The framework has confirmed that the database is running before it calls this method.

Parameters:
aConfig - is not a Map, as in other interfaces, since startup tasks often need more than just settings in web.xml - for example, placing code tables in app scope will need access to the ServletContext.
aDatabaseName - refers to one of the names defined by ConnectionSource.getDatabaseNames(), or an empty string. Implementations of this method should reference those names directly, instead of hard-coding strings.
Throws:
AppException

Version 4.10.0

Copyright Hirondelle Systems. Published October 19, 2013 - User Guide - All Docs.