Ejemplo n.º 1
0
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 ());
}
Ejemplo n.º 2
0
int
ImR_Activator_i::init_with_orb (CORBA::ORB_ptr orb, const Activator_Options& opts)
{
  ACE_ASSERT(! CORBA::is_nil (orb));
  orb_ = CORBA::ORB::_duplicate (orb);
  debug_ = opts.debug ();
  notify_imr_ = opts.notify_imr ();
  induce_delay_ = opts.induce_delay ();
  env_buf_len_ = opts.env_buf_len ();
  max_env_vars_ = opts.max_env_vars ();
  if (opts.name ().length () > 0)
    {
      name_ = opts.name();
    }

  try
    {
      CORBA::Object_var obj = orb->resolve_initial_references ("RootPOA");
      ACE_ASSERT (! CORBA::is_nil (obj.in ()));
      this->root_poa_ = PortableServer::POA::_narrow (obj.in ());
      ACE_ASSERT (! CORBA::is_nil(this->root_poa_.in ()));

      // The activator must use a persistent POA so that it can be started before the
      // locator in some scenarios, such as when the locator persists its database, and
      // wants to reconnect to running activators to auto_start some servers.
      this->imr_poa_ = createPersistentPOA (this->root_poa_.in (),
        "ImR_Activator");
      ACE_ASSERT (! CORBA::is_nil(this->imr_poa_.in ()));

      // Activate ourself
      PortableServer::ObjectId_var id = PortableServer::string_to_ObjectId ("ImR_Activator");
      this->imr_poa_->activate_object_with_id (id.in (), this);
      obj = this->imr_poa_->id_to_reference (id.in ());
      ImplementationRepository::ActivatorExt_var activator =
        ImplementationRepository::ActivatorExt::_narrow (obj.in ());
      ACE_ASSERT(! CORBA::is_nil (activator.in ()));

      CORBA::String_var ior = this->orb_->object_to_string (activator.in ());

      if (this->debug_ > 0)
        ORBSVCS_DEBUG((LM_DEBUG, "ImR Activator: Starting %s\n", name_.c_str ()));

      // initialize our process manager.
      // This requires a reactor that has signal handling.
      ACE_Reactor *reactor = ACE_Reactor::instance ();
      if (reactor != 0)
        {
          if (this->process_mgr_.open (ACE_Process_Manager::DEFAULT_SIZE, reactor) == -1)
            {
              ORBSVCS_ERROR_RETURN ((LM_ERROR,
                "The ACE_Process_Manager didnt get initialized\n"), -1);
            }
        }

      this->register_with_imr (activator.in ()); // no throw

      PortableServer::POAManager_var poaman =
        this->root_poa_->the_POAManager ();
      poaman->activate ();

      if (this->debug_ > 1)
        {
          ORBSVCS_DEBUG ((LM_DEBUG,
            "ImR Activator: The Activator IOR is: <%s>\n", ior.in ()));
        }

      // The last thing we do is write out the ior so that a test program can assume
      // that the activator is ready to go as soon as the ior is written.
      if (opts.ior_filename ().length () > 0)
        {
          FILE* fp = ACE_OS::fopen (opts.ior_filename ().c_str (), "w");
          if (fp == 0)
            {
              ORBSVCS_ERROR_RETURN ((LM_ERROR,
                "ImR Activator: Could not open file: %s\n", opts.ior_filename ().c_str ()), -1);
            }
          ACE_OS::fprintf (fp, "%s", ior.in ());
          ACE_OS::fclose (fp);
        }
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception (
        "ImR_Activator_i::init_with_orb");
      throw;
    }
  return 0;
}
Ejemplo n.º 3
0
void
ImR_Locator_i::kill_server
(ImplementationRepository::AMH_AdministrationExtResponseHandler_ptr _tao_rh,
 const char * name,
 CORBA::Short signum)
{
  Server_Info_Ptr si;
  if (!this->get_info_for_name (name, si))
    {
      CORBA::Exception *ex =
        new ImplementationRepository::NotFound;
      ImplementationRepository::AMH_AdministrationExtExceptionHolder h (ex);
      _tao_rh->kill_server_excep (&h);
      return;
    }

  if (!si->alt_info_.null ())
    {
      si = si->alt_info_;
    }

  UpdateableServerInfo info (this->repository_, si, true);
  if (info->is_mode(ImplementationRepository::PER_CLIENT))
    {
      CORBA::Exception *ex =
        new ImplementationRepository::CannotComplete ("per-client server");
      ImplementationRepository::AMH_AdministrationExtExceptionHolder h (ex);
      _tao_rh->kill_server_excep (&h);
      return;
    }

  Activator_Info_Ptr ainfo = this->get_activator (si->activator);
  if (ainfo.null ())
    {
       CORBA::Exception *ex =
        new ImplementationRepository::CannotComplete ("no activator");
      ImplementationRepository::AMH_AdministrationExtExceptionHolder h (ex);
      _tao_rh->kill_server_excep (&h);
      return;
   }
  ImplementationRepository::ActivatorExt_var actext =
    ImplementationRepository::ActivatorExt::_narrow (ainfo->activator.in());
  if (CORBA::is_nil (actext.in()))
    {
      CORBA::Exception *ex =
        new ImplementationRepository::CannotComplete ("activator incompatible");
      ImplementationRepository::AMH_AdministrationExtExceptionHolder h (ex);
      _tao_rh->kill_server_excep (&h);
      return;
    }
  if (!actext->kill_server (si->key_name_.c_str(), si->pid, signum))
    {
      CORBA::Exception *ex =
        new ImplementationRepository::CannotComplete ("server not running");
      ImplementationRepository::AMH_AdministrationExtExceptionHolder h (ex);
      _tao_rh->kill_server_excep (&h);
    }
  else
    {
      _tao_rh->kill_server ();
      AsyncAccessManager_ptr aam = this->find_aam (si->key_name_.c_str ());
      if (!aam.is_nil ())
        {
          aam->shutdown_initiated ();
        }
    }
}