From d42dc9b505577bb6de5635a5fc48ef2387af146e Mon Sep 17 00:00:00 2001 From: caremoli Date: Mon, 22 Mar 2010 09:23:39 +0000 Subject: [PATCH] CCAR: improve the shutdown process 1- use salome_kernel.py module instead of salome.py in shutdownSalome.py to avoid calling Study 2- disconnect all connections in the connection manager 3- change the order of servers shutdown : - connection manager - study - module catalog - registry - launcher - logger and add some waiting time between each shutdown because it is asynchronous. --- bin/shutdownSalome.py | 10 +- src/DSC/DSC_Basic/ConnectionManager_i.cxx | 14 ++- src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx | 118 ++++++++++++++----- src/SALOMEDS/SALOMEDS_Server.cxx | 1 + 4 files changed, 104 insertions(+), 39 deletions(-) diff --git a/bin/shutdownSalome.py b/bin/shutdownSalome.py index a7826c464..775b8f04e 100755 --- a/bin/shutdownSalome.py +++ b/bin/shutdownSalome.py @@ -24,12 +24,12 @@ ## \file shutdownSalome.py # shutdown all %SALOME servers and naming service # -# +# import time -import salome -salome.salome_init() -salome.lcc.shutdownServers() +import salome_kernel +orb, lcc, naming_service, cm = salome_kernel.salome_kernel_init() +lcc.shutdownServers() #give some time to shutdown to complete time.sleep(1) -salome.LifeCycleCORBA.killOmniNames() +salome_kernel.LifeCycleCORBA.killOmniNames() diff --git a/src/DSC/DSC_Basic/ConnectionManager_i.cxx b/src/DSC/DSC_Basic/ConnectionManager_i.cxx index 04a2706c3..6aa0e3450 100644 --- a/src/DSC/DSC_Basic/ConnectionManager_i.cxx +++ b/src/DSC/DSC_Basic/ConnectionManager_i.cxx @@ -92,8 +92,7 @@ ConnectionManager_i::disconnect(Engines::ConnectionManager::connectionId id, connection_infos * infos = ids[id]; try { - infos->provides_component->disconnect_provides_port(infos->provides_port_name.c_str(), - message); + infos->provides_component->disconnect_provides_port(infos->provides_port_name.c_str(), message); } catch(CORBA::SystemException& ex) { @@ -103,8 +102,7 @@ ConnectionManager_i::disconnect(Engines::ConnectionManager::connectionId id, try { infos->uses_component->disconnect_uses_port(infos->uses_port_name.c_str(), - infos->provides_port, - message); + infos->provides_port, message); } catch(CORBA::SystemException& ex) { @@ -121,10 +119,16 @@ ConnectionManager_i::disconnect(Engines::ConnectionManager::connectionId id, void ConnectionManager_i::ShutdownWithExit() { + ids_it = ids.begin(); + while(ids_it != ids.end()) + { + disconnect(ids_it->first, Engines::DSC::RemovingConnection); + ids_it = ids.begin(); + } + if(!CORBA::is_nil(_orb)) _orb->shutdown(0); - //exit( EXIT_SUCCESS ); } CORBA::Long diff --git a/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx b/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx index c1c8b1a57..a9612b4b5 100644 --- a/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx +++ b/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx @@ -33,6 +33,7 @@ #include #ifndef WIN32 #include + #include #endif #include "Basics_Utils.hxx" @@ -530,36 +531,95 @@ void SALOME_LifeCycleCORBA::shutdownServers() string hostname = Kernel_Utils::GetHostname(); - // 1) SalomeLauncher - CORBA::Object_var objSL = _NS->Resolve("/SalomeLauncher"); - Engines::SalomeLauncher_var launcher = Engines::SalomeLauncher::_narrow(objSL); - if (!CORBA::is_nil(launcher) && (pid != launcher->getPID())) - launcher->Shutdown(); - - // 2) ConnectionManager - CORBA::Object_var objCnM=_NS->Resolve("/ConnectionManager"); - Engines::ConnectionManager_var connMan=Engines::ConnectionManager::_narrow(objCnM); - if ( !CORBA::is_nil(connMan) && ( pid != connMan->getPID() ) ) - connMan->ShutdownWithExit(); - - // 3) SALOMEDS - CORBA::Object_var objSDS = _NS->Resolve("/myStudyManager"); - SALOMEDS::StudyManager_var studyManager = SALOMEDS::StudyManager::_narrow(objSDS) ; - if ( !CORBA::is_nil(studyManager) && ( pid != studyManager->getPID() ) ) - studyManager->Shutdown(); - - // 4) ModuleCatalog - CORBA::Object_var objMC=_NS->Resolve("/Kernel/ModulCatalog"); - SALOME_ModuleCatalog::ModuleCatalog_var catalog = SALOME_ModuleCatalog::ModuleCatalog::_narrow(objMC); - if ( !CORBA::is_nil(catalog) && ( pid != catalog->getPID() ) ) - catalog->shutdown(); - - // 5) Registry - CORBA::Object_var objR = _NS->Resolve("/Registry"); - Registry::Components_var registry = Registry::Components::_narrow(objR); - if ( !CORBA::is_nil(registry) && ( pid != registry->getPID() ) ) - registry->Shutdown(); + // 1) ConnectionManager + try + { + CORBA::Object_var objCnM=_NS->Resolve("/ConnectionManager"); + Engines::ConnectionManager_var connMan=Engines::ConnectionManager::_narrow(objCnM); + if ( !CORBA::is_nil(connMan) && ( pid != connMan->getPID() ) ) + connMan->ShutdownWithExit(); + } + catch(const CORBA::Exception& e) + { + // ignore and continue + } + + timespec ts_req; + ts_req.tv_nsec=100000000; + ts_req.tv_sec=0; + +//Wait some time so that ConnectionManager be completely shutdown +#ifndef WIN32 + nanosleep(&ts_req,0); +#endif + + // 2) SALOMEDS + try + { + CORBA::Object_var objSDS = _NS->Resolve("/myStudyManager"); + SALOMEDS::StudyManager_var studyManager = SALOMEDS::StudyManager::_narrow(objSDS) ; + if ( !CORBA::is_nil(studyManager) && ( pid != studyManager->getPID() ) ) + studyManager->Shutdown(); + } + catch(const CORBA::Exception& e) + { + // ignore and continue + } + +//Wait some time so that study be completely shutdown +#ifndef WIN32 + nanosleep(&ts_req,0); +#endif + + // 3) ModuleCatalog + try + { + CORBA::Object_var objMC=_NS->Resolve("/Kernel/ModulCatalog"); + SALOME_ModuleCatalog::ModuleCatalog_var catalog = SALOME_ModuleCatalog::ModuleCatalog::_narrow(objMC); + if ( !CORBA::is_nil(catalog) && ( pid != catalog->getPID() ) ) + catalog->shutdown(); + } + catch(const CORBA::Exception& e) + { + // ignore and continue + } + +//Wait some time so that ModulCatalog be completely shutdown +#ifndef WIN32 + nanosleep(&ts_req,0); +#endif + // 4) Registry + try + { + CORBA::Object_var objR = _NS->Resolve("/Registry"); + Registry::Components_var registry = Registry::Components::_narrow(objR); + if ( !CORBA::is_nil(registry) && ( pid != registry->getPID() ) ) + registry->Shutdown(); + } + catch(const CORBA::Exception& e) + { + // ignore and continue + } + +//Wait some time so that registry be completely shutdown +#ifndef WIN32 + nanosleep(&ts_req,0); +#endif + + // 5) SalomeLauncher + try + { + CORBA::Object_var objSL = _NS->Resolve("/SalomeLauncher"); + Engines::SalomeLauncher_var launcher = Engines::SalomeLauncher::_narrow(objSL); + if (!CORBA::is_nil(launcher) && (pid != launcher->getPID())) + launcher->Shutdown(); + } + catch(const CORBA::Exception& e) + { + // ignore and continue + } + // 6) Logger int argc = 0; char *xargv = (char*)""; diff --git a/src/SALOMEDS/SALOMEDS_Server.cxx b/src/SALOMEDS/SALOMEDS_Server.cxx index 26e9474e7..e27fd0d14 100644 --- a/src/SALOMEDS/SALOMEDS_Server.cxx +++ b/src/SALOMEDS/SALOMEDS_Server.cxx @@ -175,6 +175,7 @@ int main(int argc, char** argv) timer.ShowAbsolute(); #endif orb->run(); + MESSAGE( "end of SALOME_DS server" ); orb->destroy(); } catch(CORBA::SystemException&) -- 2.39.2