Module Loading and Execution

About Modules

Modules are objects that execute business/presentation logic.

In Turbine, you have 5 types of modules :

  • Page:
  • Layout:
  • Navigation:
  • Screen: executes presentation logic
  • Action: executes business logic
Each type of module is loaded by a specific module loader and the module execution sequence is hardcoded into (the main servlet).

Guara takes a new approach. We choose to have a generic ModuleExecutor valve, which grabs module names from your request parameters and tries to execute them calling

int doPerform(RunData runData, Context context) throws Exception;

OBS: for action modules, one can define a specific method to be executed, not only doPerform()

There is no distinction on module types. All modules are loaded using the ModuleLoader component, which determines the right object to create giving a module name. and caches modules instances.

All modules instances should be thread-safe

This organization gives you the power to define abstract modules and maximize code reuse. Example: the url http://localhost/action/DoSomething can execute DoSomethingImpl which is defined at guara.xml

Module Loading Details

The ModuleExecutor is responsible for determining the name of the module that is going to be loaded, thats is why we can defined default modules for a particular request.

Other task performed by the ModuleExecutor is recursive module lookup, which walks on the package tree trying to find the module by it's class name. If no module is found, a module called Default is returned.

Here is how it works

Once the module name is determined, the ModuleExecutor calls ModuleLoader.loadModule(String name, String type) which checks it's internal cache first, if null, it searches the module tree and creates the module using it's name and type using the Factory component.

The Factory can then initialize the Module and return it to the ModuleLoader, which caches it and returns to the ModuleExecutor

TODO: add sequence diagram here

Predefined Module Executors

Guara provides two predefined Module Executors:

  • ActionExecutor: determines the action module, calling a specific method other than doPerform if it applies
  • ScreenExecutor: determines the screen module using the template name as a hint
TODO: write examples with URLs