00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "Forwarder.h"
00015 #include "ImR_Locator_i.h"
00016
00017 #include "tao/ORB.h"
00018 #include "tao/Object_KeyC.h"
00019 #include "tao/ORB_Constants.h"
00020
00021 #include "tao/PortableServer/PortableServer.h"
00022 #include "tao/PortableServer/POA_Current_Impl.h"
00023 #include "tao/PortableServer/POA_Current.h"
00024
00025
00026
00027
00028
00029
00030 ImR_Forwarder::ImR_Forwarder (ImR_Locator_i& imr_impl)
00031 : locator_ (imr_impl)
00032 {
00033 }
00034
00035 void
00036 ImR_Forwarder::init (CORBA::ORB_ptr orb ACE_ENV_ARG_DECL)
00037 {
00038 ACE_ASSERT (! CORBA::is_nil(orb));
00039 this->orb_ = orb;
00040 ACE_TRY_NEW_ENV
00041 {
00042 CORBA::Object_var tmp =
00043 orb->resolve_initial_references ("POACurrent" ACE_ENV_ARG_PARAMETER);
00044 ACE_TRY_CHECK;
00045
00046 this->poa_current_var_ =
00047 PortableServer::Current::_narrow (tmp.in () ACE_ENV_ARG_PARAMETER);
00048 ACE_TRY_CHECK;
00049 }
00050 ACE_CATCHANY
00051 {
00052 ACE_DEBUG ((LM_DEBUG, "ImR_Forwarder::init() Exception ignored.\n"));
00053 }
00054 ACE_ENDTRY;
00055 ACE_CHECK;
00056 ACE_ASSERT (!CORBA::is_nil (this->poa_current_var_.in ()));
00057 }
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067 PortableServer::Servant
00068 ImR_Forwarder::preinvoke (const PortableServer::ObjectId &,
00069 PortableServer::POA_ptr poa,
00070 const char *,
00071 PortableServer::ServantLocator::Cookie &
00072 ACE_ENV_ARG_DECL)
00073 ACE_THROW_SPEC ((CORBA::SystemException, PortableServer::ForwardRequest))
00074 {
00075 ACE_ASSERT (! CORBA::is_nil(poa));
00076 CORBA::Object_var forward_obj;
00077
00078 ACE_TRY
00079 {
00080 CORBA::String_var server_name = poa->the_name();
00081
00082 if (locator_.debug() > 1)
00083 ACE_DEBUG ((LM_DEBUG, "ImR: Activating server <%s>.\n", server_name.in()));
00084
00085
00086
00087
00088 CORBA::String_var pior = locator_.activate_server_by_name (server_name.in (), false ACE_ENV_ARG_PARAMETER);
00089 ACE_TRY_CHECK;
00090
00091 ACE_CString ior = pior.in ();
00092
00093
00094
00095 if (ior.find ("corbaloc:") != 0 || ior[ior.length () - 1] != '/')
00096 {
00097 ACE_ERROR ((LM_ERROR, "ImR_Forwarder::preinvoke () Invalid corbaloc ior.\n\t<%s>\n", ior.c_str()));
00098 ACE_TRY_THROW (CORBA::OBJECT_NOT_EXIST (
00099 CORBA::SystemException::_tao_minor_code (TAO_IMPLREPO_MINOR_CODE, 0),
00100 CORBA::COMPLETED_NO));
00101 }
00102
00103 CORBA::String_var key_str;
00104
00105 TAO::Portable_Server::POA_Current* tao_current =
00106 dynamic_cast <TAO::Portable_Server::POA_Current*> (this->poa_current_var_.in ());
00107
00108 ACE_ASSERT(tao_current != 0);
00109 TAO::Portable_Server::POA_Current_Impl* impl = tao_current->implementation ();
00110 TAO::ObjectKey::encode_sequence_to_string (key_str.out (), impl->object_key ());
00111
00112 ior += key_str.in();
00113
00114 if (locator_.debug() > 0)
00115 ACE_DEBUG ((LM_DEBUG, "ImR: Forwarding invocation on <%s> to <%s>\n", server_name.in(), ior.c_str()));
00116
00117 forward_obj =
00118 this->orb_->string_to_object (ior.c_str () ACE_ENV_ARG_PARAMETER);
00119 ACE_TRY_CHECK;
00120 }
00121 ACE_CATCH (ImplementationRepository::CannotActivate, ex)
00122 {
00123 ACE_TRY_THROW (CORBA::TRANSIENT (
00124 CORBA::SystemException::_tao_minor_code (TAO_IMPLREPO_MINOR_CODE, 0),
00125 CORBA::COMPLETED_NO));
00126 }
00127 ACE_CATCH (ImplementationRepository::NotFound, ex)
00128 {
00129 ACE_TRY_THROW (CORBA::TRANSIENT (
00130 CORBA::SystemException::_tao_minor_code (TAO_IMPLREPO_MINOR_CODE, 0),
00131 CORBA::COMPLETED_NO));
00132 }
00133 ACE_CATCHANY
00134 {
00135 ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "Forwarder");
00136 ACE_TRY_THROW (CORBA::TRANSIENT (
00137 CORBA::SystemException::_tao_minor_code (TAO_IMPLREPO_MINOR_CODE, 0),
00138 CORBA::COMPLETED_NO));
00139 }
00140 ACE_ENDTRY;
00141 ACE_CHECK_RETURN (0);
00142
00143 if (!CORBA::is_nil (forward_obj.in ()))
00144 ACE_THROW_RETURN (PortableServer::ForwardRequest (forward_obj.in ()), 0);
00145
00146 ACE_ERROR ((LM_ERROR, "Error: Forward_to reference is nil.\n"));
00147 ACE_THROW_RETURN (CORBA::OBJECT_NOT_EXIST (
00148 CORBA::SystemException::_tao_minor_code (TAO_IMPLREPO_MINOR_CODE, 0),
00149 CORBA::COMPLETED_NO), 0);
00150 }
00151
00152 void
00153 ImR_Forwarder::postinvoke (const PortableServer::ObjectId &,
00154 PortableServer::POA_ptr,
00155 const char *,
00156 PortableServer::ServantLocator::Cookie,
00157 PortableServer::Servant
00158 ACE_ENV_ARG_DECL_NOT_USED
00159 ) ACE_THROW_SPEC ((CORBA::SystemException))
00160 {
00161 }
00162