Skip to content

Commit

Permalink
TRUNK-3738 Fixed stopping module
Browse files Browse the repository at this point in the history
  • Loading branch information
rkorytkowski committed Aug 20, 2013
1 parent fd7cffc commit 67c9f03
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions api/src/main/java/org/openmrs/module/ModuleUtil.java
Expand Up @@ -750,7 +750,8 @@ public static AbstractRefreshableApplicationContext refreshApplicationContext(Ab
public static AbstractRefreshableApplicationContext refreshApplicationContext(AbstractRefreshableApplicationContext ctx,
boolean isOpenmrsStartup, Module startedModule) {
//notify all started modules that we are about to refresh the context
for (Module module : ModuleFactory.getStartedModules()) {
Set<Module> startedModules = new HashSet<Module>(ModuleFactory.getStartedModules());
for (Module module : startedModules) {
try {
if (module.getModuleActivator() != null)
module.getModuleActivator().willRefreshContext();
Expand Down Expand Up @@ -791,16 +792,19 @@ public static AbstractRefreshableApplicationContext refreshApplicationContext(Ab

// reload the advice points that were lost when refreshing Spring
if (log.isDebugEnabled())
log.debug("Reloading advice for all started modules: " + ModuleFactory.getStartedModules().size());
log.debug("Reloading advice for all started modules: " + startedModules.size());

try {
//The call backs in this block may need lazy loading of objects
//which will fail because we use an OpenSessionInViewFilter whose opened session
//was closed when the application context was refreshed as above.
//So we need to open another session now. TRUNK-3739
Context.openSessionWithCurrentUser();

for (Module module : ModuleFactory.getStartedModules()) {
for (Module module : startedModules) {
if (!module.isStarted()) {
continue;
}

ModuleFactory.loadAdvice(module);
try {
ModuleFactory.passDaemonToken(module);
Expand All @@ -817,7 +821,7 @@ else if (!isOpenmrsStartup && module.equals(startedModule))
}
catch (Exception e) {
log.warn("Unable to invoke started() method on the module's activator", e);
ModuleFactory.stopModule(module);
ModuleFactory.stopModule(module, true, true);
}
}

Expand Down

0 comments on commit 67c9f03

Please sign in to comment.