Back to index

salome-kernel  6.5.0
Functions
NamingService_WaitForServerReadiness.cxx File Reference
#include "NamingService_WaitForServerReadiness.hxx"
#include "utilities.h"
#include <iostream>
#include <ctime>

Go to the source code of this file.

Functions

void NamingService_WaitForServerReadiness (SALOME_NamingService *NS, std::string serverName)
 Wait until a server is registered in naming service.

Function Documentation

void NamingService_WaitForServerReadiness ( SALOME_NamingService NS,
std::string  serverName 
)

Wait until a server is registered in naming service.

Parameters:
serverNamename of the server to find.
NSSALOME_NamingService object Wait until the given server is ready i.e. is name is found in namingService. Try 40 times, with 500 ms sleep between each try. If Logger is used for traces, it must be ready before this call, because SALOME_NamingService client uses SALOME traces. So, Logger readiness must be checked in Launch script before execution of WaitForServerReadiness.

Definition at line 47 of file NamingService_WaitForServerReadiness.cxx.

{
  long TIMESleep = 500000000; // 500 ms.
  int NumberOfTries = 40;     // total wait = 20 s.
  int found = 0;

  timespec ts_req;
  ts_req.tv_nsec=TIMESleep;
  ts_req.tv_sec=0;
  timespec ts_rem;
  ts_rem.tv_nsec=0;
  ts_rem.tv_sec=0;

  ASSERT(NS);
  for (int itry=0; itry < NumberOfTries; itry++)
    {
      try
        {
          if (serverName.length() == 0)
            {
              CORBA::String_var dummyadr = NS->getIORaddr(); // to wait for naming service
              found = 1;
              break; // naming service found
            }
          else
            {
              CORBA::Object_var obj = NS->Resolve(serverName.c_str());
              if (! CORBA::is_nil(obj))
                {
                  found =1;
                  break; // server found, no more try to do
                }
              MESSAGE("Server "<< serverName <<" not yet ready, waiting...");
#ifndef WIN32
              nanosleep(&ts_req,&ts_rem); // wait before retry
#else
              Sleep(TIMESleep/1000000);
#endif
            }
        }
      catch( ServiceUnreachable& )
        {
          MESSAGE("CORBA::COMM_FAILURE: Naming Service not yet ready, waiting...");
#ifndef WIN32
          nanosleep(&ts_req,&ts_rem); // wait before retry
#else
          Sleep(TIMESleep/1000000);
#endif
        }
    }
  if (!found)
    {
    INFOS("Server "<< serverName <<" not found, abort...");
    exit(EXIT_FAILURE);
    }
}

Here is the caller graph for this function: