Module Queue API Usage
This is a 1.9+ feature
Introduction
For some years in Openmrs Module Administration, Module actions Add, Upgrade, Start, Stop, Unload, Download from Repository and Download/Install Update was coupled with a Spring Context refresh. This one to one coupling means whenever a module action is performed, The Web Application Context is effectively restarted thus resulting in interruptions to Scheduled Tasks and Background Processes.
This had to be changed and module actions required to be decoupled from the Spring Context Refresh. Spring Context Refresh was ought to be a separate action. To enable that the Module Queue API was developed.
[edit]
Module Administration API UsageQueuing Module Add Download the module file from the module repository.Load the module file using ModuleFactory.loadModule(File moduleFile).If module load is successful Queue the module for pending start using ModuleFactory.queueAction(String moduleId, ModuleAction pendingAction). moduleId - The Id of the loaded module you want to start.pendingAction - The action for starting a module (ModuleAction.PENDING_START)
Ex:-ModuleFactory.loadModule(restModuleFile);ModuleFactory.queueAction(“restmodule”,ModuleAction.PENDING_START);
Queuing Module Upgrade Download the latest module file from module repository/Upload the latest module via fileuploadUse ModuleFactory.upgradeModule(Module newModule, String newModuleName) To do all the pre conditions for module upgrade queuing and queue the moduleupgrade. newModule - Latest version of the existing loaded module.newModuleName - File name of the latest version of the existing loaded module.
Ex:-ModuleFactory.upgradeModule(newModule, “newmodule-2.0.omod”);ModuleFactory.queueAction(“newmodule”,ModuleAction.PENDING_START);
Queuing Module Start Use ModuleFactory.queueAction(String moduleId, ModuleAction pendingAction).
moduleId - The Id of the loaded module you want to start.pendingAction - The action for starting a module (ModuleAction.PENDING_START) Ex:-ModuleFactory.queueAction(“restmodule”, ModuleAction.PENDING_START); Queuing Module Stop Use ModuleFactory.queueAction(String moduleId, ModuleAction pendingAction).
moduleId - The Id of the loaded module you want to stop.pendingAction - The action for stopping a module (ModuleAction.PENDING_STOP) Ex:-ModuleFactory.queueAction(“restmodule”, ModuleAction.PENDING_STOP); Queuing Module Unload Use ModuleFactory.queueAction(String moduleId, ModuleAction pendingAction).
moduleId - The Id of the loaded module you want to unload.pendingAction - The action for starting a module(ModuleAction.PENDING_UNLOAD)Ex:-ModuleFactory.queueAction(“restmodule”, ModuleAction.PENDING_UNLOAD);[edit]
Performing Queued Module ActionsAll modules with pending actions can be retrieved using ModuleFactory.getModulesWithPendingActions(). For each module with a pending :action the appropriate action can be performed by checking its pending action using Module.getPendingAction(). Ex:-Iterator<Module> modules = ModuleFactory.getModulesWithPendingAction();
for(Module m:modules){
switch(m.getPendingAction())
}
[edit]