Esempio n. 1
0
Server_Info_Ptr
Locator_Repository::get_active_server (const ACE_CString& name, int pid)
{
  sync_load ();
  ACE_CString key;
  Server_Info_Ptr si;
  if (name.length() == 0)
    {
      return si;
    }
  Server_Info::fqname_to_key (name.c_str(), key);
  servers ().find (key, si);
  if (si.null())
    {
      if (this->opts_.debug() > 5)
        {
          ORBSVCS_DEBUG ((LM_DEBUG,
                          ACE_TEXT ("(%P|%t) get_active_server could not find %C\n"),
                          name.c_str()));
        }
      si = find_by_poa (key);
      if (si.null())
        {
          if (name.find ("JACORB:") == ACE_CString::npos)
            {
              ACE_CString jo_key ("JACORB:");
              ACE_CString::size_type pos = name.find (':');
              if (pos == ACE_CString::npos)
                {
                  jo_key += name;
                }
              else
                {
                  jo_key += name.substring (0, pos);
                  jo_key += '/';
                  jo_key += name.substring (pos+1);
                }
              return this->get_active_server (jo_key, pid);
            }
          else
            {
              return si;
            }
        }
    }

  if (pid != 0 && si->pid != 0 && si->pid != pid)
    {
      if (this->opts_.debug() > 5)
        {
          ORBSVCS_DEBUG ((LM_DEBUG,
                          ACE_TEXT ("(%P|%t) get_active_server could not")
                          ACE_TEXT (" find %C, %d != %d\n"),
                          name.c_str(), pid, si->pid));
        }
      si.reset ();
    }
  return si;
}
void
ImR_Locator_i::link_servers
(ImplementationRepository::AMH_AdministrationExtResponseHandler_ptr _tao_rh,
 const char * name,
 const CORBA::StringSeq & peers)
{
  Server_Info_Ptr root_si = this->repository_->get_active_server (name);
  if (root_si.null())
    {
      CORBA::Exception *ex =
        new ImplementationRepository::NotFound;
      ImplementationRepository::AMH_AdministrationExtExceptionHolder h (ex);
      _tao_rh->link_servers_excep (&h);
      return;
    }
  else if (!root_si->alt_info_.null())
    {
      ACE_CString errstr = name;
      errstr += " is not a base POA";
      CORBA::Exception *ex =
        new ImplementationRepository::CannotComplete (errstr.c_str());
      ImplementationRepository::AMH_AdministrationExtExceptionHolder h (ex);
      _tao_rh->link_servers_excep (&h);
      return;
    }

  for (CORBA::ULong i = 0; i < peers.length(); i++)
    {
      ACE_CString peer(peers[i]);
      Server_Info_Ptr si = this->repository_->get_active_server (peer);
      if (!si.null ())
        {
          ACE_CString errstr(peers[i]);
          errstr += " is already registered";
          CORBA::Exception *ex =
            new ImplementationRepository::CannotComplete (errstr.c_str());
          ImplementationRepository::AMH_AdministrationExtExceptionHolder h (ex);
          _tao_rh->link_servers_excep (&h);
          return;
        }
    }

  this->repository_->link_peers (root_si, peers);

  _tao_rh->link_servers ();
  return;
}
void
ImR_Locator_i::find
  (ImplementationRepository::AMH_AdministrationResponseHandler_ptr _tao_rh,
   const char* id)
{
  Server_Info_Ptr si = this->repository_->get_active_server (id);
  ImplementationRepository::ServerInformation_var imr_info;
  try
    {
      if (! si.null ())
        {
          imr_info = si->createImRServerInfo ();

          if (debug_ > 1)
            ORBSVCS_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) ImR: Found server %C.\n"), id));
        }
      else
        {
          ACE_NEW_THROW_EX (imr_info,
                            ImplementationRepository::ServerInformation,
                            CORBA::NO_MEMORY ());
          imr_info->startup.activation= ImplementationRepository::NORMAL;
          if (debug_ > 1)
            ORBSVCS_DEBUG ((LM_DEBUG,
                        ACE_TEXT ("(%P|%t) ImR: Cannot find server <%C>\n"),
                        id));
        }
    }
  catch (const CORBA::Exception &ex)
    {
      ImplementationRepository::AMH_AdministrationExceptionHolder h (ex._tao_duplicate());
      _tao_rh->find_excep (&h);
      return;
    }
  _tao_rh->find (imr_info.in());
}
Esempio n. 4
0
int
Locator_Repository::unregister_if_address_reused (const ACE_CString& fqname,
                                                  const char* partial_ior,
                                                  ImR_Locator_i* imr_locator)

{
  if (this->opts_.debug() > 0)
  {
    ORBSVCS_DEBUG ((LM_DEBUG,
                    ACE_TEXT ("(%P|%t)ImR: checking reuse address ")
                    ACE_TEXT ("for server \"%C\" ior \"%C\"\n"),
                    fqname.c_str(),
                    partial_ior));
  }

  ACE_CString key;
  Server_Info_Ptr si;

  Server_Info::fqname_to_key (fqname.c_str(), key);
  servers ().find (key, si);
  ACE_CString poa_name;
  ACE_CString server_id;
  if (si.null())
    {
      Server_Info::parse_id (fqname.c_str(), server_id, poa_name);
    }
  else
    {
      server_id = si->active_info ()->server_id;
      poa_name = si->active_info ()->poa_name;
    }

  Locator_Repository::SIMap::ENTRY* sientry = 0;
  Locator_Repository::SIMap::ITERATOR siit (servers ());
  for (; siit.next (sientry); siit.advance() )
  {
    Server_Info *info = sientry->int_id_->active_info ();

    if (this->opts_.debug() > 0)
    {
      ORBSVCS_DEBUG ((LM_DEBUG,
                      ACE_TEXT ("(%P|%t)ImR: iterating - registered server")
                      ACE_TEXT ("\"%C:%C\" key = <%C> ior \"%C\"\n"), info->server_id.c_str(),
                      info->poa_name.c_str (), info->key_name_.c_str(), info->partial_ior.c_str ()));
    }
    bool same_server = info->server_id == server_id;
    if (same_server && (server_id.length () == 0))
      {
        same_server = info->poa_name == poa_name;
      }
    if (info->partial_ior == partial_ior && !same_server)
      {
        if (this->opts_.debug() > 0)
          {
            ORBSVCS_DEBUG ((LM_DEBUG,
                            ACE_TEXT ("(%P|%t)ImR: reuse address %C so remove server %C \n"),
                            info->partial_ior.c_str (), info->poa_name.c_str ()));
          }
        imr_locator->pinger ().remove_server (info->key_name_.c_str());
        AsyncAccessManager_ptr aam = imr_locator->find_aam (info->key_name_.c_str ());
        if (!aam.is_nil())
          {
            aam->server_is_shutting_down ();
          }
        info->reset_runtime ();
      }
  }

  return 0;
}
void
ImR_Locator_i::remove_server
(ImplementationRepository::AMH_AdministrationResponseHandler_ptr _tao_rh,
 const char* id)
{
  if (this->opts_->readonly ())
    {
      ORBSVCS_ERROR ((LM_ERROR,
                  ACE_TEXT ("(%P|%t) ImR: Can't remove server <%C> due to locked database.\n"),
                  id));
      CORBA::Exception *ex =
        new CORBA::NO_PERMISSION (CORBA::SystemException::_tao_minor_code
                                  (TAO_IMPLREPO_MINOR_CODE, 0),
                                  CORBA::COMPLETED_NO);
      ImplementationRepository::AMH_AdministrationExceptionHolder h (ex);
      _tao_rh->remove_server_excep (&h);
      return;
    }

  Server_Info_Ptr info = this->repository_->get_active_server (id);
  if (! info.null ())
    {
      AsyncAccessManager_ptr aam(this->find_aam  (info->key_name_.c_str()));
      if (!aam.is_nil())
        {
          if (debug_ > 0)
            ORBSVCS_DEBUG ((LM_DEBUG,
                            ACE_TEXT ("(%P|%t) ImR: Can't remove active server <%C>.\n"),
                            info->key_name_.c_str()));
          CORBA::Exception *ex =
            new CORBA::NO_PERMISSION (CORBA::SystemException::_tao_minor_code
                                      (TAO_IMPLREPO_MINOR_CODE, EBUSY),
                                      CORBA::COMPLETED_NO);
          ImplementationRepository::AMH_AdministrationExceptionHolder h (ex);
          _tao_rh->remove_server_excep (&h);
          return;
        }
      if (debug_ > 1)
        ORBSVCS_DEBUG ((LM_DEBUG,
                        ACE_TEXT ("(%P|%t) ImR: Removing Server <%C>...\n"),
                        info->key_name_.c_str()));

      ACE_CString poa_name = info->poa_name;
      if (this->repository_->remove_server (info->key_name_, this) == 0)
        {
          this->destroy_poa (poa_name);
          if (debug_ > 0)
            ORBSVCS_DEBUG ((LM_DEBUG,
                        ACE_TEXT ("(%P|%t) ImR: Removed Server <%C>.\n"),
                        id));
        }
    }
  else
    {
      ORBSVCS_ERROR ((LM_ERROR,
                  ACE_TEXT ("(%P|%t) ImR: Can't remove unknown server <%C>.\n"), id));
      CORBA::Exception *ex = new ImplementationRepository::NotFound;
      ImplementationRepository::AMH_AdministrationExceptionHolder h (ex);
      _tao_rh->remove_server_excep (&h);
      return;
    }
  _tao_rh->remove_server ();
}
bool
ImR_Locator_i::get_info_for_name (const char* name, Server_Info_Ptr &si)
{
  si = this->repository_->get_active_server (name);
  return !si.null();
}
void
ImR_Locator_i::server_is_running
(ImplementationRepository::AMH_AdministrationResponseHandler_ptr _tao_rh,
 const char* id,
 const char* partial_ior,
 ImplementationRepository::ServerObject_ptr server_object)
{
  if (debug_ > 0)
    {
      ORBSVCS_DEBUG ((LM_DEBUG,
                      ACE_TEXT ("(%P|%t) ImR: Server %C is running at %C.\n"),
                      id, partial_ior));
    }
  CORBA::String_var sior = orb_->object_to_string (server_object);

  if (debug_ > 1)
    {
      ORBSVCS_DEBUG ((LM_DEBUG,
                      ACE_TEXT ("(%P|%t) ImR: Server %C callback at %C.\n"),
                      id, sior.in ()));
    }

  if (this->opts_->unregister_if_address_reused ())
    this->repository_->unregister_if_address_reused (id, partial_ior, this);

  CORBA::Object_var obj = this->set_timeout_policy (server_object, this->opts_->ping_timeout ());
  ImplementationRepository::ServerObject_var srvobj =
    ImplementationRepository::ServerObject::_narrow (obj.in());

  UpdateableServerInfo info (this->repository_, id);
  if (info.null ())
    {
      if (debug_ > 0)
        {
          ORBSVCS_DEBUG ((LM_DEBUG,
                      ACE_TEXT ("(%P|%t) ImR: Auto adding NORMAL server <%C>.\n"),
                          id));
        }

      Server_Info_Ptr si;
      if (this->repository_->add_server (id, partial_ior, sior.in (), srvobj.in ()) == 0)
        {
          si = this->repository_->get_active_server (id);
        }

      if (si.null ())
        {
          if (debug_ > 0)
            {
              ORBSVCS_DEBUG ((LM_DEBUG,
                              ACE_TEXT ("(%P|%t) ImR: Auto adding failed, giving up <%C>\n"),
                              id));
            }
          CORBA::NO_MEMORY ex;
          ImplementationRepository::AMH_AdministrationExceptionHolder h (ex._tao_duplicate());
          _tao_rh->server_is_running_excep (&h);
          return;
        }
      info.server_info (si);
      this->pinger_.add_server (si->ping_id (), this->opts_->ping_external (), srvobj.in());

      ACE_GUARD (TAO_SYNCH_MUTEX, mon, this->lock_);
      AsyncAccessManager_ptr aam (this->create_aam (info, true));
    }
  else
    {
      if (!info->is_mode(ImplementationRepository::PER_CLIENT))
        {
          info.edit ()->set_contact (partial_ior, sior.in(), srvobj.in());

          info.update_repo();
          this->pinger_.add_server (info->ping_id(), true, srvobj.in());
        }

      AsyncAccessManager_ptr aam(this->find_aam (info->ping_id ()));
      if (!aam.is_nil())
        {
          if (ImR_Locator_i::debug () > 4)
            {
              ORBSVCS_DEBUG ((LM_DEBUG,
                              ACE_TEXT ("(%P|%t) ImR_Locator_i::server_is_running aam is not nil\n")));
            }
          aam->server_is_running (partial_ior, srvobj.in());
        }
      else
        {
          if (ImR_Locator_i::debug () > 4)
            {
              ORBSVCS_DEBUG ((LM_DEBUG,
                              ACE_TEXT ("(%P|%t) ImR_Locator_i::server_is_running aam is nil\n")));
            }
          if (!info->is_mode(ImplementationRepository::PER_CLIENT))
            {
              ACE_GUARD (TAO_SYNCH_MUTEX, mon, this->lock_);
              aam = this->create_aam (info, true);
            }
        }
    }
  _tao_rh->server_is_running ();
}