Go to the documentation of this file.00001
00002
00003 #include "tao/ImR_Client/ImR_Client.h"
00004
00005 #include "tao/debug.h"
00006 #include "tao/ORB_Core.h"
00007 #include "tao/Stub.h"
00008 #include "tao/Profile.h"
00009 #include "tao/PortableServer/Root_POA.h"
00010 #include "tao/PortableServer/Non_Servant_Upcall.h"
00011 #include "tao/ImR_Client/ServerObject_i.h"
00012 #include "tao/ImR_Client/ImplRepoC.h"
00013
00014 ACE_RCSID (ImR_Client,
00015 ImR_Client,
00016 "$Id: ImR_Client.cpp 85171 2009-04-25 06:33:24Z dai_y $")
00017
00018 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00019
00020 namespace TAO
00021 {
00022 namespace ImR_Client
00023 {
00024 ImR_Client_Adapter_Impl::ImR_Client_Adapter_Impl (void)
00025 : server_object_ (0)
00026 {
00027 }
00028
00029 void
00030 ImR_Client_Adapter_Impl::imr_notify_startup (TAO_Root_POA* poa )
00031 {
00032 CORBA::Object_var imr = poa->orb_core ().implrepo_service ();
00033
00034 if (CORBA::is_nil (imr.in ()))
00035 {
00036 ACE_ERROR ((LM_ERROR,
00037 ACE_TEXT ("(%P|%t) ERROR: No usable IMR initial reference ")
00038 ACE_TEXT ("available but use IMR has been specified.\n")));
00039 throw ::CORBA::TRANSIENT (
00040 CORBA::SystemException::_tao_minor_code (TAO_IMPLREPO_MINOR_CODE, 0),
00041 CORBA::COMPLETED_NO);
00042 }
00043
00044 if (TAO_debug_level > 0)
00045 ACE_DEBUG ((LM_DEBUG, "Notifying ImR of startup\n"));
00046
00047 ImplementationRepository::Administration_var imr_locator;
00048
00049 {
00050
00051 TAO::Portable_Server::Non_Servant_Upcall non_servant_upcall (*poa);
00052 ACE_UNUSED_ARG (non_servant_upcall);
00053
00054 imr_locator =
00055 ImplementationRepository::Administration::_narrow (imr.in ());
00056 }
00057
00058 if (CORBA::is_nil(imr_locator.in ()))
00059 {
00060 ACE_ERROR ((LM_ERROR,
00061 ACE_TEXT ("(%P|%t) ERROR: Narrowed IMR initial reference ")
00062 ACE_TEXT ("is nil but use IMR has been specified.\n")));
00063
00064 throw ::CORBA::TRANSIENT (
00065 CORBA::SystemException::_tao_minor_code (TAO_IMPLREPO_MINOR_CODE, 0),
00066 CORBA::COMPLETED_NO);
00067 }
00068
00069 TAO_Root_POA *root_poa = poa->object_adapter ().root_poa ();
00070 ACE_NEW_THROW_EX (this->server_object_,
00071 ServerObject_i (poa->orb_core ().orb (),
00072 root_poa),
00073 CORBA::NO_MEMORY ());
00074
00075 PortableServer::ServantBase_var safe_servant (this->server_object_);
00076 ACE_UNUSED_ARG (safe_servant);
00077
00078
00079
00080
00081 bool wait_occurred_restart_call_ignored = false;
00082
00083
00084 PortableServer::ObjectId_var id =
00085 root_poa->activate_object_i (this->server_object_,
00086 poa->server_priority (),
00087 wait_occurred_restart_call_ignored);
00088
00089 CORBA::Object_var obj = root_poa->id_to_reference_i (id.in (), false);
00090
00091 ImplementationRepository::ServerObject_var svr
00092 = ImplementationRepository::ServerObject::_narrow (obj.in ());
00093
00094 if (!svr->_stubobj () || !svr->_stubobj ()->profile_in_use ())
00095 {
00096 ACE_ERROR ((LM_ERROR, "Invalid ImR ServerObject, bailing out.\n"));
00097 return;
00098 }
00099
00100 CORBA::String_var ior =
00101 svr->_stubobj ()->profile_in_use ()->to_string ();
00102
00103
00104
00105 const char corbaloc[] = "corbaloc:";
00106 char *pos = ACE_OS::strstr (ior.inout (), corbaloc);
00107 pos = ACE_OS::strchr (pos + sizeof (corbaloc), ':');
00108
00109 pos = ACE_OS::strchr (pos + 1,
00110 svr->_stubobj ()->profile_in_use ()->object_key_delimiter ());
00111
00112 ACE_CString partial_ior(ior.in (), (pos - ior.in()) + 1);
00113
00114 if (TAO_debug_level > 0)
00115 ACE_DEBUG ((LM_DEBUG,
00116 "Informing IMR that we are running at: %C\n",
00117 partial_ior.c_str()));
00118
00119 try
00120 {
00121
00122 TAO::Portable_Server::Non_Servant_Upcall non_servant_upcall (*poa);
00123 ACE_UNUSED_ARG (non_servant_upcall);
00124
00125 ACE_CString serverId = poa->orb_core ().server_id ();
00126 ACE_CString name;
00127 if (serverId.empty ())
00128 {
00129 name = poa->name();
00130 }
00131 else
00132 {
00133 name = serverId + ":" + poa->name();
00134 }
00135
00136 imr_locator->server_is_running (name.c_str (),
00137 partial_ior.c_str(),
00138 svr.in());
00139 }
00140 catch (const ::CORBA::SystemException&)
00141 {
00142 throw;
00143 }
00144 catch (const ::CORBA::Exception&)
00145 {
00146 throw ::CORBA::TRANSIENT (
00147 CORBA::SystemException::_tao_minor_code (TAO_IMPLREPO_MINOR_CODE, 0),
00148 CORBA::COMPLETED_NO);
00149 }
00150
00151 if (TAO_debug_level > 0)
00152 ACE_DEBUG ((LM_DEBUG, "Successfully notified ImR of Startup\n"));
00153 }
00154
00155 void
00156 ImR_Client_Adapter_Impl::imr_notify_shutdown (TAO_Root_POA* poa )
00157 {
00158
00159 CORBA::Object_var imr = poa->orb_core ().implrepo_service ();
00160
00161
00162
00163 if (CORBA::is_nil (imr.in ()))
00164 return;
00165
00166 try
00167 {
00168 if (TAO_debug_level > 0)
00169 {
00170 CORBA::String_var poaname = poa->the_name ();
00171 ACE_DEBUG ((LM_DEBUG,
00172 "Notifying IMR of Shutdown server:%s\n",
00173 poaname.in ()));
00174 }
00175
00176
00177 TAO::Portable_Server::Non_Servant_Upcall non_servant_upcall (*poa);
00178 ACE_UNUSED_ARG (non_servant_upcall);
00179
00180
00181 ImplementationRepository::Administration_var imr_locator =
00182 ImplementationRepository::Administration::_narrow (imr.in ());
00183
00184 imr_locator->server_is_shutting_down (poa->name().c_str ());
00185 }
00186 catch (const ::CORBA::COMM_FAILURE&)
00187 {
00188
00189
00190
00191 if (TAO_debug_level > 0)
00192 ACE_DEBUG((LM_DEBUG, "Ignoring COMM_FAILURE while unregistering from ImR.\n"));
00193 }
00194 catch (const ::CORBA::TRANSIENT&)
00195 {
00196
00197 if (TAO_debug_level > 0)
00198 ACE_DEBUG((LM_DEBUG, "Ignoring TRANSIENT while unregistering from ImR.\n"));
00199 }
00200 catch (const ::CORBA::Exception& ex)
00201 {
00202 ex._tao_print_exception (
00203 "ImR_Client_Adapter_Impl::imr_notify_shutdown()");
00204
00205 }
00206
00207 if (this->server_object_)
00208 {
00209 PortableServer::POA_var poa = this->server_object_->_default_POA ();
00210
00211 TAO_Root_POA *root_poa = dynamic_cast <TAO_Root_POA*> (poa.in ());
00212
00213 if (!root_poa)
00214 {
00215 throw ::CORBA::OBJ_ADAPTER ();
00216 }
00217
00218 PortableServer::ObjectId_var id =
00219 root_poa->servant_to_id_i (this->server_object_);
00220
00221 root_poa->deactivate_object_i (id.in());
00222
00223 server_object_ = 0;
00224 }
00225 }
00226
00227
00228
00229
00230
00231 int
00232 ImR_Client_Adapter_Impl::Initializer (void)
00233 {
00234 TAO_Root_POA::imr_client_adapter_name ("Concrete_ImR_Client_Adapter");
00235
00236 return ACE_Service_Config::process_directive (ace_svc_desc_ImR_Client_Adapter_Impl);
00237 }
00238 }
00239 }
00240
00241 ACE_STATIC_SVC_DEFINE (
00242 ImR_Client_Adapter_Impl,
00243 ACE_TEXT ("Concrete_ImR_Client_Adapter"),
00244 ACE_SVC_OBJ_T,
00245 &ACE_SVC_NAME (ImR_Client_Adapter_Impl),
00246 ACE_Service_Type::DELETE_THIS | ACE_Service_Type::DELETE_OBJ,
00247 0)
00248
00249 ACE_FACTORY_NAMESPACE_DEFINE (
00250 TAO_IMR_Client,
00251 ImR_Client_Adapter_Impl,
00252 TAO::ImR_Client::ImR_Client_Adapter_Impl)
00253
00254 TAO_END_VERSIONED_NAMESPACE_DECL
00255