Downloads Documentation Community Contribute Demo






Show Sidebar
Login | Register
Show
Ignore:
Timestamp:
08/06/08 17:17:55 (5 months ago)
Author:
mseaton
Message:

synchronization_bidirectional_branch: merge from [4734] to [5181].

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • openmrs/branches/data_synchronization_bidirectional/src/api/org/openmrs/module/ModuleFactory.java

    r4969 r5183  
    168168                // loop over and try starting each of the loaded modules 
    169169                if (getLoadedModules().size() > 0) { 
    170                         Context.addProxyPrivilege(""); 
    171                         AdministrationService as = Context.getAdministrationService(); 
    172                         // try and start the modules that should be started 
    173170                        List<Module> leftoverModules = new Vector<Module>(); 
    174                         for (Module mod : getLoadedModules()) { 
    175                                 String key = mod.getModuleId() + ".started"; 
    176                                 String prop = as.getGlobalProperty(key, null); 
    177                                  
    178                                 // if a 'moduleid.started' property doesn't exist, start the module anyway 
    179                                 // as this is probably the first time they are loading it 
    180                                 if (prop == null || prop.equals("true")) { 
    181                                         if (requiredModulesStarted(mod)) 
    182                                                 try { 
     171                         
     172                        try { 
     173                                Context.addProxyPrivilege(""); 
     174                                AdministrationService as = Context.getAdministrationService(); 
     175                                // try and start the modules that should be started 
     176                                for (Module mod : getLoadedModules()) { 
     177                                        String key = mod.getModuleId() + ".started"; 
     178                                        String prop = as.getGlobalProperty(key, null); 
     179                                         
     180                                        // if a 'moduleid.started' property doesn't exist, start the module anyway 
     181                                        // as this is probably the first time they are loading it 
     182                                        if (prop == null || prop.equals("true")) { 
     183                                                if (requiredModulesStarted(mod)) 
     184                                                        try { 
     185                                                                if (log.isDebugEnabled()) 
     186                                                                        log.debug("starting module: " + mod.getModuleId()); 
     187                                                                 
     188                                                                startModule(mod); 
     189                                                        } catch (Exception e) { 
     190                                                                log.error("Error while starting module: " 
     191                                                                        + mod.getName(), e); 
     192                                                                mod.setStartupErrorMessage("Error while starting module: " + e.getMessage()); 
     193                                                        } 
     194                                                else { 
     195                                                        // if not all the modules required by this mod are loaded, save it for later 
     196                                                        leftoverModules.add(mod); 
    183197                                                        if (log.isDebugEnabled()) 
    184                                                                 log.debug("starting module: " + mod.getModuleId()); 
    185                                                          
    186                                                         startModule(mod); 
    187                                                 } catch (Exception e) { 
    188                                                         log.error("Error while starting module: " 
    189                                                                 + mod.getName(), e); 
    190                                                         mod.setStartupErrorMessage("Error while starting module: " + e.getMessage()); 
     198                                                                log.debug("cannot start because required modules are not started: " + mod.getModuleId()); 
    191199                                                } 
    192                                         else { 
    193                                                 // if not all the modules required by this mod are loaded, save it for later 
    194                                                 leftoverModules.add(mod); 
    195                                                 if (log.isDebugEnabled()) 
    196                                                         log.debug("cannot start because required modules are not started: " + mod.getModuleId()); 
    197200                                        } 
    198201                                } 
    199202                        } 
    200                         Context.removeProxyPrivilege(""); 
     203                        finally { 
     204                                Context.removeProxyPrivilege(""); 
     205                        } 
    201206 
    202207                        // loop over the leftover modules until we can't load 
     
    436441                                        .getSqlDiffs(module); 
    437442                                 
    438                                 // this method must check and run queries against the database. 
    439                                 // to do this, it must be "authenticated".  Give the current  
    440                                 // "user" the proxy privilege so this can be done. ("user" might 
    441                                 // be nobody because this is being run at startup) 
    442                                 Context.addProxyPrivilege(""); 
     443                                try { 
     444                                        // this method must check and run queries against the database. 
     445                                        // to do this, it must be "authenticated".  Give the current  
     446                                        // "user" the proxy privilege so this can be done. ("user" might 
     447                                        // be nobody because this is being run at startup) 
     448                                        Context.addProxyPrivilege(""); 
    443449                                 
    444                                 try { 
    445450                                        for (String version : diffs.keySet()) { 
    446451                                                String sql = diffs.get(version); 
     
    457462                                getStartedModulesMap().put(module.getModuleId(), module); 
    458463 
    459                                 // save the state of this module for future restarts 
    460                                 Context.addProxyPrivilege(""); 
    461                                 AdministrationService as = Context.getAdministrationService(); 
    462                                 GlobalProperty gp = new GlobalProperty(module.getModuleId() 
    463                                         + ".started", "true", 
    464                                         getGlobalPropertyStartedDescription(module 
    465                                                 .getModuleId())); 
    466                                 as.setGlobalProperty(gp); 
    467                                 Context.removeProxyPrivilege(""); 
     464                                try { 
     465                                        // save the state of this module for future restarts 
     466                                        Context.addProxyPrivilege(""); 
     467                                        AdministrationService as = Context.getAdministrationService(); 
     468                                        GlobalProperty gp = new GlobalProperty(module.getModuleId() 
     469                                                + ".started", "true", 
     470                                                getGlobalPropertyStartedDescription(module 
     471                                                        .getModuleId())); 
     472                                        as.setGlobalProperty(gp); 
     473                                } 
     474                                finally { 
     475                                        Context.removeProxyPrivilege(""); 
     476                                } 
    468477 
    469478                                // (this must be done after putting the module in the started 
     
    650659 
    651660                        if (isShuttingDown == false && !Context.isRefreshingContext()) { 
    652                                 Context.addProxyPrivilege(""); 
    653                                 AdministrationService as = Context.getAdministrationService(); 
    654                                 GlobalProperty gp = new GlobalProperty(moduleId + ".started", 
    655                                         "false", getGlobalPropertyStartedDescription(moduleId)); 
    656                                 as.saveGlobalProperty(gp); 
    657                                 Context.removeProxyPrivilege(""); 
     661                                try { 
     662                                        Context.addProxyPrivilege(""); 
     663                                        AdministrationService as = Context.getAdministrationService(); 
     664                                        GlobalProperty gp = new GlobalProperty(moduleId + ".started", 
     665                                                "false", getGlobalPropertyStartedDescription(moduleId)); 
     666                                        as.saveGlobalProperty(gp); 
     667                                } 
     668                                finally { 
     669                                        Context.removeProxyPrivilege(""); 
     670                                } 
    658671                        } 
    659672