Salome HOME
WIP
authorAnthony Geay <anthony.geay@edf.fr>
Wed, 13 Sep 2023 12:42:24 +0000 (14:42 +0200)
committerAnthony Geay <anthony.geay@edf.fr>
Wed, 13 Sep 2023 12:42:24 +0000 (14:42 +0200)
idl/SALOME_ContainerManager.idl
src/Container/SALOME_ContainerManager.cxx
src/Container/SALOME_ContainerManager.hxx

index f4de98ae171c4f030b486dd216be495de02dd252..207b0ed9f89918808e3c3631ac7daa22ed5941ea 100644 (file)
@@ -89,6 +89,16 @@ interface ContainerManager
   //!  Shutdown all containers that have been launched by the container manager
   void ShutdownContainers();
 
+  long GetTimeOutToLaunchServerInSecond();
+
+  void SetTimeOutToLaunchServerInSecond(in long timeInSecond);
+
+  long GetDeltaTimeBetweenNSLookupAtLaunchTimeInMilliSecond();
+
+  void SetDeltaTimeBetweenNSLookupAtLaunchTimeInMilliSecond(in long timeInMS);
+
+  void MakeThisProcessAServer() raises (SALOME::SALOME_Exception);
+
   void SetOverrideEnvForContainers(in KeyValDict env);
 
   KeyValDict GetOverrideEnvForContainers();
index ee251440d2db642277412f69356fcfe9b03f62fb..23788a1fd00abd935c0ea6c4f86f7d57f781c289 100644 (file)
@@ -41,6 +41,8 @@
 #include <sstream>
 #include <string>
 #include <queue>
+#include <thread>
+#include <chrono>
 
 #include <SALOMEconfig.h>
 #include CORBA_CLIENT_HEADER(SALOME_Session)
@@ -66,8 +68,9 @@
 
 const int SALOME_ContainerManager::TIME_OUT_TO_LAUNCH_CONT=60;
 
-const char *SALOME_ContainerManager::_ContainerManagerNameInNS =
-  "/ContainerManager";
+const int SALOME_ContainerManager::DFT_DELTA_TIME_NS_LOOKUP_IN_MS=1000;
+
+const char *SALOME_ContainerManager::_ContainerManagerNameInNS = "/ContainerManager";
 
 omni_mutex SALOME_ContainerManager::_numInstanceMutex;
 
@@ -85,11 +88,12 @@ Utils_Mutex SALOME_ContainerManager::_systemMutex;
 //=============================================================================
 
 SALOME_ContainerManager::SALOME_ContainerManager(CORBA::ORB_ptr orb, PortableServer::POA_var poa, SALOME_NamingService_Abstract *ns)
-  : _nbprocUsed(1)
+  : _nbprocUsed(1),_delta_time_ns_lookup_in_ms(DFT_DELTA_TIME_NS_LOOKUP_IN_MS)
 {
   MESSAGE("constructor");
   _NS = ns;
   _resManager = new SALOME_ResourcesManager_Client(ns);
+  _time_out_in_second = GetTimeOutToLoaunchServer();
 
   PortableServer::POAManager_var pman = poa->the_POAManager();
   _orb = CORBA::ORB::_duplicate(orb) ;
@@ -203,6 +207,41 @@ void SALOME_ContainerManager::Shutdown()
   _poa->deactivate_object(oid);
 }
 
+CORBA::Long SALOME_ContainerManager::GetTimeOutToLaunchServerInSecond()
+{
+  return this->_time_out_in_second;
+}
+
+void SALOME_ContainerManager::SetTimeOutToLaunchServerInSecond(CORBA::Long timeInSecond)
+{
+  this->_time_out_in_second = timeInSecond;
+}
+
+CORBA::Long SALOME_ContainerManager::GetDeltaTimeBetweenNSLookupAtLaunchTimeInMilliSecond()
+{
+  return this->_delta_time_ns_lookup_in_ms;
+}
+
+void SALOME_ContainerManager::SetDeltaTimeBetweenNSLookupAtLaunchTimeInMilliSecond(CORBA::Long timeInMS)
+{
+  this->_delta_time_ns_lookup_in_ms = timeInMS;
+}
+
+/*!
+ * Launch a this->_orb->run() in order to respond to CORBA requests from the outside.
+ */
+void SALOME_ContainerManager::MakeThisProcessAServer()
+{
+  if(_server_thread_launched)
+  {
+    THROW_SALOME_CORBA_EXCEPTION("orb.run() thread has already been launched. You are not supposed to launch it more than once",SALOME::BAD_PARAM);
+  }
+  _server_thread_launched = true;
+  auto ORBRunLauncher = [](CORBA::ORB_var orb) { MESSAGE("[SALOME_ContainerManager::MakeThisProcessAServer] ORB is running in a thread ...."); orb->run(); };
+  std::thread t(ORBRunLauncher,this->_orb);
+  t.detach();
+}
+
 //=============================================================================
 //! Loop on all the containers listed in naming service, ask shutdown on each
 /*! CORBA Method:
@@ -670,11 +709,13 @@ SALOME_ContainerManager::LaunchContainer(const Engines::ContainerParameters& par
   else
     {
       // Step 4: Wait for the container
-      int count(GetTimeOutToLoaunchServer());
-      INFOS("[GiveContainer] waiting " << count << " second steps container " << containerNameInNS);
+      double nbTurn = ( (double)this->_time_out_in_second ) * ( 1000.0 / ( (double) this->_delta_time_ns_lookup_in_ms) );
+      int count( (int)nbTurn );
+      INFOS("[GiveContainer] # attempts : " << count << " name in NS : \"" << containerNameInNS << "\"");
+      INFOS("[GiveContainer] # attempts : Time in second before time out : " << this->_time_out_in_second << " Delta time in ms between NS lookup : " << this->_delta_time_ns_lookup_in_ms);
       while (CORBA::is_nil(ret) && count)
         {
-          SleepInSecond(1);
+          std::this_thread::sleep_for(std::chrono::milliseconds(_delta_time_ns_lookup_in_ms));
           count--;
           MESSAGE("[GiveContainer] step " << count << " Waiting for container on " << resource_selected << " with entry in NS = \"" << containerNameInNS << "\"" );
           CORBA::Object_var obj(_NS->Resolve(containerNameInNS.c_str()));
@@ -1154,6 +1195,10 @@ void SALOME_ContainerManager::MakeTheCommandToBeLaunchedASync(std::string& comma
 #endif
 }
 
+/*!
+ * Return in second the time out to give chance to server to be launched and
+ * to register into NS
+ */
 int SALOME_ContainerManager::GetTimeOutToLoaunchServer()
 {
   int count(TIME_OUT_TO_LAUNCH_CONT);
index 1e458769f2374e342bab801f2a858bd221be1b8e..5f8388e515385d106bbd0787d76a0a9b83b5a727 100644 (file)
@@ -61,6 +61,16 @@ public:
 
   void DeclareUsingSalomeSession() { _isSSL = false; }
 
+  CORBA::Long GetTimeOutToLaunchServerInSecond() override;
+
+  void SetTimeOutToLaunchServerInSecond(CORBA::Long timeInSecond) override;
+
+  CORBA::Long GetDeltaTimeBetweenNSLookupAtLaunchTimeInMilliSecond() override;
+
+  void SetDeltaTimeBetweenNSLookupAtLaunchTimeInMilliSecond(CORBA::Long timeInMS) override;
+
+  void MakeThisProcessAServer();
+
   static const char *_ContainerManagerNameInNS;
 
 protected:
@@ -197,9 +207,13 @@ public:
   static void SleepInSecond(int ellapseTimeInSecond);
  private:
   static const int TIME_OUT_TO_LAUNCH_CONT;
+  static const int DFT_DELTA_TIME_NS_LOOKUP_IN_MS;
   static Utils_Mutex _getenvMutex;
   static Utils_Mutex _systemMutex;
 private:
   std::vector< std::pair<std::string, std::string> > _override_env;
+  int _time_out_in_second;
+  int _delta_time_ns_lookup_in_ms;
+  bool _server_thread_launched = false;
 };
 #endif