Loading and unloading modules

classic Classic list List threaded Threaded
2 messages Options
Darius Jazayeri-2 Darius Jazayeri-2
Reply | Threaded
Open this post in threaded view
|

Loading and unloading modules

Hey Ben,

I did what may have been an incorrect initial attempt at the distro/ozip approach, by just having a controller delete file from and copy them into the modules folder. I imagine that would work, but I'd have to ask the user to restart OpenMRS themself, which is non-ideal.

So I'm going to try to rewrite my code to start and stop the relevant modules from the zip file in-place. Do you know where exactly the spring application context is restarted though? Does that happen each time I do a ModuleFactory.startModule, or a WebModuleUtil.startModule? Or is it something I have to manually make happen?

-Darius

[hidden email] from OpenMRS Developers' mailing list
Ben Wolfe (openmrs) Ben Wolfe (openmrs)
Reply | Threaded
Open this post in threaded view
|

Re: Loading and unloading modules

You will need to do it manually so that the spring restart happens once per batch instead of once per module.

I don't like how the module system has to start up, but its worked for the last 5 years and I've never had a chance to refactor it.  You must first start the module in the api layer, then start it in the web layer.  The latter is where spring is restarted for you (unless you ask it to delay the spring restart).  Spring doesn't need to be restarted for all modules, only 90% of them. Your choice of whether you want to support that or not.

1) Load each module.  See ModuleFactory.loadModules(modulesToLoad)
2) Then start all loaded modules in the api layer. ModuleFactory.startModules();
3) Then loop over each started module and "start" it in the web layer:

(see org.openmrs.web.Listener.performWebStartOfModules)
for Module mod in ModFactory.getStartedModules():
  WebModuleUtil.startModule(mod, servletContext, /* delayContextRefresh */ true)

// do this only once after all modules have been started
WebModuleUtil.refreshWAC(ServletContext, false, null)

4) ???
5) Profit!

(sorry, couldn't help but throw that meme in there)

Ben

On Thu, May 10, 2012 at 3:36 AM, Darius Jazayeri <[hidden email]> wrote:
Hey Ben,

I did what may have been an incorrect initial attempt at the distro/ozip approach, by just having a controller delete file from and copy them into the modules folder. I imagine that would work, but I'd have to ask the user to restart OpenMRS themself, which is non-ideal.

So I'm going to try to rewrite my code to start and stop the relevant modules from the zip file in-place. Do you know where exactly the spring application context is restarted though? Does that happen each time I do a ModuleFactory.startModule, or a WebModuleUtil.startModule? Or is it something I have to manually make happen?

-Darius

[hidden email] from OpenMRS Developers' mailing list


[hidden email] from OpenMRS Developers' mailing list