int
ImR_Locator_i::init_with_orb (CORBA::ORB_ptr orb)
{
  this->orb_ = CORBA::ORB::_duplicate (orb);
  ImR_Locator_i::debug_ = this->opts_->debug ();
  CORBA::Object_var obj =
    this->orb_->resolve_initial_references ("RootPOA");
  this->root_poa_ = PortableServer::POA::_narrow (obj.in ());
  ACE_ASSERT (! CORBA::is_nil (this->root_poa_.in ()));

  this->dsi_forwarder_.init (orb);
  this->adapter_.init (& this->dsi_forwarder_);
  this->pinger_.init (orb, this->opts_->ping_interval ());

  this->opts_->pinger (&this->pinger_);

  // Register the Adapter_Activator reference to be the RootPOA's
  // Adapter Activator.
  root_poa_->the_activator (&this->adapter_);

  // Use a persistent POA so that any IOR
  this->imr_poa_ = createPersistentPOA (this->root_poa_.in (),
                                        "ImplRepo_Service");
  ACE_ASSERT (! CORBA::is_nil (this->imr_poa_.in ()));

  PortableServer::ObjectId_var id =
    PortableServer::string_to_ObjectId ("ImplRepo_Service");
  this->imr_poa_->activate_object_with_id (id.in (), this);

  obj = this->imr_poa_->id_to_reference (id.in ());
  ImplementationRepository::Locator_var locator =
    ImplementationRepository::Locator::_narrow (obj.in ());
  ACE_ASSERT(! CORBA::is_nil (locator.in ()));
  const CORBA::String_var ior = this->orb_->object_to_string (obj.in ());

  // create the selected Locator_Repository with backing store
  switch (this->opts_->repository_mode ())
    {
    case Options::REPO_REGISTRY:
      {
        repository_.reset(new Registry_Backing_Store(*this->opts_, orb));
        break;
      }
    case Options::REPO_HEAP_FILE:
      {
        repository_.reset(new Heap_Backing_Store(*this->opts_, orb));
        break;
      }
    case Options::REPO_XML_FILE:
      {
        repository_.reset(new XML_Backing_Store(*this->opts_, orb));
        break;
      }
    case Options::REPO_SHARED_FILES:
      {
        repository_.reset(new Shared_Backing_Store(*this->opts_, orb, this));
        break;
      }
    case Options::REPO_NONE:
      {
        repository_.reset(new No_Backing_Store(*this->opts_, orb));
        break;
      }
    default:
      {
        bool invalid_rmode_specified = false;
        ACE_ASSERT (invalid_rmode_specified);
        ACE_UNUSED_ARG (invalid_rmode_specified);
        ORBSVCS_ERROR_RETURN ((
          LM_ERROR, ACE_TEXT ("Repository failed to initialize\n")), -1);
      }
    }

  // Register the ImR for use with INS
  obj = orb->resolve_initial_references ("AsyncIORTable");
  IORTable::Table_var ior_table = IORTable::Table::_narrow (obj.in ());
  ACE_ASSERT (! CORBA::is_nil (ior_table.in ()));
  ior_table->set_locator (this->ins_locator_.in ());

  // initialize the repository. This will load any values that
  // may have been persisted before.
  int result = this->repository_->init(this->root_poa_.in (),
                                       this->imr_poa_.in (),
                                       ior);
  if (result != 0)
    {
      return result;
    }

  Locator_Repository::SIMap::ENTRY* entry = 0;
  Locator_Repository::SIMap::ITERATOR it (this->repository_->servers ());

  for (;it.next (entry) != 0; it.advance ())
    {
      UpdateableServerInfo info (this->repository_, entry->int_id_);
      bool is_alive = this->server_is_alive (info);
      Server_Info *active = info.edit()->active_info ();
      if (this->debug_ > 0)
        {
          ORBSVCS_DEBUG ((LM_DEBUG,
                          ACE_TEXT ("server %C is_alive = %d\n"),
                          active->ping_id(), is_alive));
        }

      if (!is_alive)
        {
          info.edit()->reset_runtime ();
          active->reset_runtime ();
          continue;
        }

      active->death_notify = false;
      if (active->pid > 0)
        {
          Activator_Info_Ptr ainfo =
            this->get_activator (active->activator);

          if (!(ainfo.null () || CORBA::is_nil (ainfo->activator.in ())))
            {
              ImplementationRepository::ActivatorExt_var actx =
                ImplementationRepository::ActivatorExt::_narrow (ainfo->activator.in ());
              try
                {
                  active->death_notify =
                    !CORBA::is_nil (actx.in ()) && actx->still_alive (active->pid);
                }
              catch (const CORBA::Exception &)
                {
                }
              if (this->debug_ > 0)
                {
                  ORBSVCS_DEBUG ((LM_DEBUG,
                                  ACE_TEXT ("activator says death_notify = %d\n"),
                                  active->death_notify));
                }
            }
        }
    }

  //only after verifying do we report the IOR and become open for business
  return this->repository_->report_ior(this->imr_poa_.in ());
}