void
ImR_Locator_i::shutdown_server
(ImplementationRepository::AMH_AdministrationResponseHandler_ptr _tao_rh,
 const char* id)
{
  const CORBA::ULong TAO_MINOR_MASK = 0x00000f80;
  if (debug_ > 0)
    ORBSVCS_DEBUG ((LM_DEBUG,
                ACE_TEXT ("(%P|%t) ImR: Shutting down server <%C>.\n"),
                id));

  UpdateableServerInfo info (this->repository_, id);
  if (info.null ())
    {
      ORBSVCS_ERROR ((LM_ERROR,
                  ACE_TEXT ("(%P|%t) ImR: shutdown_server () Cannot find info for server <%C>\n"),
                  id));
      CORBA::Exception *ex = new ImplementationRepository::NotFound;
      ImplementationRepository::AMH_AdministrationExceptionHolder h (ex);
      _tao_rh->shutdown_server_excep (&h);
      return;
    }

  this->connect_server (info);

  if (CORBA::is_nil (info->active_info()->server.in ()))
    {
      ORBSVCS_ERROR ((LM_ERROR,
                  ACE_TEXT ("(%P|%t) ImR: shutdown_server () Cannot connect to server <%C>\n"),
                  id));
      CORBA::Exception *ex = new ImplementationRepository::NotFound;
      ImplementationRepository::AMH_AdministrationExceptionHolder h (ex);
      try
        {
          _tao_rh->shutdown_server_excep (&h);
        }
      catch (const CORBA::Exception &ex)
        {
          ex._tao_print_exception (ACE_TEXT ("reporting connect error\n"));
        }
      return;
    }

  try
    {
      CORBA::Object_var obj = this->set_timeout_policy (info->active_info()->server.in (),
                                                        DEFAULT_SHUTDOWN_TIMEOUT);
      ImplementationRepository::ServerObject_var server =
        ImplementationRepository::ServerObject::_unchecked_narrow (obj.in ());
      server->shutdown ();
      // reset the server info on a successful call. A failure indicates the server isn't
      // acting on the shutdown. Either it is shutting down already, or hasn't yet started,
      // in which case the shutdown will need to be reissued.
      info.edit ()->reset_runtime ();
      AsyncAccessManager_ptr aam = this->find_aam (info->ping_id ());
      if (!aam.is_nil())
        {
          aam->shutdown_initiated ();
        }
    }
  catch (const CORBA::TIMEOUT &ex)
    {
      info.edit ()->reset_runtime ();
      // Note : This is a good thing. It means we didn't waste our time waiting for
      // the server to finish shutting down.
      if (debug_ > 1)
        {
          ORBSVCS_DEBUG ((LM_DEBUG,
                      ACE_TEXT ("(%P|%t) ImR: Timeout while waiting for <%C> shutdown.\n"),
                      id));
        }
      ImplementationRepository::AMH_AdministrationExceptionHolder h (ex._tao_duplicate());
      _tao_rh->shutdown_server_excep (&h);
      return;
    }
  catch (const CORBA::COMM_FAILURE& ex)
    {
      info.edit ()->reset_runtime ();
      if (debug_ > 1)
        {
          ORBSVCS_DEBUG ((LM_DEBUG,
                      ACE_TEXT ("ImR: COMM_FAILURE while waiting for <%C> shutdown.\n"),
                      id));
        }
      if (this->opts_->throw_shutdown_exceptions ())
        {
          ImplementationRepository::AMH_AdministrationExceptionHolder h (ex._tao_duplicate());
          _tao_rh->shutdown_server_excep (&h);
          return;
        }
    }
  catch (const CORBA::TRANSIENT& ex)
    {
      CORBA::ULong minor = ex.minor () & TAO_MINOR_MASK;
      if (minor != TAO_POA_DISCARDING && minor != TAO_POA_HOLDING)
        {
          info.edit ()->reset_runtime ();
        }
      if (debug_ > 1)
        {
          ORBSVCS_DEBUG ((LM_DEBUG,
                      ACE_TEXT ("ImR: TRANSIENT while waiting for <%C> shutdown.\n"),
                      id));
        }
      if (this->opts_->throw_shutdown_exceptions ())
        {
          ImplementationRepository::AMH_AdministrationExceptionHolder h (ex._tao_duplicate());
          _tao_rh->shutdown_server_excep (&h);
          return;
        }
    }
  catch (const CORBA::Exception &ex)
    {
      if (debug_ > 1)
        {
          ORBSVCS_DEBUG ((LM_DEBUG,
            ACE_TEXT ("(%P|%t) ImR: Exception while shutting down <%C>\n"),
            id));
        }
      if (this->opts_->throw_shutdown_exceptions ())
        {
          ImplementationRepository::AMH_AdministrationExceptionHolder h (ex._tao_duplicate());
          _tao_rh->shutdown_server_excep (&h);
          return;
        }
    }

  _tao_rh->shutdown_server ();
}
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 ();
}
Exemplo n.º 3
0
    void
    ImR_Client_Adapter_Impl::imr_notify_startup (TAO_Root_POA* poa )
    {
      CORBA::Object_var imr = poa->orb_core ().implrepo_service ();

      if (CORBA::is_nil (imr.in ()))
        {
          if (TAO_debug_level > 0)
            {
              TAOLIB_ERROR ((LM_ERROR,
                          ACE_TEXT ("TAO_ImR_Client (%P|%t) - ERROR: No usable IMR initial reference ")
                          ACE_TEXT ("available but use IMR has been specified.\n")));
            }
          throw ::CORBA::TRANSIENT (
              CORBA::SystemException::_tao_minor_code (TAO_IMPLREPO_MINOR_CODE, 0),
              CORBA::COMPLETED_NO);
        }

      if (TAO_debug_level > 0)
        {
          if (TAO_debug_level > 1)
            {
              CORBA::ORB_ptr orb = poa->orb_core ().orb ();
              CORBA::String_var ior = orb->object_to_string (imr.in ());
              TAOLIB_DEBUG ((LM_DEBUG,
                            ACE_TEXT ("TAO_ImR_Client (%P|%t) - Notifying ImR of startup IMR IOR <%C>\n"),
                            ior.in ()));
            }
        }

      ImplementationRepository::Administration_var imr_locator;

      {
        // ATTENTION: Trick locking here, see class header for details
        TAO::Portable_Server::Non_Servant_Upcall non_servant_upcall (*poa);
        ACE_UNUSED_ARG (non_servant_upcall);

        imr_locator =
          ImplementationRepository::Administration::_narrow (imr.in ());
      }

      if (CORBA::is_nil (imr_locator.in ()))
        {
          if (TAO_debug_level > 0)
            {
              TAOLIB_ERROR ((LM_ERROR,
                          ACE_TEXT ("TAO_ImR_Client (%P|%t) - ERROR: Narrowed IMR initial reference ")
                          ACE_TEXT ("is nil but use IMR has been specified.\n")));
            }

          throw ::CORBA::TRANSIENT (
              CORBA::SystemException::_tao_minor_code (TAO_IMPLREPO_MINOR_CODE, 0),
              CORBA::COMPLETED_NO);
        }

      TAO_Root_POA *root_poa = poa->object_adapter ().root_poa ();
      ACE_NEW_THROW_EX (this->server_object_,
                        ServerObject_i (poa->orb_core ().orb (),
                                        root_poa),
                        CORBA::NO_MEMORY ());

      PortableServer::ServantBase_var safe_servant (this->server_object_);
      ACE_UNUSED_ARG (safe_servant);

      // Since this method is called from the POA constructor, there
      // shouldn't be any waiting required.  Therefore,
      // <wait_occurred_restart_call_ignored> can be ignored.
      bool wait_occurred_restart_call_ignored = false;

      // Activate the servant in the root poa.
      PortableServer::ObjectId_var id =
        root_poa->activate_object_i (this->server_object_,
                                     poa->server_priority (),
                                     wait_occurred_restart_call_ignored);

      CORBA::Object_var obj = root_poa->id_to_reference_i (id.in (), false);

      ImplementationRepository::ServerObject_var svr
        = ImplementationRepository::ServerObject::_narrow (obj.in ());

      if (!svr->_stubobj () || !svr->_stubobj ()->profile_in_use ())
        {
          if (TAO_debug_level > 0)
            {
              TAOLIB_ERROR ((LM_ERROR, "TAO_ImR_Client (%P|%t) - Invalid ImR ServerObject, bailing out.\n"));
            }
          return;
        }
      CORBA::ORB_var orb = root_poa->_get_orb ();
      CORBA::String_var full_ior = orb->object_to_string (obj.in ());
      TAO_Profile& profile = *(svr->_stubobj ()->profile_in_use ());
      CORBA::String_var ior = profile.to_string();
      if (TAO_debug_level > 0)
        {
          TAOLIB_DEBUG((LM_INFO,
                        "TAO_ImR_Client (%P|%t) - full_ior <%C>\nior <%C>\n",
                        full_ior.in(),
                        ior.in()));
        }
      char* const pos = find_delimiter (ior.inout (),
                                        profile.object_key_delimiter ());

      const ACE_CString partial_ior (ior.in (), (pos - ior.in ()) + 1);

      if (TAO_debug_level > 0)
      {
        CORBA::String_var poaname = poa->the_name ();
        TAOLIB_DEBUG ((LM_DEBUG,
                    ACE_TEXT ("TAO_ImR_Client (%P|%t) - Informing IMR that <%C> is running at <%C>\n"),
                    poaname.in(), partial_ior.c_str ()));
      }

      try
        {
          // ATTENTION: Trick locking here, see class header for details
          TAO::Portable_Server::Non_Servant_Upcall non_servant_upcall (*poa);
          ACE_UNUSED_ARG (non_servant_upcall);

          ACE_CString const serverId = poa->orb_core ().server_id ();
          ACE_CString name;
          if (serverId.empty ())
            {
              name = poa->name ();
            }
          else
            {
              name = serverId + ":" + poa->name ();
            }

          imr_locator->server_is_running (name.c_str (),
                                          partial_ior.c_str (),
                                          svr.in ());
        }
      catch (const ::CORBA::SystemException&)
        {
          throw;
        }
      catch (const ::CORBA::Exception&)
        {
          throw ::CORBA::TRANSIENT (
              CORBA::SystemException::_tao_minor_code (TAO_IMPLREPO_MINOR_CODE, 0),
              CORBA::COMPLETED_NO);
        }

      if (TAO_debug_level > 0)
        {
          TAOLIB_DEBUG ((LM_DEBUG,
                         ACE_TEXT ("TAO_ImR_Client (%P|%t) - Successfully notified ImR of Startup\n")));
        }
    }